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

    <tr>
        <th>Summary</th>
        <td>
            [RISCV][SLP] Crash in getShuffleCost
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:RISC-V,
            llvm:SLPVectorizer,
            crash
      </td>
    </tr>

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

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

<pre>
    I found this crash when building the mediabench benchmark from the llvm-test-suite on RV64. Opt crashes when running SLP on this function (`opt -passes=slp-vectorizer reduced.ll`). 

```llvm
; ModuleID = 'reduced.bc'
target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128"
target triple = "riscv64-unknown-linux-gnu"

define void @process_data_context_main() #0 {
  %1 = shl i64 0, 0
  %2 = icmp ult i64 0, 0
  %3 = icmp ult i64 0, 0
  %4 = or i1 %2, %3
  %5 = icmp ult i64 0, 0
  %6 = or i1 %4, %5
  %7 = icmp ult i64 0, 0
  %8 = or i1 %6, %7
  %9 = icmp ult i64 0, 0
  %10 = or i1 %8, %9
  %11 = icmp ult i64 0, 0
  %12 = or i1 %10, %11
  %13 = icmp ult i64 0, 0
  %14 = or i1 %12, %13
  %15 = icmp ult i64 0, 0
  %16 = or i1 %14, %15
  %17 = icmp ult i64 0, 0
 %18 = or i1 %16, %17
  %19 = icmp ult i64 0, 0
  %20 = or i1 %18, %19
  %21 = icmp ult i64 0, 0
  %22 = or i1 %20, %21
  %23 = icmp ult i64 0, 0
  %24 = or i1 %22, %23
  %25 = icmp ult i64 0, 0
  %26 = or i1 %24, %25
  %27 = icmp ult i64 0, 0
  %28 = or i1 %26, %27
 %29 = icmp ult i64 0, 0
  %30 = or i1 %28, %29
  %31 = icmp ult i64 %1, 0
  %32 = or i1 %30, %31
  %33 = icmp ult i64 0, 0
  %34 = or i1 %32, %33
  %35 = icmp ult i64 0, 0
  %36 = or i1 %34, %35
  %37 = icmp ult i64 0, 0
  %38 = or i1 %36, %37
  %39 = icmp ult i64 0, 0
 %40 = or i1 %38, %39
  %41 = icmp ult i64 0, 0
  %42 = or i1 %40, %41
  %43 = icmp ult i64 0, 0
  %44 = or i1 %42, %43
  %45 = icmp ult i64 %1, 0
  %46 = or i1 %44, %45
  %47 = icmp ult i64 0, 0
  %48 = or i1 %46, %47
  %49 = icmp ult i64 0, 0
  %50 = or i1 %48, %49
 %51 = icmp ult i64 0, 0
  %52 = or i1 %50, %51
  %53 = icmp ult i64 0, 0
  %54 = or i1 %52, %53
  %55 = icmp ult i64 0, 0
  %56 = or i1 %54, %55
  %57 = icmp ult i64 0, 0
  %58 = or i1 %56, %57
  %59 = icmp ult i64 0, 0
  %60 = or i1 %58, %59
  %61 = icmp ult i64 0, 0
 %62 = or i1 %60, %61
  %63 = icmp ult i64 0, 0
  %64 = or i1 %62, %63
  br i1 %64, label %66, label %65

65: ; preds = %0
  ret void

66: ; preds = %0
  ret void
}

attributes #0 = { "target-features"="+64bit,+a,+d,+f,+m,+relax,+v,+zicsr,+zifencei,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-c,-e,-experimental-smaia,-experimental-ssaia,-experimental-zacas,-experimental-zfa,-experimental-zfbfmin,-experimental-zicfilp,-experimental-zicond,-experimental-ztso,-experimental-zvbb,-experimental-zvbc,-experimental-zvfbfmin,-experimental-zvfbfwma,-experimental-zvkb,-experimental-zvkg,-experimental-zvkn,-experimental-zvknc,-experimental-zvkned,-experimental-zvkng,-experimental-zvknha,-experimental-zvknhb,-experimental-zvks,-experimental-zvksc,-experimental-zvksed,-experimental-zvksg,-experimental-zvksh,-experimental-zvkt,-h,-save-restore,-svinval,-svnapot,-svpbmt,-unaligned-scalar-mem,-unaligned-vector-mem,-xcvalu,-xcvbi,-xcvbitmanip,-xcvmac,-xcvsimd,-xsfcie,-xsfvcp,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmp,-zcmt,-zdinx,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zicbom,-zicbop,-zicboz,-zicntr,-zihintntl,-zihintpause,-zihpm,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-zmmul,-zvfh,-zvl1024b,-zvl16384b,-zvl2048b,-zvl256b,-zvl32768b,-zvl4096b,-zvl512b,-zvl65536b,-zvl8192b" }
```

```
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: opt -passes=slp-vectorizer reduced.ll -o - -S
 #0 0x0000559647d76ac8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/root/llvm-project/build.release/bin/opt+0x23e8ac8)
 #1 0x0000559647d7489e llvm::sys::RunSignalHandlers() (/root/llvm-project/build.release/bin/opt+0x23e689e)
 #2 0x0000559647d77288 SignalHandler(int) Signals.cpp:0:0
 #3 0x00007f3c9dc5a510 (/lib/x86_64-linux-gnu/libc.so.6+0x3c510)
 #4 0x0000559646da4aec llvm::RISCVTTIImpl::getShuffleCost(llvm::TargetTransformInfo::ShuffleKind, llvm::VectorType*, llvm::ArrayRef<int>, llvm::TargetTransformInfo::TargetCostKind, int, llvm::VectorType*, llvm::ArrayRef<llvm::Value const*>) RISCVTargetTransformInfo.cpp:0:0
 #5 0x00005596483a6b0c llvm::slpvectorizer::BoUpSLP::getGatherCost(llvm::ArrayRef<llvm::Value*>, bool) const (/root/llvm-project/build.release/bin/opt+0x2a18b0c)
 #6 0x00005596483d1bc8 llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator::getBuildVectorCost(llvm::ArrayRef<llvm::Value*>, llvm::Value*) SLPVectorizer.cpp:0:0
 #7 0x000055964839f6df llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator::gather(llvm::ArrayRef<llvm::Value*>, llvm::Value*) SLPVectorizer.cpp:0:0
 #8 0x000055964839a42e llvm::slpvectorizer::BoUpSLP::getEntryCost(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>, llvm::SmallPtrSetImpl<llvm::Value*>&) (/root/llvm-project/build.release/bin/opt+0x2a0c42e)
 #9 0x00005596483a2b48 llvm::slpvectorizer::BoUpSLP::getTreeCost(llvm::ArrayRef<llvm::Value*>) (/root/llvm-project/build.release/bin/opt+0x2a14b48)
#10 0x00005596483df4a4 (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&) SLPVectorizer.cpp:0:0
#11 0x00005596483c52a6 llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*, llvm::SmallVectorImpl<llvm::WeakTrackingVH>&) (/root/llvm-project/build.release/bin/opt+0x2a372a6)
#12 0x00005596483c541b llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*) (/root/llvm-project/build.release/bin/opt+0x2a3741b)
#13 0x00005596483bd66d llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/root/llvm-project/build.release/bin/opt+0x2a2f66d)
#14 0x00005596483bb781 llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (/root/llvm-project/build.release/bin/opt+0x2a2d781)
#15 0x00005596483bb0b0 llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/root/llvm-project/build.release/bin/opt+0x2a2d0b0)
#16 0x0000559647f3d83d llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) PassBuilder.cpp:0:0
#17 0x0000559647938892 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/root/llvm-project/build.release/bin/opt+0x1faa892)
#18 0x0000559647f1c0ad 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>&) PassBuilder.cpp:0:0
#19 0x000055964793bc62 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/root/llvm-project/build.release/bin/opt+0x1fadc62)
#20 0x0000559647f1c28d llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) PassBuilder.cpp:0:0
#21 0x0000559647937bc2 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/root/llvm-project/build.release/bin/opt+0x1fa9bc2)
#22 0x0000559646caf9cf 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, bool) (/root/llvm-project/build.release/bin/opt+0x13219cf)
#23 0x0000559646cbda89 main (/root/llvm-project/build.release/bin/opt+0x132fa89)
#24 0x00007f3c9dc456ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#25 0x00007f3c9dc45785 call_init ./csu/../csu/libc-start.c:128:20
#26 0x00007f3c9dc45785 __libc_start_main ./csu/../csu/libc-start.c:347:5
#27 0x0000559646ca97a1 _start (/root/llvm-project/build.release/bin/opt+0x131b7a1)
```

I've bisected it to 9a207578ac4f9f4fedbee6dc47bc6e2226104fc1
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcmltzo76SwD8NeVHZBRLXhzw4yWQntfPff2qSnX1MCSFsrUGiJOFJ8um3JIENmJyQSc7uqZ3KoEaXVveP1gVhrBTbckovvejKi24ucKt3Ql5W7Z5WWXKRi-Ll8g6UouUF0DumAJFY7cDvHeUgb1lVML4FekdBTQuGc8rJDthrjeUelFLUtrSqDvVKU6VXqmWaAsHBz19xuAZ_N9qppMoplS3nRufDj3tTy_ZZtpxoJjjwYOrFvmg0WDVYKao8dKOqZnWgRAvJXqkEkhYtocW6qrzY92C2Bp5_4_mb7hr77s8Y1GWhK_CXKNqK3t0AD90ADya9kpx4MHHVNJZbqkGBNa7wi2h1VxfSVe2hDV01HtrEob2s2FEIYOqhTQDTFUfQ5T2YPAhHarVkTUV7lZIpcojDVcv3XPzmq4rx9nm15e2xmbsWtGScgoNgBfBCv5GCUKWejI1PRHBNn_VTjRk32GAGPIh84CVXrjEAHowC26XaVYDFIfA9eA38QTG0xYzUDWgrPV8HLagT2jpCAhZYtabcNB1UiRaoicdqwk5NNKiSLFCTjtXEnZpkUCVboCbwx3rSTk82rBMsUQTHigK_0xQEw1pLQAcT0kGPOhiyDpbADia0gx53MOQdvAfc1JkAD3riwRB5sIQ5nDAPeujBkDpcQh1OqMOeOhx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