[llvm] 275bee3 - [LoopUnroll] Forget block and loop dispositions during unrolling.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 27 00:49:31 PDT 2022
Author: Florian Hahn
Date: 2022-09-27T08:49:04+01:00
New Revision: 275bee32ad305eb5da121e8a60918256f3caf1e7
URL: https://github.com/llvm/llvm-project/commit/275bee32ad305eb5da121e8a60918256f3caf1e7
DIFF: https://github.com/llvm/llvm-project/commit/275bee32ad305eb5da121e8a60918256f3caf1e7.diff
LOG: [LoopUnroll] Forget block and loop dispositions during unrolling.
After unrolling a loop, the block and loop dispositions need to be
cleared. As we don't know which SCEVs in the loop/blocks may be
impacted, completely clear the cache. This should also fix some cases
where deleted loops remained in the LoopDispositions cache.
This fixes a verification failure surfaced by D134531.
I am planning on reviewing/updating the existing uses of
forgetLoopDispositions to check if they should be replaced by
forgetBlockAndLoopDispositions.
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D134612
Added:
Modified:
llvm/include/llvm/Analysis/ScalarEvolution.h
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/lib/Transforms/Utils/LoopUnroll.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/ScalarEvolution.h b/llvm/include/llvm/Analysis/ScalarEvolution.h
index 1de1296a63a9..83f8a9e94bfe 100644
--- a/llvm/include/llvm/Analysis/ScalarEvolution.h
+++ b/llvm/include/llvm/Analysis/ScalarEvolution.h
@@ -939,6 +939,13 @@ class ScalarEvolution {
/// recompute is simpler.
void forgetLoopDispositions();
+ /// Called when the client has changed the disposition of values in
+ /// a loop or block.
+ ///
+ /// We don't have a way to invalidate per-loop/per-block dispositions. Clear
+ /// and recompute is simpler.
+ void forgetBlockAndLoopDispositions();
+
/// Determine the minimum number of zero bits that S is guaranteed to end in
/// (at every loop iteration). It is, at the same time, the minimum number
/// of times S is divisible by 2. For example, given {4,+,8} it returns 2.
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 966bb3594433..f56b9e7950c1 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -8384,6 +8384,11 @@ void ScalarEvolution::forgetValue(Value *V) {
void ScalarEvolution::forgetLoopDispositions() { LoopDispositions.clear(); }
+void ScalarEvolution::forgetBlockAndLoopDispositions() {
+ BlockDispositions.clear();
+ LoopDispositions.clear();
+}
+
/// Get the exact loop backedge taken count considering all loop exits. A
/// computable result can only be returned for loops with all exiting blocks
/// dominating the latch. howFarToZero assumes that the limit of each loop test
diff --git a/llvm/lib/Transforms/Utils/LoopUnroll.cpp b/llvm/lib/Transforms/Utils/LoopUnroll.cpp
index 75961a1d898c..6d6c3db034ca 100644
--- a/llvm/lib/Transforms/Utils/LoopUnroll.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUnroll.cpp
@@ -465,8 +465,10 @@ LoopUnrollResult llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI,
if (SE) {
if (ULO.ForgetAllSCEV)
SE->forgetAllLoops();
- else
+ else {
SE->forgetTopmostLoop(L);
+ SE->forgetBlockAndLoopDispositions();
+ }
}
if (!LatchIsExiting)
More information about the llvm-commits
mailing list