This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/38126] suboptimal code for (a && b || !a && !b)
- From: "svfuerst at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 02 Feb 2012 06:11:27 +0000
- Subject: [Bug middle-end/38126] suboptimal code for (a && b || !a && !b)
- Auto-submitted: auto-generated
- References: <bug-38126-4@http.gcc.gnu.org/bugzilla/>
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.