This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug rtl-optimization/71336] 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: Tue, 16 Aug 2016 20:04:34 +0000
- Subject: [Bug rtl-optimization/71336] Suboptimal x86 code generated for "(a & 1) ? (CST1 + CST2) : CST1"
- Authentication-results: sourceware.org; auth=none
- Auto-submitted: auto-generated
- References: <bug-71336-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71336
--- Comment #4 from Patrick Palka <ppalka at gcc dot gnu.org> ---
On a related note I noticed the final code for
int test(int a) {
return (a & CST) * 4 + 3;
}
is not optimal when CST is a power of two, e.g. when CST=8:
_Z4testi:
.LFB0:
.cfi_startproc
andl $8, %edi
leal 0(,%rdi,4), %eax
addl $3, %eax
ret
The leal and the addl could be combined into a single leal. When CST is not a
power of two then there is no addl.