https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71336
Bug ID: 71336 Summary: Suboptimal x86 code generated for "(a & 1) ? (CST1 + CST2) : CST1" Product: gcc Version: 6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: ppalka at gcc dot gnu.org Target Milestone: --- $ cat test.c int test(int a) { return a & 1 ? 7 : 3; } $ gcc -O2 -o- -S test.c test: .LFB0: .cfi_startproc andl $1, %edi cmpl $1, %edi sbbl %eax, %eax andl $-4, %eax addl $7, %eax ret .cfi_endproc The optimal code would look like andl $1, %edi leal 3(,%rdi,4), %eax ret