diff options
author | Evan Cheng <evan.cheng@apple.com> | 2007-08-18 05:57:05 +0000 |
---|---|---|
committer | Evan Cheng <evan.cheng@apple.com> | 2007-08-18 05:57:05 +0000 |
commit | 571c4788d5d1527af39f9904e14983d9229c2443 (patch) | |
tree | 198850c7980bf18a87ed8733510d75f45a21a4f7 | |
parent | 9710536b44ec47a1121942df11416c063272245a (diff) | |
download | external_llvm-571c4788d5d1527af39f9904e14983d9229c2443.zip external_llvm-571c4788d5d1527af39f9904e14983d9229c2443.tar.gz external_llvm-571c4788d5d1527af39f9904e14983d9229c2443.tar.bz2 |
Fold C ? 0 : 1 to ~C or zext(~C) or trunc(~C) depending the types.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41163 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index b38b479..d9c09e1 100644 --- a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -2249,6 +2249,7 @@ SDOperand DAGCombiner::visitSELECT(SDNode *N) { ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1); ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2); MVT::ValueType VT = N->getValueType(0); + MVT::ValueType VT0 = N0.getValueType(); // fold select C, X, X -> X if (N1 == N2) @@ -2262,15 +2263,25 @@ SDOperand DAGCombiner::visitSELECT(SDNode *N) { // fold select C, 1, X -> C | X if (MVT::i1 == VT && N1C && N1C->getValue() == 1) return DAG.getNode(ISD::OR, VT, N0, N2); + // fold select C, 0, 1 -> ~C + if (MVT::isInteger(VT) && MVT::isInteger(VT0) && + N1C && N2C && N1C->isNullValue() && N2C->getValue() == 1) { + SDOperand XORNode = DAG.getNode(ISD::XOR, VT0, N0, DAG.getConstant(1, VT0)); + if (VT == VT0) + return XORNode; + AddToWorkList(XORNode.Val); + if (MVT::getSizeInBits(VT) > MVT::getSizeInBits(VT0)) + return DAG.getNode(ISD::ZERO_EXTEND, VT, XORNode); + return DAG.getNode(ISD::TRUNCATE, VT, XORNode); + } // fold select C, 0, X -> ~C & X - // FIXME: this should check for C type == X type, not i1? - if (MVT::i1 == VT && N1C && N1C->isNullValue()) { + if (VT == VT0 && N1C && N1C->isNullValue()) { SDOperand XORNode = DAG.getNode(ISD::XOR, VT, N0, DAG.getConstant(1, VT)); AddToWorkList(XORNode.Val); return DAG.getNode(ISD::AND, VT, XORNode, N2); } // fold select C, X, 1 -> ~C | X - if (MVT::i1 == VT && N2C && N2C->getValue() == 1) { + if (VT == VT0 && N2C && N2C->getValue() == 1) { SDOperand XORNode = DAG.getNode(ISD::XOR, VT, N0, DAG.getConstant(1, VT)); AddToWorkList(XORNode.Val); return DAG.getNode(ISD::OR, VT, XORNode, N1); |