Skip to content

Commit

Permalink
[SLP][REVEC] Make shufflevector can be vectorized with ReorderIndices…
Browse files Browse the repository at this point in the history
… and ReuseShuffleIndices. (#114965)
  • Loading branch information
HanKuanChen authored Nov 7, 2024
1 parent 70bc12e commit c6091cd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
16 changes: 8 additions & 8 deletions llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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()) &&
Expand Down Expand Up @@ -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;
Expand Down
23 changes: 23 additions & 0 deletions llvm/test/Transforms/SLPVectorizer/revec-shufflevector.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit c6091cd

Please sign in to comment.