[llvm-commits] [llvm] r101027 - /llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp

Dan Gohman gohman at apple.com
Mon Apr 12 00:29:15 PDT 2010


Author: djg
Date: Mon Apr 12 02:29:15 2010
New Revision: 101027

URL: http://llvm.org/viewvc/llvm-project?rev=101027&view=rev
Log:
Use RecursivelyDeleteTriviallyDeadInstructions in EliminateIVComparisons,
instead of deleting just the user. This makes it more consistent with
other code in IndVarSimplify, and theoretically can eliminate more users
earlier.

Modified:
    llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp?rev=101027&r1=101026&r2=101027&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp Mon Apr 12 02:29:15 2010
@@ -338,9 +338,11 @@
 }
 
 void IndVarSimplify::EliminateIVComparisons() {
+  SmallVector<WeakVH, 16> DeadInsts;
+
   // Look for ICmp users.
-  for (IVUsers::iterator I = IU->begin(), E = IU->end(); I != E;) {
-    IVStrideUse &UI = *I++;
+  for (IVUsers::iterator I = IU->begin(), E = IU->end(); I != E; ++I) {
+    IVStrideUse &UI = *I;
     ICmpInst *ICmp = dyn_cast<ICmpInst>(UI.getUser());
     if (!ICmp) continue;
 
@@ -367,8 +369,15 @@
       continue;
 
     DEBUG(dbgs() << "INDVARS: Eliminated comparison: " << *ICmp << '\n');
-    ICmp->eraseFromParent();
+    DeadInsts.push_back(ICmp);
   }
+
+  // Now that we're done iterating through lists, clean up any instructions
+  // which are now dead.
+  while (!DeadInsts.empty())
+    if (Instruction *Inst =
+          dyn_cast_or_null<Instruction>(DeadInsts.pop_back_val()))
+      RecursivelyDeleteTriviallyDeadInstructions(Inst);
 }
 
 bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) {





More information about the llvm-commits mailing list