[PATCH] D94972: [SLP]Need to shrink the load vector after reordering.
Alexey Bataev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 19 07:37:40 PST 2021
ABataev created this revision.
ABataev added reviewers: RKSimon, spatel, dtemirbulatov, anton-afanasyev.
Herald added a subscriber: hiraditya.
ABataev requested review of this revision.
Herald added a project: LLVM.
After merging the shuffles, we cannot rely on the previous shuffle
anymore and need to shrink the final shuffle, if it is required.
Reported in D92668 <https://reviews.llvm.org/D92668>.
The previous patch in D93967 <https://reviews.llvm.org/D93967> was reverted because the original code had a bug. This patch fixes it.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D94972
Files:
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
llvm/test/Transforms/SLPVectorizer/X86/shrink_after_reorder.ll
Index: llvm/test/Transforms/SLPVectorizer/X86/shrink_after_reorder.ll
===================================================================
--- llvm/test/Transforms/SLPVectorizer/X86/shrink_after_reorder.ll
+++ llvm/test/Transforms/SLPVectorizer/X86/shrink_after_reorder.ll
@@ -10,7 +10,8 @@
; CHECK-NEXT: [[TMP1:%.*]] = load <2 x i32>, <2 x i32>* [[TMP0]], align 8
; CHECK-NEXT: [[SHUFFLE:%.*]] = shufflevector <2 x i32> [[TMP1]], <2 x i32> poison, <4 x i32> <i32 1, i32 0, i32 1, i32 0>
; CHECK-NEXT: [[TMP27:%.*]] = getelementptr inbounds i32, i32* [[PTR1:%.*]], i32 3
-; CHECK-NEXT: [[TMP2:%.*]] = add nsw <2 x i32> [[TMP1]], <i32 -1, i32 -1>
+; CHECK-NEXT: [[SHRINK_SHUFFLE:%.*]] = shufflevector <4 x i32> [[SHUFFLE]], <4 x i32> poison, <2 x i32> <i32 0, i32 1>
+; CHECK-NEXT: [[TMP2:%.*]] = add nsw <2 x i32> [[SHRINK_SHUFFLE]], <i32 -1, i32 -1>
; CHECK-NEXT: [[SHUFFLE1:%.*]] = shufflevector <2 x i32> [[TMP2]], <2 x i32> poison, <4 x i32> <i32 0, i32 1, i32 0, i32 1>
; CHECK-NEXT: [[TMP34:%.*]] = getelementptr inbounds i32, i32* [[PTR1]], i32 4
; CHECK-NEXT: [[TMP40:%.*]] = getelementptr inbounds i32, i32* [[PTR1]], i32 5
@@ -65,7 +66,7 @@
; CHECK-NEXT: entry:
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
; CHECK: for.body:
-; CHECK-NEXT: [[TMP0:%.*]] = phi <2 x i16> [ undef, [[ENTRY:%.*]] ], [ [[TMP0]], [[IF_END:%.*]] ]
+; CHECK-NEXT: [[TMP0:%.*]] = phi <2 x i16> [ undef, [[ENTRY:%.*]] ], [ [[SHRINK_SHUFFLE:%.*]], [[IF_END:%.*]] ]
; CHECK-NEXT: [[SHUFFLE:%.*]] = shufflevector <2 x i16> [[TMP0]], <2 x i16> poison, <8 x i32> <i32 0, i32 0, i32 0, i32 0, i32 1, i32 1, i32 1, i32 1>
; CHECK-NEXT: br label [[IF_END]]
; CHECK: if.end:
@@ -77,6 +78,7 @@
; CHECK-NEXT: [[ARRAYIDX11_6:%.*]] = getelementptr inbounds i16, i16* undef, i32 6
; CHECK-NEXT: [[ARRAYIDX11_7:%.*]] = getelementptr inbounds i16, i16* undef, i32 7
; CHECK-NEXT: store <8 x i16> [[SHUFFLE]], <8 x i16>* undef, align 2
+; CHECK-NEXT: [[SHRINK_SHUFFLE]] = shufflevector <8 x i16> [[SHUFFLE]], <8 x i16> poison, <2 x i32> <i32 0, i32 4>
; CHECK-NEXT: br label [[FOR_BODY]]
;
entry:
Index: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -4274,18 +4274,16 @@
if (E->isSame(VL)) {
Value *V = vectorizeTree(E);
if (VL.size() == E->Scalars.size() && !E->ReuseShuffleIndices.empty()) {
- // We need to get the vectorized value but without shuffle.
- if (auto *SV = dyn_cast<ShuffleVectorInst>(V)) {
- V = SV->getOperand(0);
- } else {
- // Reshuffle to get only unique values.
- SmallVector<int, 4> UniqueIdxs;
- SmallSet<int, 4> UsedIdxs;
- for (int Idx : E->ReuseShuffleIndices)
- if (UsedIdxs.insert(Idx).second)
- UniqueIdxs.emplace_back(Idx);
- V = Builder.CreateShuffleVector(V, UniqueIdxs);
+ // Reshuffle to get only unique values.
+ SmallVector<int, 4> UniqueIdxs;
+ SmallSet<int, 4> UsedIdxs;
+ int Pos = 0;
+ for (int Idx : E->ReuseShuffleIndices) {
+ if (UsedIdxs.insert(Idx).second)
+ UniqueIdxs.emplace_back(Pos);
+ ++Pos;
}
+ V = Builder.CreateShuffleVector(V, UniqueIdxs, "shrink.shuffle");
}
return V;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94972.317565.patch
Type: text/x-patch
Size: 3526 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210119/2aac799f/attachment.bin>
More information about the llvm-commits
mailing list