[llvm] [VPlan] Fix assert in finding WideCanIV (NFC) (PR #193269)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 21 09:56:08 PDT 2026
https://github.com/artagnon created https://github.com/llvm/llvm-project/pull/193269
addActiveLaneMask asserts that the return value of a find_if is contextully convertible to true, when finding a WideCanonicalIV recipe: what it should really be checking that the iterator is not the end iterator. Fix this assert by introducing and using a variant of vputils::findUserOf.
>From 356c2b54bd76693dfd1e53f398f867cce6d7d9fd Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <artagnon at tenstorrent.com>
Date: Tue, 21 Apr 2026 17:49:34 +0100
Subject: [PATCH] [VPlan] Fix assert in finding WideCanIV (NFC)
addActiveLaneMask asserts that the return value of a find_if is
contextully convertible to true, when finding a WideCanonicalIV recipe:
what it should really be checking that the iterator is not the end
iterator. Fix this assert by introducing and using a variant of
vputils::findUserOf.
---
llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp | 8 +++-----
llvm/lib/Transforms/Vectorize/VPlanUtils.h | 6 ++++++
2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index f4a87b47cb9cd..c75c0c260c80a 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -3058,13 +3058,11 @@ addVPLaneMaskPhiAndUpdateExitBranch(VPlan &Plan) {
void VPlanTransforms::addActiveLaneMask(VPlan &Plan,
bool UseActiveLaneMaskForControlFlow) {
VPRegionBlock *LoopRegion = Plan.getVectorLoopRegion();
- auto *FoundWidenCanonicalIVUser = find_if(
- LoopRegion->getCanonicalIV()->users(), IsaPred<VPWidenCanonicalIVRecipe>);
- assert(FoundWidenCanonicalIVUser &&
+ auto *WideCanonicalIV = vputils::findUserOf<VPWidenCanonicalIVRecipe>(
+ LoopRegion->getCanonicalIV());
+ assert(WideCanonicalIV &&
"Must have widened canonical IV when tail folding!");
VPSingleDefRecipe *HeaderMask = vputils::findHeaderMask(Plan);
- auto *WideCanonicalIV =
- cast<VPWidenCanonicalIVRecipe>(*FoundWidenCanonicalIVUser);
VPSingleDefRecipe *LaneMask;
if (UseActiveLaneMaskForControlFlow) {
LaneMask = addVPLaneMaskPhiAndUpdateExitBranch(Plan);
diff --git a/llvm/lib/Transforms/Vectorize/VPlanUtils.h b/llvm/lib/Transforms/Vectorize/VPlanUtils.h
index fd15737bfabd6..bd76b91549dc0 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanUtils.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanUtils.h
@@ -130,6 +130,7 @@ inline VPRecipeBase *findRecipe(VPValue *Start, PredT Pred) {
/// return nullptr;
template <typename MatchT>
static VPRecipeBase *findUserOf(VPValue *V, const MatchT &P) {
+ using namespace llvm::VPlanPatternMatch;
auto It = find_if(V->users(), match_fn(P));
return It == V->user_end() ? nullptr : cast<VPRecipeBase>(*It);
}
@@ -141,6 +142,11 @@ template <unsigned Opcode> static VPInstruction *findUserOf(VPValue *V) {
return cast_or_null<VPInstruction>(findUserOf(V, m_VPInstruction<Opcode>()));
}
+template <typename RecipeTy> static RecipeTy *findUserOf(VPValue *V) {
+ using namespace llvm::VPlanPatternMatch;
+ return cast_or_null<RecipeTy>(findUserOf(V, m_Isa<RecipeTy>()));
+}
+
/// Find the canonical IV increment of \p Plan's vector loop region. Returns
/// nullptr if not found.
VPInstruction *findCanonicalIVIncrement(VPlan &Plan);
More information about the llvm-commits
mailing list