The following code is producing false results with -O2 optimization (-O1 and O3 are correct): ------- #include <stdio.h> #define BLOCK_SIZE 100000
int main() { int i; float block_f[BLOCK_SIZE]; int d_phase = 0; int d_phase_inc = 0x100000; for (i = 0; i < BLOCK_SIZE; i++){ block_f[i] = (float)(d_phase); d_phase += d_phase_inc; } printf ("%x %x\n", (int)block_f[1695], (int)block_f[1696]); return 0; } ----- With -O2, the loop is run only 0x6a0 times, instead of 0x186a0 times. gcc is from openSUSE 11.0 (4.3.1 20080507 (prerelease) [gcc-4_3-branch revision 135036] (SUSE Linux)), but fc9 is most probably affected as well. Failing code is a very simplified test case from gnuradio (http://www.ruby-forum.com/topic/156807) -- Summary: gcc creating wrong code with -O2 Product: gcc Version: 4.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: stefan dot bruens at rwth-aachen dot de http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37067