[llvm] c6091cd - [SLP][REVEC] Make shufflevector can be vectorized with ReorderIndices and ReuseShuffleIndices. (#114965)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 6 19:04:38 PST 2024
Author: Han-Kuan Chen
Date: 2024-11-07T11:04:34+08:00
New Revision: c6091cdbedd86cdab0a0d0f18569bf28e016ed9d
URL: https://github.com/llvm/llvm-project/commit/c6091cdbedd86cdab0a0d0f18569bf28e016ed9d
DIFF: https://github.com/llvm/llvm-project/commit/c6091cdbedd86cdab0a0d0f18569bf28e016ed9d.diff
LOG: [SLP][REVEC] Make shufflevector can be vectorized with ReorderIndices and ReuseShuffleIndices. (#114965)
Added:
Modified:
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
llvm/test/Transforms/SLPVectorizer/revec-shufflevector.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 53e514766fee81..184413b420089a 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -15645,9 +15645,6 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) {
case Instruction::ShuffleVector: {
Value *V;
if (SLPReVec && !E->isAltShuffle()) {
- assert(E->ReuseShuffleIndices.empty() &&
- "Not support ReuseShuffleIndices yet.");
- assert(E->ReorderIndices.empty() && "Not support ReorderIndices yet.");
setInsertPointAfterBundle(E);
Value *Src = vectorizeOperand(E, 0, PostponedPHIs);
if (E->VectorizedValue) {
@@ -15665,6 +15662,9 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) {
[&SVSrc](int Mask) { return SVSrc->getShuffleMask()[Mask]; });
V = Builder.CreateShuffleVector(SVSrc->getOperand(0), NewMask);
propagateIRFlags(V, E->Scalars, VL0);
+ if (auto *I = dyn_cast<Instruction>(V))
+ V = propagateMetadata(I, E->Scalars);
+ V = FinalShuffle(V, E);
} else {
assert(E->isAltShuffle() &&
((Instruction::isBinaryOp(E->getOpcode()) &&
@@ -15795,11 +15795,11 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) {
transformScalarShuffleIndiciesToVector(VecTy->getNumElements(), Mask);
}
V = Builder.CreateShuffleVector(V0, V1, Mask);
- }
- if (auto *I = dyn_cast<Instruction>(V)) {
- V = propagateMetadata(I, E->Scalars);
- GatherShuffleExtractSeq.insert(I);
- CSEBlocks.insert(I->getParent());
+ if (auto *I = dyn_cast<Instruction>(V)) {
+ V = propagateMetadata(I, E->Scalars);
+ GatherShuffleExtractSeq.insert(I);
+ CSEBlocks.insert(I->getParent());
+ }
}
E->VectorizedValue = V;
diff --git a/llvm/test/Transforms/SLPVectorizer/revec-shufflevector.ll b/llvm/test/Transforms/SLPVectorizer/revec-shufflevector.ll
index 1fc0b0306d1194..8091c218addfab 100644
--- a/llvm/test/Transforms/SLPVectorizer/revec-shufflevector.ll
+++ b/llvm/test/Transforms/SLPVectorizer/revec-shufflevector.ll
@@ -82,3 +82,26 @@ entry:
store <4 x i32> %4, ptr %8, align 4
ret void
}
+
+define void @test4(ptr %in, ptr %out) {
+; CHECK-LABEL: @test4(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[TMP0:%.*]] = load <8 x i32>, ptr [[IN:%.*]], align 4
+; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <8 x i32> [[TMP0]], <8 x i32> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
+; CHECK-NEXT: store <16 x i32> [[TMP1]], ptr [[OUT:%.*]], align 4
+; CHECK-NEXT: ret void
+;
+entry:
+ %0 = load <8 x i32>, ptr %in, align 4
+ %1 = shufflevector <8 x i32> %0, <8 x i32> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
+ %2 = shufflevector <8 x i32> %0, <8 x i32> poison, <4 x i32> <i32 4, i32 5, i32 6, i32 7>
+ %3 = getelementptr inbounds i32, ptr %out, i64 0
+ %4 = getelementptr inbounds i32, ptr %out, i64 4
+ %5 = getelementptr inbounds i32, ptr %out, i64 8
+ %6 = getelementptr inbounds i32, ptr %out, i64 12
+ store <4 x i32> %1, ptr %3, align 4
+ store <4 x i32> %2, ptr %4, align 4
+ store <4 x i32> %1, ptr %5, align 4
+ store <4 x i32> %2, ptr %6, align 4
+ ret void
+}
More information about the llvm-commits
mailing list