[This problem occurs in 4.1.2 and 4.1.3 as well] Given the following source:
int in_canforward(unsigned int in) { unsigned int net; if ((in & ~0xffffff0f) == 0xf0 || (in & ~0xffffff0f) == 0xe0) return 0; if ((in & 0x80) == 0) { net = in & 0xff; if (net == 0 || net == 0x7f) return 0; } return 1; "cc1 -O2 -quiet" emit: #NO_APP .file "inc.c" .text .align 1 .globl in_canforward .type in_canforward, @function in_canforward: .word 0x0 subl2 $4,%sp movl 4(%ap),%r1 bicl3 $-241,%r1,%r0 cmpl %r0,$240 jeql .L2 cmpl %r0,$224 jeql .L2 bicb3 $127,%r1,%r0 jneq .L12 bicl2 $-256,%r1 jneq .L13 .L2: clrl %r0 ret .L12: movl $1,%r0 ret .L13: cmpl %r1,$127 jeql .L14 xorb2 $1,%r0 movzbl %r0,%r0 ret .L14: movb $1,%r0 xorb2 $1,%r0 movzbl %r0,%r0 ret .size in_canforward, .-in_canforward .ident "GCC: (GNU) 4.3.0 20070319 (experimental)" Notice the code at .L14? Why go through all extra that effort? Why not just do clrl %r0 and ret or preferrably branch to .L2 which already does that? The same argument goes for the xorb2/movzbl right before .L14. movl $1,%r0 and ret or preferably branch to .L12 which already does that. Now if you move .L13 before .L12 (so it can all fall through) and take the mentioned branches, the almost-optimal version becomes: in_canforward: .word 0x0 subl2 $4,%sp movl 4(%ap),%r1 bicl3 $-241,%r1,%r0 cmpl %r0,$240 jeql .L2 cmpl %r0,$224 jeql .L2 bicb3 $127,%r1,%r0 jneq .L12 bicl2 $-256,%r1 jneq .L13 .L2: clrl %r0 ret .L13: cmpl %r1,$127 jeql .L2 .L12: movl $1,%r0 ret -- Summary: gcc is being too clever Product: gcc Version: 4.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: matt at 3am-software dot com GCC build triplet: x86_64--netbsd GCC host triplet: x86_64--netbsd GCC target triplet: vax--netbsdelf http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31272