[llvm] [slp] fix scheduler deadlock for copyable users of vectorized instructions (PR #176661)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 19 09:47:19 PST 2026


https://github.com/Serosh-commits updated https://github.com/llvm/llvm-project/pull/176661

>From acfdafec6875ad9fa9dd7e3ac96c020b98e6bc86 Mon Sep 17 00:00:00 2001
From: Serosh <janmejayapanda400 at gmail.com>
Date: Mon, 19 Jan 2026 07:43:34 +0530
Subject: [PATCH] [SLP] Fix scheduler deadlock by filtering non-schedulable
 nodes early

This avoids a deadlock where a schedulable node depends on a non-schedulable
one. By skipping bundle creation for these nodes, we let them fall back to
individual scalars, which breaks the dependency cycle.

Fixes #176658
---
 .../Transforms/Vectorize/SLPVectorizer.cpp    | 20 ++-----
 .../X86/gh176658-scheduler-deadlock.ll        | 53 +++++++++++++++++++
 2 files changed, 58 insertions(+), 15 deletions(-)
 create mode 100644 llvm/test/Transforms/SLPVectorizer/X86/gh176658-scheduler-deadlock.ll

diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 4c4901c314406..81d526ba0e867 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -21730,27 +21730,17 @@ BoUpSLP::BlockScheduling::tryScheduleBundle(ArrayRef<Value *> VL, BoUpSLP *SLP,
   if (isa<PHINode>(S.getMainOp()) ||
       isVectorLikeInstWithConstOps(S.getMainOp()))
     return nullptr;
+
+  if (S.areInstructionsWithCopyableElements() && EI && EI.UserTE->hasState() &&
+      EI.UserTE->doesNotNeedToSchedule())
+    return nullptr;
+
   // If the parent node is non-schedulable and the current node is copyable, and
   // any of parent instructions are used outside several basic blocks or in
   // bin-op node - cancel scheduling, it may cause wrong def-use deps in
   // analysis, leading to a crash.
   // Non-scheduled nodes may not have related ScheduleData model, which may lead
   // to a skipped dep analysis.
-  if (S.areInstructionsWithCopyableElements() && EI && EI.UserTE->hasState() &&
-      EI.UserTE->doesNotNeedToSchedule() &&
-      EI.UserTE->getOpcode() != Instruction::PHI &&
-      any_of(EI.UserTE->Scalars, [](Value *V) {
-        auto *I = dyn_cast<Instruction>(V);
-        if (!I || I->hasOneUser())
-          return false;
-        for (User *U : I->users()) {
-          auto *UI = cast<Instruction>(U);
-          if (isa<BinaryOperator>(UI))
-            return true;
-        }
-        return false;
-      }))
-    return std::nullopt;
   if (S.areInstructionsWithCopyableElements() && EI && EI.UserTE->hasState() &&
       EI.UserTE->hasCopyableElements() &&
       EI.UserTE->getMainOp()->getParent() == S.getMainOp()->getParent() &&
diff --git a/llvm/test/Transforms/SLPVectorizer/X86/gh176658-scheduler-deadlock.ll b/llvm/test/Transforms/SLPVectorizer/X86/gh176658-scheduler-deadlock.ll
new file mode 100644
index 0000000000000..96006ca030dd9
--- /dev/null
+++ b/llvm/test/Transforms/SLPVectorizer/X86/gh176658-scheduler-deadlock.ll
@@ -0,0 +1,53 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -passes=slp-vectorizer -slp-threshold=-99999 -S | FileCheck %s
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128-ni:1-p2:32:8:8:32-ni:2"
+target triple = "x86_64-unknown-linux-gnu"
+
+define i32 @gh176658() #0 gc "statepoint-example" {
+;
+; CHECK-LABEL: @gh176658(
+; CHECK-NEXT:  bb:
+; CHECK-NEXT:    br label [[BB3:%.*]]
+; CHECK:       bb1:
+; CHECK-NEXT:    [[TMP0:%.*]] = phi <2 x i32> [ [[TMP8:%.*]], [[BB3]] ]
+; CHECK-NEXT:    ret i32 0
+; CHECK:       bb3:
+; CHECK-NEXT:    [[TMP1:%.*]] = phi <2 x i32> [ zeroinitializer, [[BB:%.*]] ], [ [[TMP11:%.*]], [[BB3]] ]
+; CHECK-NEXT:    [[LOAD:%.*]] = load i64, ptr addrspace(1) null, align 8
+; CHECK-NEXT:    [[TMP2:%.*]] = trunc i64 [[LOAD]] to i32
+; CHECK-NEXT:    [[TMP3:%.*]] = insertelement <2 x i32> <i32 0, i32 poison>, i32 [[TMP2]], i32 1
+; CHECK-NEXT:    [[TMP4:%.*]] = and <2 x i32> [[TMP3]], <i32 0, i32 -1>
+; CHECK-NEXT:    [[TMP5:%.*]] = extractelement <2 x i32> [[TMP4]], i32 0
+; CHECK-NEXT:    [[ASHR:%.*]] = ashr i32 0, [[TMP5]]
+; CHECK-NEXT:    [[TMP6:%.*]] = ashr <2 x i32> [[TMP1]], [[TMP4]]
+; CHECK-NEXT:    [[TMP7:%.*]] = or <2 x i32> [[TMP1]], [[TMP4]]
+; CHECK-NEXT:    [[TMP8]] = shufflevector <2 x i32> [[TMP6]], <2 x i32> [[TMP7]], <2 x i32> <i32 0, i32 3>
+; CHECK-NEXT:    [[TMP9:%.*]] = shufflevector <2 x i32> [[TMP8]], <2 x i32> [[TMP1]], <2 x i32> <i32 0, i32 3>
+; CHECK-NEXT:    [[TMP10:%.*]] = shufflevector <2 x i32> [[TMP3]], <2 x i32> <i32 0, i32 poison>, <2 x i32> <i32 2, i32 1>
+; CHECK-NEXT:    [[TMP11]] = or <2 x i32> [[TMP9]], [[TMP10]]
+; CHECK-NEXT:    br i1 false, label [[BB1:%.*]], label [[BB3]]
+;
+bb:
+  br label %bb3
+
+bb1:
+  %phi = phi i32 [ %or, %bb3 ]
+  %phi2 = phi i32 [ %ashr7, %bb3 ]
+  ret i32 0
+
+bb3:
+  %phi4 = phi i32 [ 0, %bb ], [ %or, %bb3 ]
+  %phi5 = phi i32 [ 0, %bb ], [ %or8, %bb3 ]
+  %load = load i64, ptr addrspace(1) null, align 8
+  %trunc = trunc i64 %load to i32
+  %or = or i32 %phi4, %trunc
+  %trunc6 = trunc i64 0 to i32
+  %and = and i32 %trunc6, 0
+  %ashr = ashr i32 0, %and
+  %ashr7 = ashr i32 %phi5, %and
+  %or8 = or i32 %ashr7, 0
+  br i1 false, label %bb1, label %bb3
+}
+
+attributes #0 = { "target-features"="+avx2" }



More information about the llvm-commits mailing list