diff options
| author | Nate Begeman <natebegeman@mac.com> | 2005-08-24 04:57:57 +0000 | 
|---|---|---|
| committer | Nate Begeman <natebegeman@mac.com> | 2005-08-24 04:57:57 +0000 | 
| commit | 45bbbb3f114d8f32ef46839464a713060ffab8ae (patch) | |
| tree | 779205756ff9e3a2758b39684180473f74e2956d /llvm/lib/CodeGen | |
| parent | b6d034a841b6b5c83337b28b22aa88a98133d58b (diff) | |
| download | bcm5719-llvm-45bbbb3f114d8f32ef46839464a713060ffab8ae.tar.gz bcm5719-llvm-45bbbb3f114d8f32ef46839464a713060ffab8ae.zip | |
Teach SelectionDAG how to simplify a few more setcc-equivalent select_cc
nodes so that backends don't have to.
llvm-svn: 22999
Diffstat (limited to 'llvm/lib/CodeGen')
| -rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 27 | 
1 files changed, 21 insertions, 6 deletions
| diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index c7687e3c618..21f763a9462 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -853,21 +853,36 @@ SDOperand SelectionDAG::SimplifySelectCC(SDOperand N1, SDOperand N2,      }    } -  // Check to see if this is the equivalent of seteq X, 0. -  // select_cc eq X, 0, 1, 0 -> setcc X, 0, eq -> srl (ctlz X), log2(size(X)) -  if (N2C && N2C->isNullValue() && N4C && N4C->isNullValue() && -      N3C && (N3C->getValue() == 1ULL) && CC == ISD::SETEQ) { +  // Check to see if this is the equivalent of setcc X, 0 +  if (N4C && N4C->isNullValue() && N3C && (N3C->getValue() == 1ULL)) {      MVT::ValueType XType = N1.getValueType();      if (TLI.getOperationAction(ISD::SETCC, TLI.getSetCCResultTy()) ==           TargetLowering::Legal) { -      return getSetCC(TLI.getSetCCResultTy(), N1, N2, ISD::SETEQ); +      return getSetCC(TLI.getSetCCResultTy(), N1, N2, CC);      } -    if (TLI.getOperationAction(ISD::CTLZ, XType) == TargetLowering::Legal) { +    // seteq X, 0 -> srl (ctlz X, log2(size(X))) +    if (N2C && N2C->isNullValue() && CC == ISD::SETEQ &&  +        TLI.getOperationAction(ISD::CTLZ, XType) == TargetLowering::Legal) {        SDOperand Ctlz = getNode(ISD::CTLZ, XType, N1);        return getNode(ISD::SRL, XType, Ctlz,                        getConstant(Log2_32(MVT::getSizeInBits(XType)),                                   TLI.getShiftAmountTy()));      } +    // setgt X, 0 -> srl (and (-X, ~X), size(X)-1) +    if (N2C && N2C->isNullValue() && CC == ISD::SETGT) {  +      SDOperand NegN1 = getNode(ISD::SUB, XType, getConstant(0, XType), N1); +      SDOperand NotN1 = getNode(ISD::XOR, XType, N1, getConstant(~0ULL, XType)); +      return getNode(ISD::SRL, XType, getNode(ISD::AND, XType, NegN1, NotN1), +                     getConstant(MVT::getSizeInBits(XType)-1, +                                 TLI.getShiftAmountTy())); +    } +    // setgt X, -1 -> xor (srl (X, size(X)-1), 1) +    if (N2C && N2C->isAllOnesValue() && CC == ISD::SETGT) { +      SDOperand Sign = getNode(ISD::SRL, XType, N1, +                               getConstant(MVT::getSizeInBits(XType)-1, +                                           TLI.getShiftAmountTy())); +      return getNode(ISD::XOR, XType, Sign, getConstant(1, XType)); +    }    }    // Check to see if this is an integer abs. select_cc setl[te] X, 0, -X, X -> | 

