<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/95883>95883</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            SLPVectorizer pass raised exception with reproducible IR
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          BruceDai003
      </td>
    </tr>
</table>

<pre>
    I used llvm-reduce tool to simplify the test case:
```
define void @any_kernel_2_0d1d2de() {
  %1 = extractelement <4 x i8> zeroinitializer, i64 0
  %2 = extractelement <4 x i8> zeroinitializer, i64 0
  %3 = extractelement <4 x i8> zeroinitializer, i64 0
  %4 = extractelement <4 x i8> zeroinitializer, i64 0
  br label %5

5:                                                ; preds = %0
 %6 = or i8 %1, %2
  %7 = or i8 %6, %3
  %8 = or i8 %7, %4
  %9 = icmp ne i8 %8, 0
  ret void
}
```
This input IR will crash when going through the slp-vectorizer pass with command:
`./opt -S --passes=slp-vectorizer reduced.ll`
The raised exception is:
opt: /home/xx/tests/llvm/llvm-project/llvm/include/llvm/Support/Casting.h:662: decltype(auto) llvm::dyn_cast(From*) [with To = llvm::Instruction; From = llvm::Value]: Assertion `detail::isPresent(Val) && "dyn_cast on a non-existent value"' failed.

and the crash backtrace is:
```
Stack dump:
0.      Program arguments: ./opt -S --passes=slp-vectorizer ../../reduced.ll
 #0 0x0000559a45781650 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (./opt+0x2264650)
 #1 0x0000559a4577ef6f llvm::sys::RunSignalHandlers() (./opt+0x2261f6f)
 #2 0x0000559a4577f0c5 SignalHandler(int) Signals.cpp:0:0
 #3 0x00007f1f8589a520 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007f1f858ee9fc pthread_kill (/usr/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007f1f8589a476 gsignal (/usr/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007f1f858807f3 abort (/usr/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x00007f1f8588071b (/usr/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x00007f1f85891e96 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x0000559a445b6694 (./opt+0x1099694)
#10 0x0000559a45d6f920 llvm::slpvectorizer::BoUpSLP::BlockScheduling::getScheduleData(llvm::Value*) (./opt+0x2852920)
#11 0x0000559a45dbce8e llvm::slpvectorizer::BoUpSLP::getLastInstructionInBundle(llvm::slpvectorizer::BoUpSLP::TreeEntry const*) (./opt+0x289fe8e)
#12 0x0000559a45de2b39 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::MapVector<llvm::Value*, llvm::SmallVector<llvm::Instruction*, 2u>, llvm::DenseMap<llvm::Value*, unsigned int, llvm::DenseMapInfo<llvm::Value*, void>, llvm::detail::DenseMapPair<llvm::Value*, unsigned int>>, std::vector<std::pair<llvm::Value*, llvm::SmallVector<llvm::Instruction*, 2u>>, std::allocator<std::pair<llvm::Value*, llvm::SmallVector<llvm::Instruction*, 2u>>>>> const&, llvm::SmallVectorImpl<std::pair<llvm::Value*, llvm::Value*>>&, llvm::Instruction*) (./opt+0x28c5b39)
#13 0x0000559a45ded84e (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&) SLPVectorizer.cpp:0:0
#14 0x0000559a45defc82 llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*, llvm::SmallVectorImpl<llvm::WeakTrackingVH>&) (./opt+0x28d2c82)
#15 0x0000559a45df3a92 llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*) (.constprop.0) SLPVectorizer.cpp:0:0
#16 0x0000559a45df3cd5 llvm::SLPVectorizerPass::vectorizeCmpInsts(llvm::ArrayRef<llvm::CmpInst*>, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (./opt+0x28d6cd5)
#17 0x0000559a45df47ae llvm::SLPVectorizerPass::vectorizeSimpleInstructions(llvm::SmallSetVector<llvm::Instruction*, 8u>&, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, bool) (./opt+0x28d77ae)
#18 0x0000559a45df7008 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (./opt+0x28da008)
#19 0x0000559a45dfa325 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
#20 0x0000559a45dfac82 llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (./opt+0x28ddc82)
#21 0x0000559a45996f16 llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (./opt+0x2479f16)
#22 0x0000559a43f4917a llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (./opt+0xa2c17a)
#23 0x0000559a4508670b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (./opt+0x1b6970b)
#24 0x0000559a43f31a96 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (./opt+0xa14a96)
#25 0x0000559a450844f1 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (./opt+0x1b674f1)
#26 0x0000559a43ae98f5 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool) (./opt+0x5cc8f5)
#27 0x0000559a43a3c772 main (./opt+0x51f772)
#28 0x00007f1f85881d90 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#29 0x00007f1f85881e40 __libc_start_main (/usr/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#30 0x0000559a43adc875 _start (./opt+0x5bf875)
Aborted (core dumped)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUWV9T4zgS_zTmRUXKlv8_5CGQSQ11M7cUcHOPKdlqJzpkySXJDNlPfyU5IZYTZoHltvamMgGkVv_5df-ktkW0ZhsBMA_SqyBdXpDebKWaX6m-hiVhYRhfVJLu5jeo10AR50_tpQLa14CMlBwZiTRrO86aHTJbQAa0QTXREMSLIFwG4SLIwv3H_UmhYQLQk2QUBUlIxG79CEoAX-N1SCOKKQS4CHCJgvxqWIJQgNMIBfESwbNRpDbAoQVhUBBfJ-gZsSKIv6DfQUkmmGGEs99BBfgasSxB4UgJ_gwl8WcoSf60kkohTirgVlu6h9p9p0G8QO_8F8RXqFNAtXMrwOnBTIDTzI1JhVjhEmE9sViOosl9kWwvEo9ECl8k34skI5HSibC67ZCAvVxh5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