Bug type: crash
Component: LoopVectorize
Issue title: Assertion `verifyVPlanIsValid(*Plan) && "VPlan is invalid"' failed
Labels: vectorizers
crash
Reported by: TatyanaDoubts

The following test fails when run opt with -passes loop-vectorize
```
; 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 void @wombat() gc "statepoint-example" {
bb:
  br label %bb1

bb1:                                              ; preds = %bb2, %bb
  %phi = phi i32 [ %add, %bb2 ], [ 0, %bb ]
  br i1 false, label %bb2, label %bb4

bb2:                                              ; preds = %bb4, %bb1
  %phi3 = phi i64 [ 1, %bb4 ], [ 0, %bb1 ]
  %add = add i32 %phi, 1
  %icmp = icmp sgt i32 %phi, 0
  br i1 %icmp, label %bb5, label %bb1

bb4:                                              ; preds = %bb1
  br label %bb2

bb5:                                              ; preds = %bb2
  %phi6 = phi i64 [ %phi3, %bb2 ]
  ret void
}
```
Reproducer https://godbolt.org/z/9YW1o7qo6
Stack dump:
```
Found non-header PHI recipe in header VPBB: BLEND ir<%phi3> = ir<1> ir<0>/ir<false>
opt: /root/llvm-project/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: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes loop-vectorize <source>
 #0 0x0000000004d05ee8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d05ee8)
 #1 0x0000000004d0363c SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f7623242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x00007f76232969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #4 0x00007f7623242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #5 0x00007f76232287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #6 0x00007f762322871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #7 0x00007f7623239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #8 0x0000000003de70b8 llvm::LoopVectorizationPlanner::buildVPlansWithVPRecipes(llvm::ElementCount, llvm::ElementCount) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3de70b8)
 #9 0x0000000003dee731 llvm::LoopVectorizationPlanner::plan(llvm::ElementCount, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3dee731)
#10 0x0000000003df18fe llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3df18fe)
#11 0x0000000003df4c6d 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*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3df4c6d)
#12 0x0000000003df5e7b llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3df5e7b)
#13 0x0000000002d67f0e 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+0x2d67f0e)
#14 0x0000000000db3554 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+0xdb3554)
#15 0x0000000004b1663e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4b1663e)
#16 0x0000000000d97cce 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+0xd97cce)
#17 0x0000000004b1454c llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4b1454c)
#18 0x00000000008c74f2 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+0x8c74f2)
#19 0x00000000008bad45 optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8bad45)
#20 0x00007f7623229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#21 0x00007f7623229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#22 0x00000000008b1aee _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8b1aee)
Program terminated with signal: SIGSEGV
Compiler returned: 139
```


Fix patch:
commit 34777c238b117b52dd41a9d12e8b54fb83677a12
Author: Florian Hahn <flo@fhahn.com>
Date:   Tue Apr 16 21:24:24 2024 +0100

    [VPlan] Don't mark VPBlendRecipe as phi-like.
    
    VPBlendRecipes don't get lowered to phis and usually do not appear at
    the beginning of blocks, due to their masks appearing before them.
    
    This effectively relaxes an over-eager verifier message.
    
    Fixes https://github.com/llvm/llvm-project/issues/88297.
    Fixes https://github.com/llvm/llvm-project/issues/88804.

diff --git a/llvm/lib/Transforms/Vectorize/VPlanValue.h b/llvm/lib/Transforms/Vectorize/VPlanValue.h
index da3a768552fc..3f8d4f4fe7d6 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanValue.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanValue.h
@@ -361,8 +361,8 @@ public:
     VPWidenMemoryInstructionSC,
     VPWidenSC,
     VPWidenSelectSC,
-    // START: Phi-like recipes. Need to be kept together.
     VPBlendSC,
+    // START: Phi-like recipes. Need to be kept together.
     VPWidenPHISC,
     VPPredInstPHISC,
     // START: SubclassID for recipes that inherit VPHeaderPHIRecipe.
@@ -376,7 +376,7 @@ public:
     VPReductionPHISC,
     // END: SubclassID for recipes that inherit VPHeaderPHIRecipe
     // END: Phi-like recipes
-    VPFirstPHISC = VPBlendSC,
+    VPFirstPHISC = VPWidenPHISC,
     VPFirstHeaderPHISC = VPCanonicalIVPHISC,
     VPLastHeaderPHISC = VPReductionPHISC,
     VPLastPHISC = VPReductionPHISC,


Regression tests:
file: llvm/test/Transforms/LoopVectorize/blend-in-header.ll
commands: opt -p loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -S %s
tests: test_name: <module>
test_body: 
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"

; Test with blend recipe in header VPBB, from
; https://github.com/llvm/llvm-project/issues/88297.
define i64 @pr88297() {
;
entry:
  br label %loop.header

loop.header:
  %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ]
  br i1 false, label %loop.latch, label %then

then:
  br label %loop.latch

loop.latch:
  %r = phi i64 [ 1, %then ], [ 0, %loop.header ]
  %iv.next = add i32 %iv, 1
  %icmp = icmp sgt i32 %iv, 1000
  br i1 %icmp, label %exit, label %loop.header

exit:
  %r.lcssa = phi i64 [ %r, %loop.latch ]
  ret i64 %r.lcssa
}

define i64 @pr88297_incoming_ops_reordered() {
;
entry:
  br label %loop.header

loop.header:
  %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ]
  br i1 false, label %loop.latch, label %then

then:
  br label %loop.latch

loop.latch:
  %r = phi i64 [ 0, %loop.header ], [ 1, %then ]
  %iv.next = add i32 %iv, 1
  %icmp = icmp sgt i32 %iv, 1000
  br i1 %icmp, label %exit, label %loop.header

exit:
  %r.lcssa = phi i64 [ %r, %loop.latch ]
  ret i64 %r.lcssa
}

define i64 @invar_cond(i1 %c) {
;
entry:
  br label %loop.header

loop.header:
  %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ]
  br i1 %c, label %loop.latch, label %then

then:
  br label %loop.latch

loop.latch:
  %r = phi i64 [ 1, %then ], [ 0, %loop.header ]
  %iv.next = add i32 %iv, 1
  %icmp = icmp sgt i32 %iv, 1000
  br i1 %icmp, label %exit, label %loop.header

exit:
  %r.lcssa = phi i64 [ %r, %loop.latch ]
  ret i64 %r.lcssa
}

define i64 @invar_cond_incoming_ops_reordered(i1 %c) {
;
entry:
  br label %loop.header

loop.header:
  %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ]
  br i1 %c, label %loop.latch, label %then

then:
  br label %loop.latch

loop.latch:
  %r = phi i64 [ 0, %loop.header ], [ 1, %then ]
  %iv.next = add i32 %iv, 1
  %icmp = icmp sgt i32 %iv, 1000
  br i1 %icmp, label %exit, label %loop.header

exit:
  %r.lcssa = phi i64 [ %r, %loop.latch ]
  ret i64 %r.lcssa
}
;.
;.