From: Sanjay Patel Date: Mon, 22 Apr 2019 13:36:07 +0000 (+0000) Subject: [DAGCombiner] prepare shuffle-of-splat to handle more patterns; NFC X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f90f1ca6f1b9b1c8118148c13183fc22908eddea;p=llvm [DAGCombiner] prepare shuffle-of-splat to handle more patterns; NFC git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358884 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 202a98526a4..d5c2488a8c7 100644 --- a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -17936,11 +17936,17 @@ static SDValue combineTruncationShuffle(ShuffleVectorSDNode *SVN, // If splat-mask contains undef elements, we need to be careful about // introducing undef's in the folded mask which are not the result of composing // the masks of the shuffles. -static SDValue combineShuffleOfSplat(ArrayRef UserMask, - ShuffleVectorSDNode *Splat, - SelectionDAG &DAG) { +static SDValue combineShuffleOfSplatVal(ShuffleVectorSDNode *Shuf, + SelectionDAG &DAG) { + if (!Shuf->getOperand(1).isUndef()) + return SDValue(); + auto *Splat = dyn_cast(Shuf->getOperand(0)); + if (!Splat || !Splat->isSplat()) + return SDValue(); + + ArrayRef Mask = Shuf->getMask(); ArrayRef SplatMask = Splat->getMask(); - assert(UserMask.size() == SplatMask.size() && "Mask length mismatch"); + assert(Mask.size() == SplatMask.size() && "Mask length mismatch"); // Prefer simplifying to the splat-shuffle, if possible. This is legal if // every undef mask element in the splat-shuffle has a corresponding undef @@ -17966,13 +17972,13 @@ static SDValue combineShuffleOfSplat(ArrayRef UserMask, return false; return true; }; - if (CanSimplifyToExistingSplat(UserMask, SplatMask)) - return SDValue(Splat, 0); + if (CanSimplifyToExistingSplat(Mask, SplatMask)) + return Shuf->getOperand(0); // Create a new shuffle with a mask that is composed of the two shuffles' // masks. SmallVector NewMask; - for (int Idx : UserMask) + for (int Idx : Mask) NewMask.push_back(Idx == -1 ? -1 : SplatMask[Idx]); return DAG.getVectorShuffle(Splat->getValueType(0), SDLoc(Splat), @@ -18135,10 +18141,9 @@ SDValue DAGCombiner::visitVECTOR_SHUFFLE(SDNode *N) { if (SDValue InsElt = replaceShuffleOfInsert(SVN, DAG)) return InsElt; - // A shuffle of a single vector that is a splat can always be folded. - if (auto *N0Shuf = dyn_cast(N0)) - if (N1->isUndef() && N0Shuf->isSplat()) - return combineShuffleOfSplat(SVN->getMask(), N0Shuf, DAG); + // A shuffle of a single vector that is a splatted value can always be folded. + if (SDValue V = combineShuffleOfSplatVal(SVN, DAG)) + return V; // If it is a splat, check if the argument vector is another splat or a // build_vector.