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 @@ -12757,42 +12757,43 @@ 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); - UnsignedRanges.erase(S); - SignedRanges.erase(S); - ExprValueMap.erase(S); - HasRecMap.erase(S); - MinTrailingZerosCache.erase(S); - + SmallPtrSet ToForget(SCEVs.begin(), SCEVs.end()); for (auto I = PredicatedSCEVRewrites.begin(); I != PredicatedSCEVRewrites.end();) { std::pair Entry = I->first; - if (Entry.first == S) + if (ToForget.count(Entry.first)) PredicatedSCEVRewrites.erase(I++); else ++I; } - auto RemoveSCEVFromBackedgeMap = - [S](DenseMap &Map) { + auto RemoveSCEVFromBackedgeMap = [this, &ToForget]( + DenseMap &Map) { for (auto I = Map.begin(), E = Map.end(); I != E;) { BackedgeTakenInfo &BEInfo = I->second; - if (BEInfo.hasOperand(S)) + if (any_of(ToForget, + [&BEInfo](const SCEV *S) { return BEInfo.hasOperand(S); })) Map.erase(I++); else ++I; } - }; + }; RemoveSCEVFromBackedgeMap(BackedgeTakenCounts); RemoveSCEVFromBackedgeMap(PredicatedBackedgeTakenCounts); } +void ScalarEvolution::forgetMemoizedResultsImpl(const SCEV *S) { + ValuesAtScopes.erase(S); + LoopDispositions.erase(S); + BlockDispositions.erase(S); + UnsignedRanges.erase(S); + SignedRanges.erase(S); + ExprValueMap.erase(S); + HasRecMap.erase(S); + MinTrailingZerosCache.erase(S); +} + void ScalarEvolution::getUsedLoops(const SCEV *S, SmallPtrSetImpl &LoopsUsed) {