[llvm] c384de1 - [VPlan] Prevent dangling references to trip count after expansion. (#201924)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 6 13:14:00 PDT 2026
Author: Florian Hahn
Date: 2026-06-06T22:13:56+02:00
New Revision: c384de1c688bab5d5d1fbf1bb3d31895c98e34cd
URL: https://github.com/llvm/llvm-project/commit/c384de1c688bab5d5d1fbf1bb3d31895c98e34cd
DIFF: https://github.com/llvm/llvm-project/commit/c384de1c688bab5d5d1fbf1bb3d31895c98e34cd.diff
LOG: [VPlan] Prevent dangling references to trip count after expansion. (#201924)
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.
Added:
Modified:
llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
Removed:
################################################################################
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