On Friday 03 August 2007, Jonathan S. Shapiro wrote:
> On Fri, 2007-08-03 at 12:46 -0400, Daniel Jacobowitz wrote:
> > On Fri, Aug 03, 2007 at 05:24:28PM +0100, Dave Korn wrote:
> > >   I'm a bit surprised too.  But it occurs to me that the ARM, unlike
> > > the i386 and m68k, is bi-endian.  Perhaps you can't actually know which
> > > mode it's running in at compile time and /have/ to test it at runtime?
> >
> > No.  You can't generate code in general that works on both!
>
> Then it seems very curious that the constant folding should fail on this
> platform. Any idea what may be going on here?

You're exploiting a hole in the C aliasing rules by accessing a 32-bit int as 
type char. I tested several compilers (4.2, 4.1 and 3.4 x86, 4.2 m68k and 4.2 
arm) and the only one that eliminated the comparison was 3.4-x86.

My guess is that most optimization passes see this type punning, and leave 
well alone. You're probably relying on the low-level RTL optimizers to spot 
this, which depending on architecture may be too late for it to be provably 
safe. I'm fairly surprised it got caught at all.

Paul

Reply via email to