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(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(V)) { - V = propagateMetadata(I, E->Scalars); - GatherShuffleExtractSeq.insert(I); - CSEBlocks.insert(I->getParent()); + if (auto *I = dyn_cast(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> +; 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> + %2 = shufflevector <8 x i32> %0, <8 x i32> poison, <4 x i32> + %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 +}