[llvm] 8c013a1 - [SLP]Do not stop the seed scan when a dependent seed is skipped

via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 18 04:29:01 PDT 2026


Author: Alexey Bataev
Date: 2026-09-18T07:28:55-04:00
New Revision: 8c013a1947a8c9fbe22fed19fdb2da1b2513aa5e

URL: https://github.com/llvm/llvm-project/commit/8c013a1947a8c9fbe22fed19fdb2da1b2513aa5e
DIFF: https://github.com/llvm/llvm-project/commit/8c013a1947a8c9fbe22fed19fdb2da1b2513aa5e.diff

LOG: [SLP]Do not stop the seed scan when a dependent seed is skipped

The dependency check leaves the current window short, and the
not-enough-instructions exit then ends the whole start-position scan for
the current VF, so later independent operations are never tried. Keep
scanning from the next position when the shortfall was caused by a
skipped dependent seed.

Fixes #224286

Reviewers: 

Pull Request: https://github.com/llvm/llvm-project/pull/224606

Added: 
    

Modified: 
    llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
    llvm/test/Transforms/SLPVectorizer/X86/dependent-seeds.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 10b27edb97362..8a01bcd9cc4f5 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -29812,6 +29812,7 @@ bool SLPVectorizerPass::tryToVectorizeList(ArrayRef<Value *> VL, BoUpSLP &R,
       SmallVector<Value *> Ops(ActualVF, nullptr);
       unsigned Idx = 0;
       SmallPtrSet<const Value *, 8> Taken;
+      bool DependentSkipped = false;
       for (Value *V : VL.drop_front(I)) {
         // Check that a previous iteration of this loop did not delete the
         // Value.
@@ -29822,8 +29823,10 @@ bool SLPVectorizerPass::tryToVectorizeList(ArrayRef<Value *> VL, BoUpSLP &R,
         // already taken one, is left for the next window.
         if (StandaloneSeeds && Inst &&
             any_of(Inst->operand_values(),
-                   [&](const Value *Op) { return Taken.contains(Op); }))
+                   [&](const Value *Op) { return Taken.contains(Op); })) {
+          DependentSkipped = true;
           continue;
+        }
         Ops[Idx] = V;
         if (StandaloneSeeds)
           Taken.insert(V);
@@ -29831,9 +29834,13 @@ bool SLPVectorizerPass::tryToVectorizeList(ArrayRef<Value *> VL, BoUpSLP &R,
         if (Idx == ActualVF)
           break;
       }
-      // Not enough vectorizable instructions - exit.
-      if (Idx != ActualVF)
-        break;
+      // Not enough vectorizable instructions - exit. A skipped dependent seed
+      // may start the next window, so the scan must not stop because of it.
+      if (Idx != ActualVF) {
+        if (!DependentSkipped)
+          break;
+        continue;
+      }
 
       // The identical lanes compute the very same value, so the vector node
       // only duplicates it, and the window, rejected by another attempt in the

diff  --git a/llvm/test/Transforms/SLPVectorizer/X86/dependent-seeds.ll b/llvm/test/Transforms/SLPVectorizer/X86/dependent-seeds.ll
index 3c29db3aa17d3..536129fb76570 100644
--- a/llvm/test/Transforms/SLPVectorizer/X86/dependent-seeds.ll
+++ b/llvm/test/Transforms/SLPVectorizer/X86/dependent-seeds.ll
@@ -6,10 +6,13 @@ define { float, float, float } @test(float %x0, float %x1, float %x2, float %x3)
 ; CHECK-SAME: float [[X0:%.*]], float [[X1:%.*]], float [[X2:%.*]], float [[X3:%.*]]) {
 ; CHECK-NEXT:    [[Q0:%.*]] = fdiv float [[X0]], 3.000000e+00
 ; CHECK-NEXT:    [[Q1:%.*]] = fdiv float [[X1]], [[Q0]]
-; CHECK-NEXT:    [[Q2:%.*]] = fdiv float [[X2]], 5.000000e+00
-; CHECK-NEXT:    [[Q3:%.*]] = fdiv float [[X3]], 7.000000e+00
+; CHECK-NEXT:    [[TMP1:%.*]] = insertelement <2 x float> poison, float [[X2]], i64 0
+; CHECK-NEXT:    [[TMP2:%.*]] = insertelement <2 x float> [[TMP1]], float [[X3]], i64 1
+; CHECK-NEXT:    [[TMP3:%.*]] = fdiv <2 x float> [[TMP2]], <float 5.000000e+00, float 7.000000e+00>
 ; CHECK-NEXT:    [[R0:%.*]] = insertvalue { float, float, float } poison, float [[Q1]], 0
+; CHECK-NEXT:    [[Q2:%.*]] = extractelement <2 x float> [[TMP3]], i64 0
 ; CHECK-NEXT:    [[R1:%.*]] = insertvalue { float, float, float } [[R0]], float [[Q2]], 1
+; CHECK-NEXT:    [[Q3:%.*]] = extractelement <2 x float> [[TMP3]], i64 1
 ; CHECK-NEXT:    [[R2:%.*]] = insertvalue { float, float, float } [[R1]], float [[Q3]], 2
 ; CHECK-NEXT:    ret { float, float, float } [[R2]]
 ;


        


More information about the llvm-commits mailing list