[Bug middle-end/38126] suboptimal code for (a && b || !a && !b)
svfuerst at gmail dot com
gcc-bugzilla@gcc.gnu.org
Thu Feb 2 06:12:00 GMT 2012
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38126
--- Comment #4 from Steven Fuerst <svfuerst at gmail dot com> 2012-02-02 06:11:27 UTC ---
Two more cases for simple boolean logic optimizations.
gcc-4.7 produces with -O3 for
int test_and(long long x, long long y)
{
return x && y;
}
test %rsi, %rsi
setne %dl
xor %eax, %eax
test %rdi, %rdi
setne %al
and %edx, %eax
retq
Whereas this is faster:
neg %rdi
sbb %rdi, %rdi
xor %eax, %eax
and %rsi, %rdi
setne %al
retq
Also
int test_other(long long x, long long y)
{
return !x && y; /* or !(x || !y) */
}
gives
test %rsi,%rsi
setne %dl
xor %eax,%eax
test %rdi,%rdi
sete %al
and %edx,%eax
retq
when
sub $1, %rsi
sbb %rsi, %rsi
xor %eax, %eax
or %rdi, %rsi
sete %al
retq
is faster.
More information about the Gcc-bugs
mailing list