Bug 47239 - [4.6 Regression] (int)&func & 3 is always optimized to 0 on some targets
Summary: [4.6 Regression] (int)&func & 3 is always optimized to 0 on some targets
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: 4.6.0
Assignee: Richard Biener
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2011-01-09 23:23 UTC by Kazumoto Kojima
Modified: 2011-01-12 12:10 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work: 4.5.3
Known to fail: 4.6.0
Last reconfirmed: 2011-01-11 12:53:34


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kazumoto Kojima 2011-01-09 23:23:22 UTC
Targets like arm, hppa and sh64 use the lower bits of the address
of functions for special purposes.  Even on those targets,

----
extern void plabel32_function (void);

int
is_plabel32 (void)
{
  return ((unsigned long) &plabel32_function & 3);
}
----

which was the test case of PR 35705, is wrongly compiled with -O2.
It seems that tree-bit-ccp optimization evaluates the expression
((unsigned long) &plabel32_function & 3) to zero always.
With -fno-tree-bit-ccp, the result looks OK.  For example, arm-eabi
compiler outputs

	mov	r0, #0
	bx	lr

with -O2 and

	ldr	r0, .L2
	and	r0, r0, #3
	bx	lr
.L3:
	.align	2
.L2:
	.word	plabel32_function

with -O2 -fno-tree-bit-ccp.  I've got similar results for hppa and sh64
compilers.
Comment 1 Richard Biener 2011-01-11 12:53:34 UTC
Confirmed, mine.  The fix for PR35705 only extracts alignment information
from function decls for the single case &fn & 1.  That's odd.  I'm going
to simply punt for function-decls for now.
Comment 2 Richard Biener 2011-01-11 14:23:23 UTC
Author: rguenth
Date: Tue Jan 11 14:23:20 2011
New Revision: 168661

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=168661
Log:
2011-01-11  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/47239
	* tree-ssa-ccp.c (get_value_from_alignment): Punt for FUNCTION_DECLs.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/tree-ssa-ccp.c
Comment 3 Kazumoto Kojima 2011-01-11 23:14:45 UTC
I've tried 168661 with arm, hppa and sh64 cc1's. The problem
has gone away on all these 3 targets.  Thanks!
Comment 4 Richard Biener 2011-01-12 12:10:05 UTC
Fixed.