Skip to content

Commit a62c549

Browse files
authored
[SLP][REVEC] The vectorized result for ShuffleVector may not be ShuffleVectorInst. (#116940)
1 parent fce917d commit a62c549

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

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

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,19 @@ entry:
105105
store <4 x i32> %2, ptr %6, align 4
106106
ret void
107107
}
108+
109+
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+
;
115+
entry:
116+
%0 = shufflevector <8 x i32> zeroinitializer, <8 x i32> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
117+
%1 = shufflevector <8 x i32> zeroinitializer, <8 x i32> poison, <4 x i32> <i32 4, i32 5, i32 6, i32 7>
118+
%2 = getelementptr inbounds i32, ptr %out, i64 0
119+
%3 = getelementptr inbounds i32, ptr %out, i64 4
120+
store <4 x i32> %0, ptr %2, align 4
121+
store <4 x i32> %1, ptr %3, align 4
122+
ret void
123+
}

0 commit comments

Comments
 (0)