diff --git a/llvm/include/llvm/Analysis/ScalarEvolution.h b/llvm/include/llvm/Analysis/ScalarEvolution.h --- a/llvm/include/llvm/Analysis/ScalarEvolution.h +++ b/llvm/include/llvm/Analysis/ScalarEvolution.h @@ -939,6 +939,13 @@ /// 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 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -8384,6 +8384,11 @@ 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 --- a/llvm/lib/Transforms/Utils/LoopUnroll.cpp +++ b/llvm/lib/Transforms/Utils/LoopUnroll.cpp @@ -465,8 +465,10 @@ if (SE) { if (ULO.ForgetAllSCEV) SE->forgetAllLoops(); - else + else { SE->forgetTopmostLoop(L); + SE->forgetBlockAndLoopDispositions(); + } } if (!LatchIsExiting)