Make SCEVCallbackVH::allUsesReplacedWith more thorough in removing
authorDan Gohman <gohman@apple.com>
Tue, 14 Jul 2009 14:34:04 +0000 (14:34 +0000)
committerDan Gohman <gohman@apple.com>
Tue, 14 Jul 2009 14:34:04 +0000 (14:34 +0000)
users from the Scalars map.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75634 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/ScalarEvolution.cpp

index 457466f9de5711b4e9fd63f3f7f0234f7c143e48..2b4623cd84f027f2f18e917983a0428462141931 100644 (file)
@@ -4845,6 +4845,7 @@ void ScalarEvolution::SCEVCallbackVH::allUsesReplacedWith(Value *) {
   // so that future queries will recompute the expressions using the new
   // value.
   SmallVector<User *, 16> Worklist;
+  SmallPtrSet<User *, 8> Visited;
   Value *Old = getValPtr();
   bool DeleteOld = false;
   for (Value::use_iterator UI = Old->use_begin(), UE = Old->use_end();
@@ -4858,15 +4859,18 @@ void ScalarEvolution::SCEVCallbackVH::allUsesReplacedWith(Value *) {
       DeleteOld = true;
       continue;
     }
+    if (!Visited.insert(U))
+      continue;
     if (PHINode *PN = dyn_cast<PHINode>(U))
       SE->ConstantEvolutionLoopExitValue.erase(PN);
     if (Instruction *I = dyn_cast<Instruction>(U))
       SE->ValuesAtScopes.erase(I);
-    if (SE->Scalars.erase(U))
-      for (Value::use_iterator UI = U->use_begin(), UE = U->use_end();
-           UI != UE; ++UI)
-        Worklist.push_back(*UI);
+    SE->Scalars.erase(U);
+    for (Value::use_iterator UI = U->use_begin(), UE = U->use_end();
+         UI != UE; ++UI)
+      Worklist.push_back(*UI);
   }
+  // Delete the Old value if it (indirectly) references itself.
   if (DeleteOld) {
     if (PHINode *PN = dyn_cast<PHINode>(Old))
       SE->ConstantEvolutionLoopExitValue.erase(PN);