[llvm] [VPlan] Prevent dangling references to trip count after expansion. (PR #201924)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 6 12:37:55 PDT 2026
https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/201924
>From 0a89276dd45c17e8b96255d256b8db837d54fbb4 Mon Sep 17 00:00:00 2001
From: Florian Hahn <flo at fhahn.com>
Date: Fri, 5 Jun 2026 20:37:04 +0100
Subject: [PATCH] [VPlan] Prevent dangling references to trip count after
expansion.
Set trip count to Poison after expanding SCEVs to VPInstructions.
getTripCount should not be used after that other than printing; setting
to poison avoids accessing dangling references.
---
llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index e0d06366592ae..fac0f9e9b7499 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -5470,8 +5470,11 @@ void VPlanTransforms::expandSCEVsToVPInstructions(VPlan &Plan,
if (!Expanded)
continue;
ExpSCEV->replaceAllUsesWith(Expanded);
+ // TripCount should not be used after expansion to VPInstructions. Reset to
+ // poison to avoid dangling references.
if (Plan.getTripCount() == ExpSCEV)
- Plan.resetTripCount(Expanded);
+ Plan.resetTripCount(
+ Plan.getOrAddLiveIn(PoisonValue::get(ExpSCEV->getScalarType())));
ExpSCEV->eraseFromParent();
}
}
More information about the llvm-commits
mailing list