Take the following test case: int foo();
int test( int *b ) { (*b)--; if( *b == 0 ) return foo(); return 0; } On x86_64, with "-fomit-frame-pointer -O3 -c", gcc 4.6 compiles this to: 0: 8b 07 mov eax, [rdi] 2: 83 e8 01 sub eax, 0x1 5: 85 c0 test eax, eax 7: 89 07 mov [rdi], eax 9: 74 05 je 10 <test+0x10> b: 31 c0 xor eax, eax d: c3 ret 10: e9 00 00 00 00 jmp 15 <test+0x15> //foo As can be seen, gcc inserts a redundant "test" instruction. This problem is present in all versions of gcc I tested (3.4, 4.3.4, 4.4.1, and 4.6 SVN r160330). According to Alexander Strange on IRC: <astrange> the problem is that subl $1, %eax does (clobber (reg:CC 17 flags)) instead of (set (reg:CCZ 17 flags) (compare:CCZ .... <astrange> which i don't think is fixable in a real way, but i didn't write it -- Summary: GCC inserts redundant "test" instruction due to incorrect clobber Product: gcc Version: 4.6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: darkshikari at gmail dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44474