Bug type: crash
Component: SLPVectorizer
Bug location: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp: BoUpSLP::BlockScheduling::tryScheduleBundle
Issue title: Assertion `all_of(Bundles, [](const ScheduleBundle *Bundle) { return Bundle->isScheduled(); }) && "must be scheduled at this point"' failed.
Labels: llvm:SLPVectorizer
crash-on-valid
Reported by: gregbedwell

Not bisected yet, but a recent regression (at least in terms of the full C++ level test-case that the following is reduced from):

https://godbolt.org/z/qcMY4W9PP

```
define float @widget() {
bb:
  %fadd = fadd float 0.000000e+00, 0.000000e+00
  %load = load float, ptr null, align 4
  %fadd1 = fadd float %fadd, %load
  %fadd2 = fadd float 0.000000e+00, 0.000000e+00
  %fmul = fmul float 0.000000e+00, 0.000000e+00
  %fmul3 = fmul float 0.000000e+00, 0.000000e+00
  %fadd4 = fadd float %fmul3, 0.000000e+00
  br i1 false, label %bb5, label %bb6

bb5:                                              ; preds = %bb
  br label %bb8

bb6:                                              ; preds = %bb
  %fdiv = fdiv float %fadd1, 0.000000e+00
  %fdiv7 = fdiv float %fadd2, 0.000000e+00
  br label %bb8

bb8:                                              ; preds = %bb6, %bb5
  %phi = phi float [ 0.000000e+00, %bb5 ], [ %fdiv7, %bb6 ]
  %phi9 = phi float [ %fmul, %bb5 ], [ 0.000000e+00, %bb6 ]
  %phi10 = phi float [ %fadd4, %bb5 ], [ %load, %bb6 ]
  %phi11 = phi float [ %fadd1, %bb5 ], [ %fdiv, %bb6 ]
  ret float %phi11
}
```


```
opt: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:22650: void llvm::slpvectorizer::BoUpSLP::scheduleBlock(const llvm::slpvectorizer::BoUpSLP&, llvm::slpvectorizer::BoUpSLP::BlockScheduling*): Assertion `all_of(Bundles, [](const ScheduleBundle *Bundle) { return Bundle->isScheduled(); }) && "must be scheduled at this point"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0.	Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S --passes=slp-vectorizer <source>
1.	Running pass "function(slp-vectorizer)" on module "<source>"
2.	Running pass "slp-vectorizer" on function "widget"
 #0 0x0000000005a7a2e8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5a7a2e8)
 #1 0x0000000005a77194 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #2 0x000070bc0b842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x000070bc0b8969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #4 0x000070bc0b842476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #5 0x000070bc0b8287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #6 0x000070bc0b82871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #7 0x000070bc0b839e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #8 0x000000000380c32a llvm::slpvectorizer::BoUpSLP::scheduleBlock(llvm::slpvectorizer::BoUpSLP const&, llvm::slpvectorizer::BoUpSLP::BlockScheduling*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x380c32a)
 #9 0x000000000386090a llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::SmallDenseSet<llvm::Value*, 4u, llvm::DenseMapInfo<llvm::Value*, void>> const&, llvm::Instruction*, llvm::ArrayRef<std::tuple<llvm::Value*, unsigned int, bool>>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x386090a)
#10 0x0000000003864e34 llvm::slpvectorizer::BoUpSLP::vectorizeTree() (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3864e34)
#11 0x0000000003885b24 llvm::SLPVectorizerPass::tryToVectorizeList(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3885b24)
#12 0x000000000388a41c bool tryToVectorizeSequence<llvm::Value>(llvm::SmallVectorImpl<llvm::Value*>&, llvm::function_ref<bool (llvm::Value*, llvm::Value*)>, llvm::function_ref<bool (llvm::ArrayRef<llvm::Value*>, llvm::Value*)>, llvm::function_ref<bool (llvm::ArrayRef<llvm::Value*>, bool)>, bool, llvm::slpvectorizer::BoUpSLP&) (.constprop.0) SLPVectorizer.cpp:0:0
#13 0x000000000388b6ac llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x388b6ac)
#14 0x00000000038935b6 llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (.part.0) SLPVectorizer.cpp:0:0
#15 0x00000000038941cb llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x38941cb)
#16 0x000000000304051e llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x304051e)
#17 0x0000000005854c81 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5854c81)
#18 0x0000000000f1b1de llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xf1b1de)
#19 0x000000000585323a llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x585323a)
#20 0x000000000097edfe llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x97edfe)
#21 0x0000000005852bf1 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5852bf1)
#22 0x00000000009890b0 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x9890b0)
#23 0x000000000097cfd8 optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x97cfd8)
#24 0x000070bc0b829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#25 0x000070bc0b829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#26 0x00000000009739d5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x9739d5)
Program terminated with signal: SIGSEGV
Compiler returned: 139
```


Fix patch:
commit 39456e4226f41213a603f75a363b6bad9f7caf39
Author: Alexey Bataev <a.bataev@outlook.com>
Date:   Wed Jan 7 08:57:02 2026 -0800

    [SLP]Do not increment dep count for non-schedulable nodes with non-schedulable parents
    
    If the node is non-scedulable, all instructions are used outside only
    and parent is non-schedulable non-phi node, the dependency count should be
    increased for such nodes
    
    Fixes #174599

diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 5bd274a27549..cc78d0189066 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -21808,8 +21808,15 @@ BoUpSLP::BlockScheduling::tryScheduleBundle(ArrayRef<Value *> VL, BoUpSLP *SLP,
     }
     if (!ControlDependentMembers.empty()) {
       ScheduleBundle Invalid = ScheduleBundle::invalid();
+      bool IsNonSchedulableWithParentPhiNode =
+          EI.UserTE->hasState() &&
+          EI.UserTE->State != TreeEntry::SplitVectorize &&
+          EI.UserTE->getOpcode() == Instruction::PHI;
       calculateDependencies(Invalid, /*InsertInReadyList=*/true, SLP,
-                            ControlDependentMembers, /*NonSchedulable=*/true);
+                            ControlDependentMembers,
+                            /*NonSchedulable=*/HasCopyables ||
+                                IsNonSchedulableWithParentPhiNode ||
+                                !all_of(VL, isUsedOutsideBlock));
     }
     return nullptr;
   }


Regression tests:
file: llvm/test/Transforms/SLPVectorizer/X86/non-schedulable-node-with-non-schedulable-parent.ll
commands: opt -passes=slp-vectorizer -S -mtriple=x86_64 < %s
tests: test_name: <module>
test_body: 
define float @test() {
;
bb:
  %fadd = fadd float 0.000000e+00, 0.000000e+00
  %load = load float, ptr null, align 4
  %fadd1 = fadd float %fadd, %load
  %fadd2 = fadd float 0.000000e+00, 0.000000e+00
  %fmul = fmul float 0.000000e+00, 0.000000e+00
  %fmul3 = fmul float 0.000000e+00, 0.000000e+00
  %fadd4 = fadd float %fmul3, 0.000000e+00
  br i1 false, label %bb5, label %bb6

bb5:
  br label %bb8

bb6:
  %fdiv = fdiv float %fadd1, 0.000000e+00
  %fdiv7 = fdiv float %fadd2, 0.000000e+00
  br label %bb8

bb8:
  %phi = phi float [ 0.000000e+00, %bb5 ], [ %fdiv7, %bb6 ]
  %phi9 = phi float [ %fmul, %bb5 ], [ 0.000000e+00, %bb6 ]
  %phi10 = phi float [ %fadd4, %bb5 ], [ %load, %bb6 ]
  %phi11 = phi float [ %fadd1, %bb5 ], [ %fdiv, %bb6 ]
  ret float %phi11
}