Issue 137185
Summary [Loop Vectorize] Crash: Assertion `CastInst::castIsValid(opc, C, Ty) && "Invalid constantexpr cast!"'
Labels new issue
Assignees
Reporter Nirhar
    Here is the godbolt link to the reproducer: https://godbolt.org/z/354qYx43T
For the record here is the IR:
```
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 @widget() {
bb:
 %sitofp = sitofp i32 0 to double
  br label %bb1

bb1: ; preds = %bb1, %bb
  %phi = phi i32 [ %add, %bb1 ], [ 0, %bb ]
  %phi2 = phi double [ %fsub, %bb1 ], [ 0.000000e+00, %bb ]
 %fsub = fsub double %phi2, %sitofp
  %add = add i32 %phi, 1
  %icmp = icmp ult i32 %phi, 252
  br i1 %icmp, label %bb1, label %bb3

bb3: ; preds = %bb1
  %phi4 = phi double [ %phi2, %bb1 ]
  %phi5 = phi double [ %fsub, %bb1 ]
  ret void
}
```
which fails when running: `opt -passes=loop-vectorize -slp-threshold=-99999 -force-vector-width=4` with the backtrace:
```
opt: /root/llvm-project/llvm/lib/IR/Constants.cpp:2231: static llvm::Constant* llvm::ConstantExpr::getCast(unsigned int, llvm::Constant*, llvm::Type*, bool): Assertion `CastInst::castIsValid(opc, C, Ty) && "Invalid constantexpr 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=loop-vectorize -slp-threshold=-99999 -force-vector-width=4 <source>
1.	Running pass "function(loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>)" on module "<source>"
2.	Running pass "loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>" on function "widget"
 #0 0x00000000054eff68 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x54eff68)
 #1 0x00000000054ed8f4 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #2 0x00007ccdb7442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x00007ccdb74969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #4 0x00007ccdb7442476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #5 0x00007ccdb74287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #6 0x00007ccdb742871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #7 0x00007ccdb7439e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #8 0x0000000005166c4b llvm::ConstantExpr::getCast(unsigned int, llvm::Constant*, llvm::Type*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5166c4b)
 #9 0x0000000000d41160 llvm::IRBuilderBase::CreateTrunc(llvm::Value*, llvm::Type*, llvm::Twine const&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xd41160)
#10 0x00000000045b9885 llvm::VPScalarIVStepsRecipe::execute(llvm::VPTransformState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x45b9885)
#11 0x0000000004576263 llvm::VPBasicBlock::executeRecipes(llvm::VPTransformState*, llvm::BasicBlock*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4576263)
#12 0x000000000457e734 llvm::VPBasicBlock::execute(llvm::VPTransformState*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x457e734)
#13 0x000000000457f740 llvm::VPRegionBlock::execute(llvm::VPTransformState*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x457f740)
#14 0x000000000458abda llvm::VPlan::execute(llvm::VPTransformState*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x458abda)
#15 0x000000000442b57c llvm::LoopVectorizationPlanner::executePlan(llvm::ElementCount, unsigned int, llvm::VPlan&, llvm::InnerLoopVectorizer&, llvm::DominatorTree*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x442b57c)
#16 0x0000000004443b38 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4443b38)
#17 0x0000000004445ce0 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4445ce0)
#18 0x0000000004446333 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4446333)
#19 0x00000000031c103e llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x31c103e)
#20 0x00000000052e90a0 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x52e90a0)
#21 0x0000000000e7bace 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+0xe7bace)
#22 0x00000000052e7973 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x52e7973)
#23 0x0000000000e7a98e 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+0xe7a98e)
#24 0x00000000052e7380 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x52e7380)
#25 0x000000000094707a 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+0x94707a)
#26 0x000000000093a84c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x93a84c)
#27 0x00007ccdb7429d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#28 0x00007ccdb7429e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#29 0x0000000000932485 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x932485)
Program terminated with signal: SIGSEGV
Compiler returned: 139
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to