Fix PR1487 and Transforms/IndVar/2007-06-06-DeleteDanglesPtr.ll
authorNick Lewycky <nicholas@mxc.ca>
Wed, 6 Jun 2007 04:12:20 +0000 (04:12 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Wed, 6 Jun 2007 04:12:20 +0000 (04:12 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37459 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/ScalarEvolution.cpp

index 1ff21a75f94601d45cc418b2bbe8c019b5a279f0..b1c3a1772737d35662a6da38b4d3c541db3542ed 100644 (file)
@@ -1196,9 +1196,28 @@ namespace {
 /// client before it removes an instruction from the program, to make sure
 /// that no dangling references are left around.
 void ScalarEvolutionsImpl::deleteInstructionFromRecords(Instruction *I) {
-  Scalars.erase(I);
-  if (PHINode *PN = dyn_cast<PHINode>(I))
-    ConstantEvolutionLoopExitValue.erase(PN);
+  SmallVector<Instruction *, 16> Worklist;
+
+  if (Scalars.erase(I)) {
+    if (PHINode *PN = dyn_cast<PHINode>(I))
+      ConstantEvolutionLoopExitValue.erase(PN);
+    Worklist.push_back(I);
+  }
+
+  while (!Worklist.empty()) {
+    Instruction *II = Worklist.back();
+    Worklist.pop_back();
+
+    for (Instruction::use_iterator UI = II->use_begin(), UE = II->use_end();
+         UI != UE; ++UI) {
+      Instruction *Inst = dyn_cast<Instruction>(*UI);
+      if (Inst && hasSCEV(Inst) && Scalars.erase(Inst)) {
+        if (PHINode *PN = dyn_cast<PHINode>(II))
+          ConstantEvolutionLoopExitValue.erase(PN);
+        Worklist.push_back(Inst);
+      }
+    }
+  }
 }