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

    <tr>
        <th>Summary</th>
        <td>
            [LoopVectorize] Found non-header PHI recipe in header - Assertion `verifyVPlanIsValid(*Plan) && "VPlan is invalid"' 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>
    Reduced LLVM IR:
```llvm ir
target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128"
target triple = "riscv64-unknown-linux-gnu"

define i32 @main() #0 {
for.cond6.preheader:
  br label %for.body10.1.i

for.body10.1.i:                                   ; preds = %cond.end.1.i, %for.cond6.preheader
  %am.028.1.i = phi i32 [ 0, %for.cond6.preheader ], [ %inc.1.i, %cond.end.1.i ]
  br i1 false, label %cond.end.1.i, label %cond.true.1.i

cond.true.1.i: ; preds = %for.body10.1.i
  br label %cond.end.1.i

cond.end.1.i:                                     ; preds = %cond.true.1.i, %for.body10.1.i
  %cond.1.i = phi i32 [ 1, %cond.true.1.i ], [ 0, %for.body10.1.i ]
  %inc.1.i = add i32 %am.028.1.i, 1
  %exitcond21 = icmp ne i32 %inc.1.i, 0
  br i1 %exitcond21, label %for.body10.1.i, label %for.cond.cleanup9.1.i.loopexit

for.cond.cleanup9.1.i.loopexit: ; preds = %cond.end.1.i
  %cond.1.i.lcssa = phi i32 [ %cond.1.i, %cond.end.1.i ]
  ret i32 0
}

attributes #0 = { "target-features"="+64bit,+a,+c,+d,+f,+m,+relax,+v,+zicsr,+zifencei,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl256b,+zvl32b,+zvl64b,-e,-experimental-smmpm,-experimental-smnpm,-experimental-ssnpm,-experimental-sspm,-experimental-ssqosid,-experimental-supm,-experimental-zaamo,-experimental-zabha,-experimental-zalasr,-experimental-zalrsc,-experimental-zfbfmin,-experimental-zicfilp,-experimental-zicfiss,-experimental-ztso,-experimental-zvfbfmin,-experimental-zvfbfwma,-h,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smepmp,-ssaia,-ssccptr,-sscofpmf,-sscounterenw,-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,-za128rs,-za64rs,-zacas,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmop,-zcmp,-zcmt,-zdinx,-zfa,-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,-zmmul,-zvbb,-zvbc,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl16384b,-zvl2048b,-zvl32768b,-zvl4096b,-zvl512b,-zvl65536b,-zvl8192b" }
```
Godbolt: https://godbolt.org/z/vrd5EvhW7

Backtrace:
```
Found non-header PHI recipe in header VPBB: BLEND ir<%cond.1.i> = ir<1> ir<0>/ir<false>
opt: /scratch/tc-testing/tc-apr-15/llvm/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:8555: void llvm::LoopVectorizationPlanner::buildVPlansWithVPRecipes(llvm::ElementCount, llvm::ElementCount): Assertion `verifyVPlanIsValid(*Plan) && "VPlan is invalid"' 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-apr-15/build-rv64gcv/build-llvm-linux/bin/opt --passes=loop-vectorize reduced.ll
 #0 0x00006290953d31b0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0x2da91b0)
 #1 0x00006290953d05bf llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0x2da65bf)
 #2 0x00006290953d0715 SignalHandler(int) Signals.cpp:0:0
 #3 0x00007953b0842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007953b08969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #5 0x00007953b08969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #6 0x00007953b08969fc pthread_kill ./nptl/pthread_kill.c:89:10
 #7 0x00007953b0842476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #8 0x00007953b08287f3 abort ./stdlib/abort.c:81:7
 #9 0x00007953b082871b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#10 0x00007953b0839e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#11 0x000062909443e70a (/scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0x1e1470a)
#12 0x000062909443ebd1 llvm::LoopVectorizationPlanner::plan(llvm::ElementCount, unsigned int) (/scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0x1e14bd1)
#13 0x0000629094440f35 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0x1e16f35)
#14 0x0000629094443fee llvm::LoopVectorizePass::runImpl(llvm::Function&, llvm::ScalarEvolution&, llvm::LoopInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::BlockFrequencyInfo*, llvm::TargetLibraryInfo*, llvm::DemandedBits&, llvm::AssumptionCache&, llvm::LoopAccessInfoManager&, llvm::OptimizationRemarkEmitter&, llvm::ProfileSummaryInfo*) (/scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0x1e19fee)
#15 0x000062909444513d llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0x1e1b13d)
#16 0x0000629093340396 llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0xd16396)
#17 0x00006290951f8451 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0x2bce451)
#18 0x0000629093337c26 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-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0xd0dc26)
#19 0x00006290951f712b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0x2bcd12b)
#20 0x000062909333fee6 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0xd15ee6)
#21 0x00006290951f4f61 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0x2bcaf61)
#22 0x0000629092bb9205 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-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0x58f205)
#23 0x0000629092bab836 optMain (/scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0x581836)
#24 0x00007953b0829d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#25 0x00007953b0829e40 call_init ./csu/../csu/libc-start.c:128:20
#26 0x00007953b0829e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#27 0x0000629092ba14b5 _start (/scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0x5774b5)
zsh: IOT instruction (core dumped) /scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/opt
```

Found via fuzzer.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWl9z46iW_zTKC2WXBJIsP-TB-eO9Xdu9k-ru6vuYQoBsNgjUg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