Prior to the 4.* series compilers, the following code :

char tell_endian()
{
    unsigned x = 1;
    return *(char*)&x;
}

... used to produce a simple contant load to a register and return.  The 4.x
compilers seem like they can no longer make this optimization.  It used to be
very convenient because code written using this construct would automatically
eliminate code since it was correctly able to identify that the return value
from "tell_endian" is a constant, i.e.

if ( tell_endian() ) little_stuff() else big_stuff()

would generate code consistant with simply writing "little_stuff()" on little
endian systems (and visa versa).


-- 
           Summary: Optimizer regression from v3 to v4
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gianni at mariani dot ws


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26116

Reply via email to