[llvm] [SLP][REVEC] Make shufflevector can be vectorized with ReorderIndices and ReuseShuffleIndices. (PR #114965)

via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 5 02:32:36 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-vectorizers

Author: Han-Kuan Chen (HanKuanChen)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/114965.diff


2 Files Affected:

- (modified) llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp (+8-8) 
- (modified) llvm/test/Transforms/SLPVectorizer/revec-shufflevector.ll (+37) 


``````````diff
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 427b8bd0e75ab0..b14465ecc1dc91 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -15374,9 +15374,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) {
@@ -15394,6 +15391,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()) &&
@@ -15524,11 +15524,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;
diff --git a/llvm/test/Transforms/SLPVectorizer/revec-shufflevector.ll b/llvm/test/Transforms/SLPVectorizer/revec-shufflevector.ll
index 1fc0b0306d1194..39ba9d52d11e9b 100644
--- a/llvm/test/Transforms/SLPVectorizer/revec-shufflevector.ll
+++ b/llvm/test/Transforms/SLPVectorizer/revec-shufflevector.ll
@@ -82,3 +82,40 @@ entry:
   store <4 x i32> %4, ptr %8, align 4
   ret void
 }
+
+define void @test4(ptr %in) {
+; CHECK-LABEL: @test4(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    br label [[LABEL0:%.*]]
+; CHECK:       label0:
+; CHECK-NEXT:    br label [[LABEL2:%.*]]
+; CHECK:       label1:
+; CHECK-NEXT:    br label [[LABEL2]]
+; CHECK:       label2:
+; CHECK-NEXT:    br label [[LABEL0]]
+;
+entry:
+  br label %label0
+
+label0:
+  %0 = load <8 x float>, ptr %in, align 4
+  %1 = shufflevector <8 x float> %0, <8 x float> zeroinitializer, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
+  %2 = shufflevector <8 x float> %0, <8 x float> zeroinitializer, <4 x i32> <i32 4, i32 5, i32 6, i32 7>
+  %3 = call <4 x float> @llvm.fma.v4f32(<4 x float> %1, <4 x float> zeroinitializer, <4 x float> zeroinitializer)
+  %4 = call <4 x float> @llvm.fma.v4f32(<4 x float> %2, <4 x float> zeroinitializer, <4 x float> zeroinitializer)
+  %5 = call <4 x float> @llvm.fma.v4f32(<4 x float> %1, <4 x float> zeroinitializer, <4 x float> zeroinitializer)
+  %6 = call <4 x float> @llvm.fma.v4f32(<4 x float> %2, <4 x float> zeroinitializer, <4 x float> zeroinitializer)
+  br label %label2
+
+label1:
+  br label %label2
+
+label2:
+  %7 = phi <4 x float> [ %3, %label0 ], [ zeroinitializer, %label1 ]
+  %8 = phi <4 x float> [ %4, %label0 ], [ zeroinitializer, %label1 ]
+  %9 = phi <4 x float> [ %5, %label0 ], [ zeroinitializer, %label1 ]
+  %10 = phi <4 x float> [ %6, %label0 ], [ zeroinitializer, %label1 ]
+  br label %label0
+}
+
+declare <4 x float> @llvm.fma.v4f32(<4 x float>, <4 x float>, <4 x float>)

``````````

</details>


https://github.com/llvm/llvm-project/pull/114965


More information about the llvm-commits mailing list