ARM constant folding bug?

Dave Korn dave.korn@artimi.com
Fri Aug 3 16:24:00 GMT 2007


On 03 August 2007 17:09, Jonathan S. Shapiro wrote:

> This is observed on gcc-3.4.6. It may be a known issue, and/or it may be
> fixed in later compilers.
> 
> For bringup purposes, I wrote an inline assembly hack to get the cross
> compiler to tell me whether the target is little/big endian. The code
> fragment is:
> 
>   const unsigned long ul = 0x04030201llu;
> 
>   if ( *((char *) &ul) == 0x1 )
>     ASMDEF(LITTLE_ENDIAN);
>   else
>     ASMDEF(BIG_ENDIAN);
> 
> The expectation is that when run with -O2, the compiler should
> constant-fold all of this stuff away, resulting in exactly one ASMDEF.
> On i386 and m68k, the constant folding occurs as expected. For ARM it
> does not(!).
> 
> I am not surprised that there is different behavior for different
> targets, but I am very surprised that *this* behavior is different. This
> optimization ought to be happening in the mid-end, and it ought to be
> entirely machine independent.

  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?


    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....



More information about the Gcc mailing list