Bug 10992 - invalid instruction reordering with -O2 / -fschedule-insns2
Summary: invalid instruction reordering with -O2 / -fschedule-insns2
Status: RESOLVED DUPLICATE of bug 5328
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 3.2.1
: P2 normal
Target Milestone: 3.4.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-05-27 08:51 UTC by Ralf Große Börger
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ralf Große Börger 2003-05-27 08:51:18 UTC
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 
compiler.






#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 *) 
&(float_value[i])));


    }


}




int main()


{


    func( j, u32_array , f_array);     


}
Comment 1 Ralf Große Börger 2003-05-27 09:01:33 UTC

*** This bug has been marked as a duplicate of 5328 ***