This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/56309] -O3 optimizer generates conditional moves instead of compare and branch resulting in almost 2x slower code
- From: "arturomdn at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 14 Feb 2013 16:43:23 +0000
- Subject: [Bug target/56309] -O3 optimizer generates conditional moves instead of compare and branch resulting in almost 2x slower code
- Auto-submitted: auto-generated
- References: <bug-56309-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56309
--- Comment #10 from arturomdn at gmail dot com 2013-02-14 16:43:23 UTC ---
Might be worth mentioning here what I said in the stackoverflow answer, that in
this particular case the entire conditional branch can be avoided because it is
redundant.
This code
if (tmp >= imax) {
carry = tmp >> numbits; // <---- A
tmp &= imax - 1; // <---- B
} else {
carry = 0; // <---- C
}
can be reduced to
carry = tmp >> numbits;
tmp &= imax - 1;
Proof:
1) numbits is 32
2) imax is 1ULL << 32 so lower 32 bits are zero
3) imax - 1 is 0xFFFFFFFF (see 2)
4) if tmp >= imax then tmp has bits set in upper 32 bits
5) otherwise if tmp < imax then tmp does not have bits set in upper 32 bits
6) statement "A" is equivalent to "C" when tmp < imax (because of 4)
7) statement "B" is a NOP when tmp < imax (because of 3 and 5)