This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/71336] New: Suboptimal x86 code generated for "(a & 1) ? (CST1 + CST2) : CST1"
- From: "ppalka at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sun, 29 May 2016 22:23:47 +0000
- Subject: [Bug target/71336] New: Suboptimal x86 code generated for "(a & 1) ? (CST1 + CST2) : CST1"
- Auto-submitted: auto-generated
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