Index: llvm/include/llvm/Analysis/ScalarEvolution.h =================================================================== --- llvm/include/llvm/Analysis/ScalarEvolution.h +++ llvm/include/llvm/Analysis/ScalarEvolution.h @@ -1884,8 +1884,11 @@ bool splitBinaryAdd(const SCEV *Expr, const SCEV *&L, const SCEV *&R, SCEV::NoWrapFlags &Flags); - /// Drop memoized information computed for S. - void forgetMemoizedResults(const SCEV *S); + /// Drop memoized information for all \p SCEVs. + void forgetMemoizedResults(ArrayRef SCEVs); + + /// Helper for forgetMemoizedResults. + void forgetMemoizedResultsImpl(const SCEV *S); /// Return an existing SCEV for V if there is one, otherwise return nullptr. const SCEV *getExistingSCEV(Value *V); Index: llvm/lib/Analysis/ScalarEvolution.cpp =================================================================== --- llvm/lib/Analysis/ScalarEvolution.cpp +++ llvm/lib/Analysis/ScalarEvolution.cpp @@ -12823,8 +12823,12 @@ return SCEVExprContains(S, [&](const SCEV *Expr) { return Expr == Op; }); } -void -ScalarEvolution::forgetMemoizedResults(const SCEV *S) { +void ScalarEvolution::forgetMemoizedResults(ArrayRef SCEVs) { + for (auto *S : SCEVs) + forgetMemoizedResultsImpl(S); +} + +void ScalarEvolution::forgetMemoizedResultsImpl(const SCEV *S) { ValuesAtScopes.erase(S); LoopDispositions.erase(S); BlockDispositions.erase(S);