Bug type: crash
Component: SLPVectorizer
Bug location: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp: findAndSetMainInstruction
Issue title: [SLPVectorizer] Assertion `ScheduleEnd && "tried to vectorize a terminator?"' failed.
Labels: llvm:SLPVectorizer
crash
Reported by: TatyanaDoubts

To reproduce run opt with the test below, -passes=slp-vectorizer
```
; ModuleID = './reduced.ll'
source_filename = "./reduced.ll"
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 void @wombat() gc "statepoint-example" personality ptr null {
bb:
  %add = add i32 0, 0
  %add1 = add i32 0, 0
  %invoke = invoke i32 null(ptr addrspace(1) null, i32 0, i32 0, i32 0)
          to label %bb2 unwind label %bb8

bb2:                                              ; preds = %bb
  %add3 = add i32 %invoke, 0
  br label %bb4

bb4:                                              ; preds = %bb2
  %phi = phi i32 [ %add3, %bb2 ]
  %phi5 = phi i32 [ 0, %bb2 ]
  %phi6 = phi i32 [ %add, %bb2 ]
  %phi7 = phi i32 [ %add1, %bb2 ]
  ret void

bb8:                                              ; preds = %bb
  %landingpad = landingpad { ptr, i32 }
          cleanup
  ret void
}
```
Reproducer: https://godbolt.org/z/njq5sde1d

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 "wombat"
 #0 0x00000000056fd7a8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x56fd7a8)
 #1 0x00000000056fa654 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #2 0x0000727df8242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x0000727df82969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #4 0x0000727df8242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #5 0x0000727df82287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #6 0x0000727df822871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #7 0x0000727df8239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #8 0x00000000035a390b llvm::slpvectorizer::BoUpSLP::BlockScheduling::tryScheduleBundle(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP*, (anonymous namespace)::InstructionsState const&, llvm::slpvectorizer::BoUpSLP::EdgeInfo const&) SLPVectorizer.cpp:0:0
 #9 0x00000000035e0d99 llvm::slpvectorizer::BoUpSLP::buildTreeRec(llvm::ArrayRef<llvm::Value*>, unsigned int, llvm::slpvectorizer::BoUpSLP::EdgeInfo const&, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x35e0d99)
#10 0x00000000035e1e58 llvm::slpvectorizer::BoUpSLP::buildTreeRec(llvm::ArrayRef<llvm::Value*>, unsigned int, llvm::slpvectorizer::BoUpSLP::EdgeInfo const&, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x35e1e58)
#11 0x00000000035e3601 llvm::slpvectorizer::BoUpSLP::buildTreeRec(llvm::ArrayRef<llvm::Value*>, unsigned int, llvm::slpvectorizer::BoUpSLP::EdgeInfo const&, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x35e3601)
#12 0x00000000036119c1 llvm::SLPVectorizerPass::tryToVectorizeList(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x36119c1)
#13 0x000000000361695d bool tryToVectorizeSequence<llvm::Value>(llvm::SmallVectorImpl<llvm::Value*>&, llvm::function_ref<bool (llvm::Value*, llvm::Value*)>, llvm::function_ref<bool (llvm::Value*, llvm::Value*)>, llvm::function_ref<bool (llvm::ArrayRef<llvm::Value*>, bool)>, bool, llvm::slpvectorizer::BoUpSLP&) (.constprop.0) SLPVectorizer.cpp:0:0
#14 0x000000000361802a llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x361802a)
#15 0x000000000361fec6 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
#16 0x0000000003620a1b llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3620a1b)
#17 0x0000000002e0752e 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+0x2e0752e)
#18 0x00000000054eb8b1 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x54eb8b1)
#19 0x0000000000ed995e 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+0xed995e)
#20 0x00000000054ebefa llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x54ebefa)
#21 0x000000000096d8fe 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+0x96d8fe)
#22 0x00000000054e9941 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x54e9941)
#23 0x0000000000977b9a 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+0x977b9a)
#24 0x000000000096bc67 optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x96bc67)
#25 0x0000727df8229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#26 0x0000727df8229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#27 0x0000000000962d85 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x962d85)
Program terminated with signal: SIGSEGV
Compiler returned: 139
```

Comments: author: danilaml
body: Seems to be caused by 2d7b55a028139dde58a994a65895841190dfde96 (at least it doesn't reproduce after revert). ping @alexey-bataev 
author: danilaml
body: Looks like `%invoke = invoke i32 null(ptr addrspace(1) null, i32 0, i32 0, i32 0)` is considered schedulable (`isNonSchedulable` returns `false` for it), which is wrong.

Fix patch:
commit eb39605192d36806ec0d41c8c54b0817be5d80c5
Author: Alexey Bataev <a.bataev@outlook.com>
Date:   Sat Aug 30 17:37:26 2025 -0700

    [SLP]Do not schedule terminate copyable from main op basic block
    
    If the copyable instruction is a terminate instruction from the same
    block, as the potential main instruction, such instruction cannot be
    copyable and the value list cannot be modeled as instructions with same
    (and copyables) opcodes.
    
    Fixes #155183

diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index dad0d1e9ef55..33418d86d51d 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -10638,8 +10638,19 @@ class InstructionsCompatibilityAnalysis {
         }
       }
     }
-    if (MainOp)
+    if (MainOp) {
+      // Do not match, if any copyable is a terminator from the same block as
+      // the main operation.
+      if (any_of(VL, [&](Value *V) {
+            auto *I = dyn_cast<Instruction>(V);
+            return I && I->getParent() == MainOp->getParent() &&
+                   I->isTerminator();
+          })) {
+        MainOp = nullptr;
+        return;
+      }
       MainOpcode = MainOp->getOpcode();
+    }
   }
 
   /// Returns the idempotent value for the \p MainOp with the detected \p


Regression tests:
file: llvm/test/Transforms/SLPVectorizer/X86/no-schedule-terminate-inst.ll
commands: opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s
tests: test_name: <module>
test_body: 
define void @test() gc "statepoint-example" personality ptr null {
;
bb:
  %add = add i32 0, 0
  %add1 = add i32 0, 0
  %invoke = invoke i32 null(ptr addrspace(1) null, i32 0, i32 0, i32 0)
  to label %bb2 unwind label %bb8

bb2:
  %add3 = add i32 %invoke, 0
  br label %bb4

bb4:
  %phi = phi i32 [ %add3, %bb2 ]
  %phi5 = phi i32 [ 0, %bb2 ]
  %phi6 = phi i32 [ %add, %bb2 ]
  %phi7 = phi i32 [ %add1, %bb2 ]
  ret void

bb8:
  %landingpad = landingpad { ptr, i32 }
  cleanup
  ret void
}