diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2014-04-26 13:00:53 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2014-04-26 13:00:53 +0000 |
commit | 75125c127d533f0da6f97619c2be4f3bee9142c4 (patch) | |
tree | 83a40a2b140a70a4bfcc86da2c2239d8d83778ad /lib/CodeGen/SelectionDAG | |
parent | aab6231cd910dcd40217bc9cf73bf72223f2cf30 (diff) | |
download | llvm-75125c127d533f0da6f97619c2be4f3bee9142c4.tar.gz llvm-75125c127d533f0da6f97619c2be4f3bee9142c4.tar.bz2 llvm-75125c127d533f0da6f97619c2be4f3bee9142c4.tar.xz |
Rip out X86-specific vector SDIV lowering, make the corresponding DAGCombiner transform work on vectors.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207316 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/SelectionDAG')
-rw-r--r-- | lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 7850bc2589..8f62dc20eb 100644 --- a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -1985,27 +1985,39 @@ SDValue DAGCombiner::visitSDIV(SDNode *N) { return DAG.getNode(ISD::UDIV, SDLoc(N), N1.getValueType(), N0, N1); } + + const APInt *Divisor = nullptr; + if (N1C) { + Divisor = &N1C->getAPIntValue(); + } else if (N1.getValueType().isVector() && + N1->getOpcode() == ISD::BUILD_VECTOR) { + BuildVectorSDNode *BV = cast<BuildVectorSDNode>(N->getOperand(1)); + if (ConstantSDNode *C = BV->getConstantSplatValue()) + Divisor = &C->getAPIntValue(); + } + // fold (sdiv X, pow2) -> simple ops after legalize - if (N1C && !N1C->isNullValue() && - (N1C->getAPIntValue().isPowerOf2() || - (-N1C->getAPIntValue()).isPowerOf2())) { + if (Divisor && !!*Divisor && + (Divisor->isPowerOf2() || (-*Divisor).isPowerOf2())) { // If dividing by powers of two is cheap, then don't perform the following // fold. if (TLI.isPow2DivCheap()) return SDValue(); - unsigned lg2 = N1C->getAPIntValue().countTrailingZeros(); + unsigned lg2 = Divisor->countTrailingZeros(); // Splat the sign bit into the register - SDValue SGN = DAG.getNode(ISD::SRA, SDLoc(N), VT, N0, - DAG.getConstant(VT.getSizeInBits()-1, - getShiftAmountTy(N0.getValueType()))); + SDValue SGN = + DAG.getNode(ISD::SRA, SDLoc(N), VT, N0, + DAG.getConstant(VT.getScalarSizeInBits() - 1, + getShiftAmountTy(N0.getValueType()))); AddToWorkList(SGN.getNode()); // Add (N0 < 0) ? abs2 - 1 : 0; - SDValue SRL = DAG.getNode(ISD::SRL, SDLoc(N), VT, SGN, - DAG.getConstant(VT.getSizeInBits() - lg2, - getShiftAmountTy(SGN.getValueType()))); + SDValue SRL = + DAG.getNode(ISD::SRL, SDLoc(N), VT, SGN, + DAG.getConstant(VT.getScalarSizeInBits() - lg2, + getShiftAmountTy(SGN.getValueType()))); SDValue ADD = DAG.getNode(ISD::ADD, SDLoc(N), VT, N0, SRL); AddToWorkList(SRL.getNode()); AddToWorkList(ADD.getNode()); // Divide by pow2 @@ -2014,12 +2026,11 @@ SDValue DAGCombiner::visitSDIV(SDNode *N) { // If we're dividing by a positive value, we're done. Otherwise, we must // negate the result. - if (N1C->getAPIntValue().isNonNegative()) + if (Divisor->isNonNegative()) return SRA; AddToWorkList(SRA.getNode()); - return DAG.getNode(ISD::SUB, SDLoc(N), VT, - DAG.getConstant(0, VT), SRA); + return DAG.getNode(ISD::SUB, SDLoc(N), VT, DAG.getConstant(0, VT), SRA); } // if integer divide is expensive and we satisfy the requirements, emit an |