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

    <tr>
        <th>Summary</th>
        <td>
            [VPlan] Assertion `VF.Width == Width && "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 d082f1f37d8cb7a0c6875537ba873a631b154d53

C Testcase:
```c
int a;
extern int b[];
signed char c;
int d[1];
void e() {
  for (short f = 2; f < c; f += 3) {
    a = ({ d[f - 1]; }) ? d[f] : 0;
 b[f] = 0;
 }
}
```
Command:
```
/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/clang -march=rv64gcv_zvl256b -O3 red.c -o /dev/null
```

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 @e(i8 %0, i64 %indvars.iv) #0 {
entry:
  %1 = zext i8 %0 to i64
  br label %for.body

for.cond.for.cond.cleanup_crit_edge:              ; preds = %cond.end
  ret void

for.body: ; preds = %cond.end, %entry
  %indvars.iv1 = phi i64 [ 0, %entry ], [ %indvars.iv.next, %cond.end ]
  %sub = add i64 0, 0
  %arrayidx = getelementptr [1 x i32], ptr null, i64 0, i64 %sub
  %2 = load i32, ptr %arrayidx, align 4
  %tobool.not = icmp eq i32 %2, 0
  br i1 %tobool.not, label %cond.end, label %cond.true

cond.true: ; preds = %for.body
  %arrayidx5 = getelementptr [1 x i32], ptr null, i64 0, i64 %indvars.iv
  %3 = load i32, ptr %arrayidx5, align 4
  br label %cond.end

cond.end: ; preds = %cond.true, %for.body
  %arrayidx7 = getelementptr [0 x i32], ptr null, i64 0, i64 %indvars.iv1
  store i32 0, ptr %arrayidx7, align 4
  %indvars.iv.next = add i64 %indvars.iv1, 3
 %cmp = icmp ult i64 %indvars.iv1, %1
  br i1 %cmp, label %for.body, label %for.cond.for.cond.cleanup_crit_edge
}

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-smmpm,-experimental-smnpm,-experimental-ssnpm,-experimental-sspm,-experimental-ssqosid,-experimental-supm,-experimental-zacas,-experimental-zalasr,-experimental-zicfilp,-experimental-zicfiss,-h,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smcdeleg,-smcsrind,-smepmp,-smstateen,-ssaia,-ssccfg,-ssccptr,-sscofpmf,-sscounterenw,-sscsrind,-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:10037: bool llvm::LoopVectorizePass::processLoop(llvm::Loop*): Assertion `VF.Width == BestVF && "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 "e"
 #0 0x000063e889a673c0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2ff63c0)
 #1 0x000063e889a647df llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2ff37df)
 #2 0x000063e889a64935 SignalHandler(int) Signals.cpp:0:0
 #3 0x00007a5322242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007a53222969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #5 0x00007a53222969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #6 0x00007a53222969fc pthread_kill ./nptl/pthread_kill.c:89:10
 #7 0x00007a5322242476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #8 0x00007a53222287f3 abort ./stdlib/abort.c:81:7
 #9 0x00007a532222871b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#10 0x00007a5322239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#11 0x000063e888a5ba9a llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1feaa9a)
#12 0x000063e888a5df51 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1fecf51)
#13 0x000063e888a5e5c7 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1fed5c7)
#14 0x000063e8878c6096 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+0xe55096)
#15 0x000063e88987deef 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+0x2e0ceef)
#16 0x000063e8878c91d6 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+0xe581d6)
#17 0x000063e88987cc6b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e0bc6b)
#18 0x000063e8878c54c6 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+0xe544c6)
#19 0x000063e88987accd 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+0x2e09ccd)
#20 0x000063e8870f3eb6 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+0x682eb6)
#21 0x000063e8870e5c41 optMain (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x674c41)
#22 0x00007a5322229d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#23 0x00007a5322229e40 call_init ./csu/../csu/libc-start.c:128:20
#24 0x00007a5322229e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#25 0x000063e8870dbff5 _start (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x66aff5)
zsh: IOT instruction (core dumped) /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt
```

Found via fuzzer.

cc @fhahn 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWluP27az_zTaF8KGRF39sA_e3RqnOA0aNEHOo0GRlM2zFKmQlOL1p_-DF8mS15s2-TcBigYbcTic-XFuokjJSGt2EJTeR_lDlD_dod4cpbrvkFEMP68UG6S-qyV5uf9ItaEE9JqJAyBxBZukSUtS4bpEMS6qMs_TskZVmaIiTeokz0ieRvFTFG_99RFYCIw0jdLAiorY_2HfZ8IAFKUPvkdPhioBLLP25k1DzmgC8BEpgCeulSRR_pDMRQfJCKARrCK4AVEZuAA0UoEIVvoolQENiNInAKP0wZGPDtSS8MEOpFe6ACCnYFHLBzdnA1YgzAui8skppDs_FOVPIEq3IJ6Mcg4F_tOcb1V9aCZijFGIomxbJMjrEIYu3GmskMHHCO4MXhmqDRMH38Gy7RinatX05_PKqF48R3BX94yT1QEPE8350K44E_3JspiI4A5zJA5g1SKFj1H6pIYiO-Bhfx44zIsarH5PgaJkjcFKggjuCLVoouf8tpXu-nY5WAMAU4GbPoB3kvSc_voUol4qSnpMybrGESy9mEHqQA0gyCCOXmRvgiykqzZKt3TVRem2yNxlxSYigVWUbhNYrUQKPe-D5UG4gDWKdZyOkIppPBTZqhfPQn4RPlarg-gnNX8ltGGCAleCURbbKmQViGAeR_ARsCKzNBNkQEqv2eCKBqbxpdSoMOplig-w4okz4kxPBgQsYKTFGmVqBTiqKbdjjVRre_fOjbI8LAVZTwTmFIm-22PFzJ6Sg80IWPyzOegUJTpEIHd6VJBxUkWNc_N6Ijd5uv0KAHy0Xe_oxctLULy_3ZH5eOUPIJ7rAHvP2X7-sNRbC3oyQXKczAlfJtF97cARIQ7cAcczAaQUemHk5KQO1FBOWypMZ5SdLwEnwFIYDLBMV_Ahs_MU676eoUIHxyUiTj3ozqazLMTZQYBspmZkL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