[llvm] 3fac056 - [VPlan] Reset trip count when replacing ExpandSCEV recipe.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 28 08:32:08 PST 2024
Author: Florian Hahn
Date: 2024-02-28T16:31:49Z
New Revision: 3fac0562f8bdf193f039945eb40c51a5e6c24de1
URL: https://github.com/llvm/llvm-project/commit/3fac0562f8bdf193f039945eb40c51a5e6c24de1
DIFF: https://github.com/llvm/llvm-project/commit/3fac0562f8bdf193f039945eb40c51a5e6c24de1.diff
LOG: [VPlan] Reset trip count when replacing ExpandSCEV recipe.
Otherwise accessing the trip count may accesses freed memory.
Fixes https://lab.llvm.org/buildbot/#/builders/74/builds/26239 and
others.
Added:
Modified:
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
llvm/lib/Transforms/Vectorize/VPlan.h
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 6b16923213c86e..ea77b6018c0d15 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -10093,6 +10093,8 @@ bool LoopVectorizePass::processLoop(Loop *L) {
auto *ExpandedVal = BestEpiPlan.getVPValueOrAddLiveIn(
ExpandedSCEVs.find(ExpandR->getSCEV())->second);
ExpandR->replaceAllUsesWith(ExpandedVal);
+ if (BestEpiPlan.getTripCount() == ExpandR)
+ BestEpiPlan.resetTripCount(ExpandedVal);
ExpandR->eraseFromParent();
}
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index 47cebecdb27083..16c09a83e777dd 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -2931,6 +2931,14 @@ class VPlan {
return TripCount;
}
+ /// Resets the trip count for the VPlan. The caller must make sure all uses of
+ /// the original trip count have been replaced.
+ void resetTripCount(VPValue *NewTripCount) {
+ assert(TripCount && NewTripCount && TripCount->getNumUsers() == 0 &&
+ "TripCount always must be set");
+ TripCount = NewTripCount;
+ }
+
/// The backedge taken count of the original loop.
VPValue *getOrCreateBackedgeTakenCount() {
if (!BackedgeTakenCount)
More information about the llvm-commits
mailing list