[Bug optimization/10992] New: invalid instruction reordering with -O2 / -fschedule-insns2

rgrosseboerger@dspace.de gcc-bugzilla@gcc.gnu.org
Tue May 27 09:08:00 GMT 2003

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.


           Summary: invalid instruction reordering with -O2 / -fschedule-
           Product: gcc
           Version: 3.2.1
            Status: UNCONFIRMED
          Severity: major
          Priority: P2
         Component: optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: rgrosseboerger@dspace.de
                CC: gcc-bugs@gcc.gnu.org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu

GCC 3.2.x and 3.3 generate incorrect code for the simple test case below.

The problems occurs, if the C code is compiled with -O2, but does not occur 

at -O1 or "-O2 -fno-schedule-insns2" (->GCC does invalid instruction reordering 

The problem disappears, if uint_value is declared as volatile. 

The correct output for the test program is :

   uint_value : 00570047  , value 00570047


   uint_value : 006B005B  , value 006B005B

Whereas the miscompilation with -O2 gives :

   uint_value : 00570047  , value BFFFF8E8


   uint_value : 006B005B  , value 00660056

I have the same problem on gcc/x86-64, but the code works OK with the Intel 

#include <stdio.h>

typedef unsigned int UInt32;

typedef unsigned int UInt16;

typedef float         Float32;

float  f_array[25];

UInt32 u32_array[25];

int j = 5;

inline void func(UInt32 count, UInt32* address, volatile Float32* float_value)


    unsigned int i;

    UInt16 value_low = 0x42;

    UInt16 value_high = 0x52;

    /*volatile*/  UInt32 uint_value;


    for (i = 0; i < count; i++)


        value_high = value_high +5;

        value_low = value_low +5;


        uint_value = (((UInt32)value_high) << 16);

        uint_value |= value_low;


        float_value[i] = *((volatile float*)(&uint_value));

        printf("   uint_value : %08X  , value %08X \n", uint_value, *((UInt32 *) 



int main()


    func( j, u32_array , f_array);     


------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.

More information about the Gcc-bugs mailing list