Compile this code with gcc 4.6.2: #include <stddef.h> size_t b; int f(size_t a) { return b == 0 || a < b; } For x86-64 I see this result: f: movq b(%rip), %rdx movl $1, %eax testq %rdx, %rdx je .L2 xorl %eax, %eax cmpq %rdi, %rdx seta %al .L2: rep ret This can be more done without a conditional jump: f: movq b(%rip), %rdx xorl %eax, %eax subq $1, %rdx cmpq %rdi, %rdx setae %al rep ret Unless the b==0 test is marked as likely I'd say this code is performing better on all architectures.
Confirmed, I have a few patches which might improve this but maybe not for x86_64; it does help MIPS right now.
_6 = b.1_1 > a_4(D); _7 = b.1_1 == 0; _8 = _6 | _7; So this is an expansion issue I think.
This has been fixed (optimally) since GCC 13, by Eugene Rozenfeld's fix for PR tree-optimization/96674. The conditional jump was eliminated back in GCC 4.9, but the combination of the two tests into a subtraction and a single comparison was implemented (at the tree level) by Eugene.