diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index dc0dffd9fcbf8..26dea50ae0b50 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -15713,16 +15713,18 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) { LLVM_DEBUG(dbgs() << "SLP: Diamond merged for " << *VL0 << ".\n"); return E->VectorizedValue; } - assert(isa(Src) && - "Not supported shufflevector usage."); - auto *SVSrc = cast(Src); - assert(isa(SVSrc->getOperand(1)) && - "Not supported shufflevector usage."); SmallVector ThisMask(calculateShufflevectorMask(E->Scalars)); - SmallVector NewMask(ThisMask.size()); - transform(ThisMask, NewMask.begin(), - [&SVSrc](int Mask) { return SVSrc->getShuffleMask()[Mask]; }); - V = Builder.CreateShuffleVector(SVSrc->getOperand(0), NewMask); + if (auto *SVSrc = dyn_cast(Src)) { + assert(isa(SVSrc->getOperand(1)) && + "Not supported shufflevector usage."); + SmallVector NewMask(ThisMask.size()); + transform(ThisMask, NewMask.begin(), [&SVSrc](int Mask) { + return SVSrc->getShuffleMask()[Mask]; + }); + V = Builder.CreateShuffleVector(SVSrc->getOperand(0), NewMask); + } else { + V = Builder.CreateShuffleVector(Src, ThisMask); + } propagateIRFlags(V, E->Scalars, VL0); if (auto *I = dyn_cast(V)) V = propagateMetadata(I, E->Scalars); diff --git a/llvm/test/Transforms/SLPVectorizer/revec-shufflevector.ll b/llvm/test/Transforms/SLPVectorizer/revec-shufflevector.ll index 8091c218addfa..a2673d81068d8 100644 --- a/llvm/test/Transforms/SLPVectorizer/revec-shufflevector.ll +++ b/llvm/test/Transforms/SLPVectorizer/revec-shufflevector.ll @@ -105,3 +105,19 @@ entry: store <4 x i32> %2, ptr %6, align 4 ret void } + +define void @test5(ptr %out) { +; CHECK-LABEL: @test5( +; CHECK-NEXT: entry: +; CHECK-NEXT: store <8 x i32> zeroinitializer, ptr [[OUT:%.*]], align 4 +; CHECK-NEXT: ret void +; +entry: + %0 = shufflevector <8 x i32> zeroinitializer, <8 x i32> poison, <4 x i32> + %1 = shufflevector <8 x i32> zeroinitializer, <8 x i32> poison, <4 x i32> + %2 = getelementptr inbounds i32, ptr %out, i64 0 + %3 = getelementptr inbounds i32, ptr %out, i64 4 + store <4 x i32> %0, ptr %2, align 4 + store <4 x i32> %1, ptr %3, align 4 + ret void +}