From fda2b55e1b169044828c8f7b2cba073bfd455dd5 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 18 Apr 2005 04:48:12 +0000 Subject: [PATCH] Fold setcc of MVT::i1 operands into logical operations git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21319 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 39 +++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index fbadd6323c9..7e870e6c2f9 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -597,6 +597,45 @@ SDOperand SelectionDAG::getSetCC(ISD::CondCode Cond, MVT::ValueType VT, } } + // Fold away ALL boolean setcc's. + if (N1.getValueType() == MVT::i1) { + switch (Cond) { + default: assert(0 && "Unknown integer setcc!"); + case ISD::SETEQ: // X == Y -> (X^Y)^1 + N1 = getNode(ISD::XOR, MVT::i1, + getNode(ISD::XOR, MVT::i1, N1, N2), + getConstant(1, MVT::i1)); + break; + case ISD::SETNE: // X != Y --> (X^Y) + N1 = getNode(ISD::XOR, MVT::i1, N1, N2); + break; + case ISD::SETGT: // X >s Y --> X == 0 & Y == 1 --> X^1 & Y + case ISD::SETULT: // X X == 0 & Y == 1 --> X^1 & Y + N1 = getNode(ISD::AND, MVT::i1, N2, + getNode(ISD::XOR, MVT::i1, N1, getConstant(1, MVT::i1))); + break; + case ISD::SETLT: // X X == 1 & Y == 0 --> Y^1 & X + case ISD::SETUGT: // X >u Y --> X == 1 & Y == 0 --> Y^1 & X + N1 = getNode(ISD::AND, MVT::i1, N1, + getNode(ISD::XOR, MVT::i1, N2, getConstant(1, MVT::i1))); + break; + case ISD::SETULE: // X <=u Y --> X == 0 | Y == 1 --> X^1 | Y + case ISD::SETGE: // X >=s Y --> X == 0 | Y == 1 --> X^1 | Y + N1 = getNode(ISD::OR, MVT::i1, N2, + getNode(ISD::XOR, MVT::i1, N1, getConstant(1, MVT::i1))); + break; + case ISD::SETUGE: // X >=u Y --> X == 1 | Y == 0 --> Y^1 | X + case ISD::SETLE: // X <=s Y --> X == 1 | Y == 0 --> Y^1 | X + N1 = getNode(ISD::OR, MVT::i1, N1, + getNode(ISD::XOR, MVT::i1, N2, getConstant(1, MVT::i1))); + break; + } + if (VT != MVT::i1) + N1 = getNode(ISD::ZERO_EXTEND, VT, N1); + return N1; + } + + SetCCSDNode *&N = SetCCs[std::make_pair(std::make_pair(N1, N2), std::make_pair(Cond, VT))]; if (N) return SDOperand(N, 0); -- 2.34.1