When the code below is compiled with -O3, func2() is called on each iteration. The .s shows that the the comparison to Array has been moved outside of the loop which is incorrect. If Array is not constant working code is produced, working code is also produced if I use -fold-unroll-loops. If I don't call a function say simply increment j, then correct code is produced too.
The other options used are: -O3 -m68000 -msoft-float -fno-exceptions -------------- const unsigned char Array[6] = { 10, 10, 10, 0, 0 ,0 }; void func2(void); int j=0; void func(void) { unsigned char i; for(i=0; i<6; i++) { if(Array[i] > 0) { func2(); } } } void func2(void) { j++; } -------------- -- Summary: Loop optimiser generates incorrect code. Product: gcc Version: 3.4.3 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: gccbug at sarek dot cc CC: gcc-bugs at gcc dot gnu dot org GCC build triplet: cygwin GCC host triplet: cygwin GCC target triplet: m68k-elf http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18612