[Bug rtl-optimization/71336] Suboptimal x86 code generated for "(a & 1) ? (CST1 + CST2) : CST1"
jakub at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon May 30 10:00:00 GMT 2016
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71336
--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I guess it could be useful even without lea.
Consider:
int test2 (int a) { return (a & 4) ? 385600 : 123456; }
We emit:
andl $4, %edi
cmpl $1, %edi
sbbl %eax, %eax
andl $-262144, %eax
addl $385600, %eax
We could change that to e.g.
andl $4, %edi
shll $16, %edi
movl %edi, %eax
orl $123456, %eax
All we care is that the comparison against zero has the other operand that has
at most one bit set in it (and we know which one, i.e. nonzero_bits must be
power of two), and that the diff in between the two values has also exactly one
bit set.
More information about the Gcc-bugs
mailing list