Index: llvm/lib/Analysis/ScalarEvolution.cpp =================================================================== --- llvm/lib/Analysis/ScalarEvolution.cpp +++ llvm/lib/Analysis/ScalarEvolution.cpp @@ -4424,6 +4424,7 @@ void ScalarEvolution::forgetSymbolicName(Instruction *PN, const SCEV *SymName) { SmallVector Worklist; SmallPtrSet Visited; + SmallVector ToForget; Visited.insert(PN); Worklist.push_back(PN); while (!Worklist.empty()) { @@ -4449,12 +4450,13 @@ !isa(Old) || (I != PN && Old == SymName)) { eraseValueFromMap(It->first); - forgetMemoizedResults(Old); + ToForget.push_back(Old); } } PushDefUseChildren(I, Worklist, Visited); } + forgetMemoizedResults(ToForget); } namespace { @@ -7440,6 +7442,7 @@ if (Result.hasAnyInfo()) { SmallVector Worklist; SmallPtrSet Discovered; + SmallVector ToForget; PushLoopPHIs(L, Worklist, Discovered); while (!Worklist.empty()) { Instruction *I = Worklist.pop_back_val(); @@ -7457,7 +7460,7 @@ // own when it gets to that point. if (!isa(I) || !isa(Old)) { eraseValueFromMap(It->first); - forgetMemoizedResults(Old); + ToForget.push_back(Old); } if (PHINode *PN = dyn_cast(I)) ConstantEvolutionLoopExitValue.erase(PN); @@ -7489,6 +7492,7 @@ Worklist.push_back(I); } } + forgetMemoizedResults(ToForget); } // Re-lookup the insert position, since the call to @@ -7525,6 +7529,7 @@ SmallVector LoopWorklist(1, L); SmallVector Worklist; SmallPtrSet Visited; + SmallVector ToForget; // Iterate over all the loops and sub-loops to drop SCEV information. while (!LoopWorklist.empty()) { @@ -7546,8 +7551,8 @@ auto LoopUsersItr = LoopUsers.find(CurrL); if (LoopUsersItr != LoopUsers.end()) { - for (auto *S : LoopUsersItr->second) - forgetMemoizedResults(S); + ToForget.insert(ToForget.end(), LoopUsersItr->second.begin(), + LoopUsersItr->second.end()); LoopUsers.erase(LoopUsersItr); } @@ -7561,7 +7566,7 @@ ValueExprMap.find_as(static_cast(I)); if (It != ValueExprMap.end()) { eraseValueFromMap(It->first); - forgetMemoizedResults(It->second); + ToForget.push_back(It->second); if (PHINode *PN = dyn_cast(I)) ConstantEvolutionLoopExitValue.erase(PN); } @@ -7574,6 +7579,7 @@ // ValuesAtScopes map. LoopWorklist.append(CurrL->begin(), CurrL->end()); } + forgetMemoizedResults(ToForget); } void ScalarEvolution::forgetTopmostLoop(const Loop *L) { @@ -7589,6 +7595,7 @@ // Drop information about expressions based on loop-header PHIs. SmallVector Worklist; SmallPtrSet Visited; + SmallVector ToForget; Worklist.push_back(I); Visited.insert(I); @@ -7598,13 +7605,14 @@ ValueExprMap.find_as(static_cast(I)); if (It != ValueExprMap.end()) { eraseValueFromMap(It->first); - forgetMemoizedResults(It->second); + ToForget.push_back(It->second); if (PHINode *PN = dyn_cast(I)) ConstantEvolutionLoopExitValue.erase(PN); } PushDefUseChildren(I, Worklist, Visited); } + forgetMemoizedResults(ToForget); } void ScalarEvolution::forgetLoopDispositions(const Loop *L) {