Skip to content

Commit f449be8

Browse files
committed
[SLP][REVEC] The vectorized result for ShuffleVector may not be
ShuffleVectorInst.
1 parent 0667878 commit f449be8

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15713,16 +15713,19 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) {
1571315713
LLVM_DEBUG(dbgs() << "SLP: Diamond merged for " << *VL0 << ".\n");
1571415714
return E->VectorizedValue;
1571515715
}
15716-
assert(isa<ShuffleVectorInst>(Src) &&
15717-
"Not supported shufflevector usage.");
15718-
auto *SVSrc = cast<ShuffleVectorInst>(Src);
15719-
assert(isa<PoisonValue>(SVSrc->getOperand(1)) &&
15720-
"Not supported shufflevector usage.");
1572115716
SmallVector<int> ThisMask(calculateShufflevectorMask(E->Scalars));
15722-
SmallVector<int> NewMask(ThisMask.size());
15723-
transform(ThisMask, NewMask.begin(),
15724-
[&SVSrc](int Mask) { return SVSrc->getShuffleMask()[Mask]; });
15725-
V = Builder.CreateShuffleVector(SVSrc->getOperand(0), NewMask);
15717+
if (isa<ShuffleVectorInst>(Src)) {
15718+
auto *SVSrc = cast<ShuffleVectorInst>(Src);
15719+
assert(isa<PoisonValue>(SVSrc->getOperand(1)) &&
15720+
"Not supported shufflevector usage.");
15721+
SmallVector<int> NewMask(ThisMask.size());
15722+
transform(ThisMask, NewMask.begin(), [&SVSrc](int Mask) {
15723+
return SVSrc->getShuffleMask()[Mask];
15724+
});
15725+
V = Builder.CreateShuffleVector(SVSrc->getOperand(0), NewMask);
15726+
} else {
15727+
V = Builder.CreateShuffleVector(Src, ThisMask);
15728+
}
1572615729
propagateIRFlags(V, E->Scalars, VL0);
1572715730
if (auto *I = dyn_cast<Instruction>(V))
1572815731
V = propagateMetadata(I, E->Scalars);

llvm/test/Transforms/SLPVectorizer/revec-shufflevector.ll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ entry:
107107
}
108108

109109
define void @test5(ptr %out) {
110+
; CHECK-LABEL: @test5(
111+
; CHECK-NEXT: entry:
112+
; CHECK-NEXT: store <8 x i32> zeroinitializer, ptr [[OUT:%.*]], align 4
113+
; CHECK-NEXT: ret void
114+
;
110115
entry:
111116
%0 = shufflevector <8 x i32> zeroinitializer, <8 x i32> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
112117
%1 = shufflevector <8 x i32> zeroinitializer, <8 x i32> poison, <4 x i32> <i32 4, i32 5, i32 6, i32 7>

0 commit comments

Comments
 (0)