[X86] Rewrite LowerBRCOND to remove dead code and handle ISD::SETCC and overflow...
authorCraig Topper <craig.topper@intel.com>
Thu, 20 Feb 2020 16:49:09 +0000 (08:49 -0800)
committerCraig Topper <craig.topper@intel.com>
Thu, 20 Feb 2020 16:50:18 +0000 (08:50 -0800)
commit3543ac9ab52df77af55a2ebdeeddfb76aba15d29
tree0150d4f5bb20759c59c6b8bbe805ae846b1341f8
parent9bbf271fc9d5b84f9e657805dfff0fb8a1607af4
[X86] Rewrite LowerBRCOND to remove dead code and handle ISD::SETCC and overflow ops directly.

There's a lot of old leftover code in LowerBRCOND. Especially
the detecting or AND or OR of X86ISD::SETCC nodes. Those were
needed before LegalizeDAG was changed to visit nodes before
their operands.

It also relied on reversing the output of LowerSETCC to find the
flags producing node to use for the X86ISD::BRCOND node.

Rather than using LowerSETCC this patch uses emitFlagsForSetcc to
handle the integer ISD::SETCC case. This gives the flag producer
and the comparison code to use directly. I've removed the addTest
flag and just produce a X86ISD::BRCOND and return immediately.

Floating point ISD::SETCC case is just an X86ISD::FCMP with special
care for OEQ and UNE derived from the previous code. I've left
f128 out so it will emit a test. And LowerSETCC will be called
later to produce a libcall and X86ISD::SETCC. We have combines
that can merge the test and X86ISD::SETCC.

We need to handle two cases for overflow ops. Either they are used
directly or they have a seteq 0 or setne 1 to invert the overflow.
The old code did not handle the setne 1 case, but I think some
other combines were making up for it.

If we fail to find a condition, we'll wrap an AND with 1 on the
original condition and tell emitFlagsForSetcc to emit a compare
with 0. This will pickup the LowerAndToBT and or the EmitTest case.
I kept the isTruncWithZeroHighBitsInput call, but we might be able
to fold that in to emitFlagsForSetcc.

Differential Revision: https://reviews.llvm.org/D74750
llvm/lib/Target/X86/X86ISelLowering.cpp