<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/106641>106641</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[VPlan] Assertion " VPlan cost model and legacy cost model disagreed"' failed.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
patrick-rivos
</td>
</tr>
</table>
<pre>
Tested using c4906588ce47de33d59bcd95f3e82ce2c3e61c23
Testcase:
```c
_Bool a;
char b;
unsigned char c;
void d(_Bool e[][6]) {
for (signed char f = 0; f < c; f += 3)
for (_Bool g = ({
__typeof__(0) h = e[1][2];
e[f][f] > h ?: h;
});
g; g = b)
for (_Bool i = 0; i < (0 >= 0); i = 1)
a = 0;
}
```
https://godbolt.org/z/Eab8s5e1K
Reduced LLVM IR Testcase:
```llvm ir
; 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 @d() #0 {
entry:
br label %for.body
for.cond.cleanup.loopexit: ; preds = %for.cond.cleanup14
ret void
for.body: ; preds = %for.cond.cleanup14, %entry
%f.039 = phi i8 [ %add, %for.cond.cleanup14 ], [ 0, %entry ]
%0 = or i8 0, 0
%extract.t = trunc i8 %0 to i1
br i1 %extract.t, label %for.body22.lr.ph, label %for.cond.cleanup14
for.body22.lr.ph: ; preds = %for.body
store i8 0, ptr null, align 1
br label %for.cond.cleanup14
for.cond.cleanup14: ; preds = %for.body22.lr.ph, %for.body
%add = add i8 %f.039, 1
%conv = sext i8 %f.039 to i32
%cmp = icmp slt i32 %conv, 1
br i1 %cmp, label %for.body, label %for.cond.cleanup.loopexit
}
attributes #0 = { "target-features"="+64bit,+a,+c,+d,+f,+m,+relax,+v,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl256b,+zvl32b,+zvl64b,-b,-e,-experimental-smctr,-experimental-smmpm,-experimental-smnpm,-experimental-ssctr,-experimental-ssnpm,-experimental-sspm,-experimental-supm,-experimental-zacas,-experimental-zalasr,-experimental-zicfilp,-experimental-zicfiss,-experimental-zvbc32e,-experimental-zvkgs,-h,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smcdeleg,-smcsrind,-smepmp,-smstateen,-ssaia,-ssccfg,-ssccptr,-sscofpmf,-sscounterenw,-sscsrind,-ssqosid,-ssstateen,-ssstrict,-sstc,-sstvala,-sstvecd,-ssu64xl,-svade,-svadu,-svbare,-svinval,-svnapot,-svpbmt,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xsfcease,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xsifivecdiscarddlone,-xsifivecflushdlone,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-xwchc,-za128rs,-za64rs,-zaamo,-zabha,-zalrsc,-zama16b,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmop,-zcmp,-zcmt,-zdinx,-zfa,-zfbfmin,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zic64b,-zicbom,-zicbop,-zicboz,-ziccamoa,-ziccif,-zicclsm,-ziccrse,-zicntr,-zicond,-zihintntl,-zihintpause,-zihpm,-zimop,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-ztso,-zvbb,-zvbc,-zvfbfmin,-zvfbfwma,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl16384b,-zvl2048b,-zvl32768b,-zvl4096b,-zvl512b,-zvl65536b,-zvl8192b" }
```
Command/backtrace:
```
> /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt -passes=loop-vectorize reduced.ll -S
opt: /scratch/tc-testing/tc-compiler-fuzz-trunk/llvm/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7365: llvm::VectorizationFactor llvm::LoopVectorizationPlanner::computeBestVF(): Assertion `(BestFactor.Width == LegacyVF.Width || planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width), BestFactor.Width, CostCtx, OrigLoop, CM)) && " VPlan cost model and legacy cost model disagreed"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt -passes=loop-vectorize reduced.ll -S
1. Running pass "function(loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>)" on module "reduced.ll"
2. Running pass "loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>" on function "d"
#0 0x000064cd5b412560 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x301e560)
#1 0x000064cd5b40f96f llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x301b96f)
#2 0x000064cd5b40fac5 SignalHandler(int) Signals.cpp:0:0
#3 0x000072ec5a042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x000072ec5a0969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#5 0x000072ec5a0969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
#6 0x000072ec5a0969fc pthread_kill ./nptl/pthread_kill.c:89:10
#7 0x000072ec5a042476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
#8 0x000072ec5a0287f3 abort ./stdlib/abort.c:81:7
#9 0x000072ec5a02871b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#10 0x000072ec5a039e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#11 0x000064cd5a3dd109 llvm::LoopVectorizationPlanner::computeBestVF() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1fe9109)
#12 0x000064cd5a3f3ccb llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1fffccb)
#13 0x000064cd5a3f6ce1 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2002ce1)
#14 0x000064cd5a3f7357 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2003357)
#15 0x000064cd592541b6 llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xe601b6)
#16 0x000064cd5b21d41f llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e2941f)
#17 0x000064cd59257346 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xe63346)
#18 0x000064cd5b21c19b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e2819b)
#19 0x000064cd592535e6 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xe5f5e6)
#20 0x000064cd5b21a1dd llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e261dd)
#21 0x000064cd58a7c106 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) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x688106)
#22 0x000064cd58a6de91 optMain (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x679e91)
#23 0x000072ec5a029d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#24 0x000072ec5a029e40 call_init ./csu/../csu/libc-start.c:128:20
#25 0x000072ec5a029e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#26 0x000064cd58a64245 _start (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x670245)
zsh: IOT instruction (core dumped) /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt
```
https://godbolt.org/z/EzdEYKW7c
Found via fuzzer
Related/prior issue: #106417
cc @fhahn
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWl-P26q2_zSeF5TIxv8f5iEz0-hWu9Wu2qpH9ynCgBPuYHABezL59FeA7diZTE939-lIR7uamsVirR_rHzY4RlqzvaD0NkjvgvThBnXmINVti4xi-HGlWC_1TSXJ8-1Xqg0loNNM7AFOyjBLiwLTJCc0jklaVpiUaR3TAmIKcUyzCMM4CB-CcOOvFgAjTYN4YARZ6P-w7-_upOQABfGd7-MDUqCaup1wphLg-Hji95IRQAJYeH3qPQnSu8w2sARBPkgCUEsFAljMgWoQxA8gDOI7R947ZEvCOzsQB7ActSd9P9PeaQawOE-w25nnlsp6twtgEdrJD07IGhV5q6Bt4rsz5vDPitRexDYgiN855W0Qb8DhrBHk1qmXCHtrtjepWth8YTU7-8ucv9ZSO5tnO-hBKDrjoElryF3-cJFE3z0Y02qbYbgN4HYvSSW5WUu1D-D2FMDtO1QVOqXRH_PK-ExJhykBHz58-wjefwavVwrnfQOYGrjxHfgoScfp-4chFbnyUOsKBzD3YgapPTWAIIM4epadGWQhXTVBvKGrNog3WeIuKzYRESyCeBPBYiVi6HlfLA_CBaxRrOV0hFRM4z5LVp14FPJJrDgT3XG1F92k5q-E1kxQ4Eo3SEJbva5SYRyey5UKo56nGABQKcBRRTkIYFpLtbbLcg5qeVgKssacItG1ay5lS4_M2Ap65Z-NYaso0YMH6SVIlIzTK2qcwZdTOjPizU9BQVtuqXdsgLWC6zAunVZ7YIAVIEjvLB8RMmi8hAJucd870XCO6wbO2KHDlcrCOrlwXEcwpUejEDZrXxFGdQK72a2WkYBFs8izaKFhkV4kA8I1V-v28GLwWkCXAZxUXwvkOdkAaCMVnRxqjQKi49zSiLO9ANFrFfNjOy5Gf2TJ3NMrBvrcOSXb-pi6LFuFa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