diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 69d2b9f2c1a2..2c2a4545b66d 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -9069,11 +9069,17 @@ static void preparePlanForMainVectorLoop(VPlan &MainPlan, VPlan &EpiPlan) { AddFreezeForFindLastIVReductions(MainPlan, true); AddFreezeForFindLastIVReductions(EpiPlan, false); - VPBasicBlock *MainScalarPH = MainPlan.getScalarPreheader(); - VPValue *VectorTC = &MainPlan.getVectorTripCount(); + VPValue *VectorTC = nullptr; + auto *Term = + MainPlan.getVectorLoopRegion()->getExitingBasicBlock()->getTerminator(); + [[maybe_unused]] bool MatchedTC = + match(Term, m_BranchOnCount(m_VPValue(), m_VPValue(VectorTC))); + assert(MatchedTC && "must match vector trip count"); + // If there is a suitable resume value for the canonical induction in the // scalar (which will become vector) epilogue loop, use it and move it to the // beginning of the scalar preheader. Otherwise create it below. + VPBasicBlock *MainScalarPH = MainPlan.getScalarPreheader(); auto ResumePhiIter = find_if(MainScalarPH->phis(), [VectorTC](VPRecipeBase &R) { return match(&R, m_VPInstruction(m_Specific(VectorTC),