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

    <tr>
        <th>Summary</th>
        <td>
            Assertion `castIsValid(op, S, Ty) && "Invalid cast!"' failed.
        </td>
    </tr>

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

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

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

<pre>
    The following test fails when run with -passes slp-vectorizer -slp-threshold=-99999

```
; 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 i32 @wombat() #0 gc "statepoint-example" {
bb:
  br label %bb2

bb1: ; No predecessors!
  br label %bb2

bb2:                                              ; preds = %bb1, %bb
  %phi = phi i32 [ 0, %bb ], [ 0, %bb1 ]
  %zext = zext i32 %phi to i64
  %sext = sext i32 %phi to i64
  %or = or i64 %zext, %sext
 %call = call i32 null(float 0.000000e+00) [ "deopt"(i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i64 %or, i32 0, i32 0, i32 0, i64 0, i32 0, i64 0) ]
  ret i32 0
}
```
Stack dump:
```
opt: /root/llvm-project/llvm/lib/IR/Instructions.cpp:3682: static llvm::CastInst* llvm::CastInst::Create(llvm::Instruction::CastOps, llvm::Value*, llvm::Type*, const llvm::Twine&, llvm::Instruction*): Assertion `castIsValid(op, S, Ty) && "Invalid cast!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes slp-vectorizer -slp-threshold=-99999 <source>
 #0 0x0000000004cf0f88 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4cf0f88)
 #1 0x0000000004cee6dc SignalHandler(int) Signals.cpp:0:0
 #2 0x00007feb6de42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x00007feb6de969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #4 0x00007feb6de42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #5 0x00007feb6de287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #6 0x00007feb6de2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #7 0x00007feb6de39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #8 0x0000000004a888bb (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4a888bb)
 #9 0x0000000000b97ed6 llvm::IRBuilderBase::CreateCast(llvm::Instruction::CastOps, llvm::Value*, llvm::Type*, llvm::Twine const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xb97ed6)
#10 0x0000000003e6ce25 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3e6ce25)
#11 0x0000000003e81be3 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>>, llvm::SmallVector<std::pair<llvm::Value*, llvm::SmallVector<llvm::Instruction*, 2u>>, 0u>> const&, llvm::SmallVectorImpl<std::pair<llvm::Value*, llvm::Value*>>&, llvm::Instruction*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3e81be3)
#12 0x0000000003e85105 llvm::slpvectorizer::BoUpSLP::vectorizeTree() (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3e85105)
#13 0x0000000003e91c30 llvm::SLPVectorizerPass::tryToVectorizeList(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3e91c30)
#14 0x0000000003e93f88 llvm::SLPVectorizerPass::tryToVectorize(llvm::Instruction*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3e93f88)
#15 0x0000000003e941e2 llvm::SLPVectorizerPass::tryToVectorize(llvm::ArrayRef<llvm::WeakTrackingVH>, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3e941e2)
#16 0x0000000003e9486c llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*) (.constprop.0) SLPVectorizer.cpp:0:0
#17 0x0000000003e97a5b llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3e97a5b)
#18 0x0000000003e9b207 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
#19 0x0000000003e9bce3 llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3e9bce3)
#20 0x0000000002d59b4e 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+0x2d59b4e)
#21 0x0000000000db0a3d 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+0xdb0a3d)
#22 0x0000000004b025ee llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4b025ee)
#23 0x0000000000d9527e 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+0xd9527e)
#24 0x0000000004b0059c llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4b0059c)
#25 0x00000000008c6f82 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) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8c6f82)
#26 0x00000000008ba7d5 optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8ba7d5)
#27 0x00007feb6de29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#28 0x00007feb6de29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#29 0x00000000008b157e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8b157e)
Program terminated with signal: SIGSEGV
Compiler returned: 139
```


Reproducer: https://godbolt.org/z/rWE8er5cv
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcWltP67gW_jXmxWqVOpcmDzy0lM6gs5lBwGEekZOstD44dmQ7XPavP7KTljq0G7p3RxpNBWnirNv3reVbUqo1WwmAcxTPUbw4o61ZS3V-T80bFXQh29zos1yWb-f3a8CV5Fy-MLHCBrTBFWVc45c1CKxagV-YWeNRQ7UGjTVvRs9QGKnYd1B4ZK_NWoFeS16icDHK7AcFCxTM-mMS9H_dZTjH17JsOVwtMAoXGJHpGJGlgrItoBxzjsi0E9WyVQU8VoyDoDX00mQoTTppQ9UKDC6poZy-ydZs5GFUo3AGo4ZMAxTOQuIO9nLiX9qzJHKHEdueTEiKwtmEpKMqDfoz4ZqSjXoSje5cM7PNo4ZsbqT9f0i6e2QYrVGs4Vtkr2nymESjVjwJ-SJGnIn2dbQS7VarO5ZQMQGYhQSjKHiRdU4NIikiGUYkDPCqsMa0oQYayYQZwSutGw6IEIym885InqOwt4dxrjCnOXCMSJznnrM8tyxhm7Y_JG4UlFCA1lJpRCZf0rdE4KM-1pn1pHtiYhsEuejONj4RiZs1cxL227ERz3GwFcQoXrgLr3Ximt9tfIfXrlLcibPSGTYS2yJ4l9QbSf2ZpFROTirbvnHSR2CVe1FE4oJy7mTdibUpWlvTacUlNTgYB-4DiMyDwCU4ntvkliAbY8uCpFbJwfsbTzoUUn1Bbm9Ltku6AtMLdGUyXewdKO4MLZ5w2dbNtlAHEpYCW5pkqaQ0iCw5f65HjZL_g2Jzab9Yjsjy6tYehDaqLQyTQo-LxloOk9QVqO0urMBOJ5yhcHZBtbHyiMz2tXZXCqgBRNJ3gR0X7xp_Ntqy8S71QHkLiMz81vu3ZtNYSKHN7q0XJgCRxFfYdWb1MotkpjUo24RREhQ2Xv1AOSsRSWVj9e_s4f6tGy8SRBJb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