From cb87d346b4e10b8a2cb1b1e284cd2ea3233c5f0f Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Wed, 18 Feb 2026 21:08:33 +0000 Subject: [PATCH] [VPlan] Retrieve vector trip count from BranchOnCount (NFC). In preparePlanForMainVectorLoop, the vector trip count may already be materialized, e.g. when narrowing interleave groups. VPSymbolicValues should not be accessed after materializing. Instead retrieve the trip count directly from the branch-on-count. This is NFC at the moment, but is needed to tighten VPSymbolicValue access verification. --- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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),