diff options
author | Simon Pilgrim <llvm-dev@redking.me.uk> | 2018-06-18 16:25:01 +0000 |
---|---|---|
committer | Simon Pilgrim <llvm-dev@redking.me.uk> | 2018-06-18 16:25:01 +0000 |
commit | 5b962b2fc345a66cd40cd9f1ac65d8b3b55ab794 (patch) | |
tree | d06614ac1078a5ee4e43dc2e104614c41724dc76 /llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | |
parent | 88c142b42bedb78b3f2c1fb4995697c64859c027 (diff) | |
download | bcm5719-llvm-5b962b2fc345a66cd40cd9f1ac65d8b3b55ab794.tar.gz bcm5719-llvm-5b962b2fc345a66cd40cd9f1ac65d8b3b55ab794.zip |
[SLPVectorizer] Tidyup isShuffle helper
Ensure we keep track of the input vectors in all cases instead of just for SK_Select.
Ideally we'd reuse the shuffle mask pattern matching in TargetTransformInfo::getInstructionThroughput here to easily add support for all TargetTransformInfo::ShuffleKind without mass code duplication, I've added a TODO for now but D48236 should help us here.
Differential Revision: https://reviews.llvm.org/D48023
llvm-svn: 334958
Diffstat (limited to 'llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp')
-rw-r--r-- | llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 41 |
1 files changed, 10 insertions, 31 deletions
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 5864dfa0c07..054c0a2c6fa 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -246,13 +246,15 @@ static bool isSplat(ArrayRef<Value *> VL) { /// %ins4 = insertelement <4 x i8> %ins3, i8 %9, i32 3 /// ret <4 x i8> %ins4 /// InstCombiner transforms this into a shuffle and vector mul +/// TODO: Can we split off and reuse the shuffle mask detection from +/// TargetTransformInfo::getInstructionThroughput? static Optional<TargetTransformInfo::ShuffleKind> isShuffle(ArrayRef<Value *> VL) { auto *EI0 = cast<ExtractElementInst>(VL[0]); unsigned Size = EI0->getVectorOperandType()->getVectorNumElements(); Value *Vec1 = nullptr; Value *Vec2 = nullptr; - enum ShuffleMode {Unknown, FirstAlternate, SecondAlternate, Permute}; + enum ShuffleMode { Unknown, Select, Permute }; ShuffleMode CommonShuffleMode = Unknown; for (unsigned I = 0, E = VL.size(); I < E; ++I) { auto *EI = cast<ExtractElementInst>(VL[I]); @@ -272,7 +274,11 @@ isShuffle(ArrayRef<Value *> VL) { continue; // For correct shuffling we have to have at most 2 different vector operands // in all extractelement instructions. - if (Vec1 && Vec2 && Vec != Vec1 && Vec != Vec2) + if (!Vec1 || Vec1 == Vec) + Vec1 = Vec; + else if (!Vec2 || Vec2 == Vec) + Vec2 = Vec; + else return None; if (CommonShuffleMode == Permute) continue; @@ -282,37 +288,10 @@ isShuffle(ArrayRef<Value *> VL) { CommonShuffleMode = Permute; continue; } - // Check the shuffle mode for the current operation. - if (!Vec1) - Vec1 = Vec; - else if (Vec != Vec1) - Vec2 = Vec; - // Example: shufflevector A, B, <0,5,2,7> - // I is odd and IntIdx for A == I - FirstAlternate shuffle. - // I is even and IntIdx for B == I - FirstAlternate shuffle. - // Example: shufflevector A, B, <4,1,6,3> - // I is even and IntIdx for A == I - SecondAlternate shuffle. - // I is odd and IntIdx for B == I - SecondAlternate shuffle. - const bool IIsEven = I & 1; - const bool CurrVecIsA = Vec == Vec1; - const bool IIsOdd = !IIsEven; - const bool CurrVecIsB = !CurrVecIsA; - ShuffleMode CurrentShuffleMode = - ((IIsOdd && CurrVecIsA) || (IIsEven && CurrVecIsB)) ? FirstAlternate - : SecondAlternate; - // Common mode is not set or the same as the shuffle mode of the current - // operation - alternate. - if (CommonShuffleMode == Unknown) - CommonShuffleMode = CurrentShuffleMode; - // Common shuffle mode is not the same as the shuffle mode of the current - // operation - permutation. - if (CommonShuffleMode != CurrentShuffleMode) - CommonShuffleMode = Permute; + CommonShuffleMode = Select; } // If we're not crossing lanes in different vectors, consider it as blending. - if ((CommonShuffleMode == FirstAlternate || - CommonShuffleMode == SecondAlternate) && - Vec2) + if (CommonShuffleMode == Select && Vec2) return TargetTransformInfo::SK_Select; // If Vec2 was never used, we have a permutation of a single vector, otherwise // we have permutation of 2 vectors. |