diff options
author | Quentin Colombet <qcolombet@apple.com> | 2014-02-21 23:42:41 +0000 |
---|---|---|
committer | Quentin Colombet <qcolombet@apple.com> | 2014-02-21 23:42:41 +0000 |
commit | 0206b30ea6ca3cdd04d968ca676ccb025ef75158 (patch) | |
tree | 23ef37e7ee095f63edc3588bac4958e2385a0327 /lib | |
parent | 94f20bfe6e9de6a1c80c7bfe2dc77202c88847b4 (diff) | |
download | llvm-0206b30ea6ca3cdd04d968ca676ccb025ef75158.tar.gz llvm-0206b30ea6ca3cdd04d968ca676ccb025ef75158.tar.bz2 llvm-0206b30ea6ca3cdd04d968ca676ccb025ef75158.tar.xz |
[DAGCombiner] PCMP* sets its result to all ones or zeros so we can AND with the
shifted mask rather than masking and shifting separately.
The patch adds this transformation to the DAGCombiner:
(shl (and (setcc:i8v16 ...) N01C) N1C) -> (and (setcc:i8v16 ...) N01C<<N1C)
<rdar://problem/16054492>
Patch by Adam Nemet <anemet@apple.com>
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@201906 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index de8fbc9d78..76974c26d9 100644 --- a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -3818,6 +3818,24 @@ SDValue DAGCombiner::visitSHL(SDNode *N) { if (VT.isVector()) { SDValue FoldedVOp = SimplifyVBinOp(N); if (FoldedVOp.getNode()) return FoldedVOp; + + BuildVectorSDNode *N1CV = dyn_cast<BuildVectorSDNode>(N1); + // If setcc produces all-one true value then: + // (shl (and (setcc) N01CV) N1CV) -> (and (setcc) N01CV<<N1CV) + if (N1CV && N1CV->isConstant() && + TLI.getBooleanContents(true) == + TargetLowering::ZeroOrNegativeOneBooleanContent && + N0.getOpcode() == ISD::AND) { + SDValue N00 = N0->getOperand(0); + SDValue N01 = N0->getOperand(1); + BuildVectorSDNode *N01CV = dyn_cast<BuildVectorSDNode>(N01); + + if (N01CV && N01CV->isConstant() && N00.getOpcode() == ISD::SETCC) { + SDValue C = DAG.FoldConstantArithmetic(ISD::SHL, VT, N01CV, N1CV); + if (C.getNode()) + return DAG.getNode(ISD::AND, SDLoc(N), VT, N00, C); + } + } } // fold (shl c1, c2) -> c1<<c2 |