[llvm-commits] [llvm] r60329 - /llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp

Chris Lattner sabre at nondot.org
Sun Nov 30 22:11:33 PST 2008


Author: lattner
Date: Mon Dec  1 00:11:32 2008
New Revision: 60329

URL: http://llvm.org/viewvc/llvm-project?rev=60329&view=rev
Log:
simplify DeleteTriviallyDeadInstructions again, unlike my previous
buggy rewrite, this notifies ScalarEvolution of a pending instruction
about to be removed and then erases it, instead of erasing it then 
notifying.

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

Modified: llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp?rev=60329&r1=60328&r2=60329&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp Mon Dec  1 00:11:32 2008
@@ -244,28 +244,21 @@
     Instruction *I = Insts.back();
     Insts.pop_back();
 
-    if (PHINode *PN = dyn_cast<PHINode>(I)) {
-      // If all incoming values to the Phi are the same, we can replace the Phi
-      // with that value.
-      if (Value *PNV = PN->hasConstantValue()) {
-        if (Instruction *U = dyn_cast<Instruction>(PNV))
-          Insts.insert(U);
-        SE->deleteValueFromRecords(PN);
-        PN->replaceAllUsesWith(PNV);
-        PN->eraseFromParent();
-        Changed = true;
-        continue;
-      }
-    }
+    if (!isInstructionTriviallyDead(I))
+      continue;
+
+    SE->deleteValueFromRecords(I);
 
-    if (isInstructionTriviallyDead(I)) {
-      for (User::op_iterator i = I->op_begin(), e = I->op_end(); i != e; ++i)
-        if (Instruction *U = dyn_cast<Instruction>(*i))
+    for (User::op_iterator i = I->op_begin(), e = I->op_end(); i != e; ++i) {
+      if (Instruction *U = dyn_cast<Instruction>(*i)) {
+        *i = 0;
+        if (U->use_empty())
           Insts.insert(U);
-      SE->deleteValueFromRecords(I);
-      I->eraseFromParent();
-      Changed = true;
+      }
     }
+    
+    I->eraseFromParent();
+    Changed = true;
   }
 }
 
@@ -2067,7 +2060,7 @@
     BasicBlock::iterator I = L->getHeader()->begin();
     while (PHINode *PN = dyn_cast<PHINode>(I++)) {
       // At this point, we know that we have killed one or more IV users.
-      // It is worth checking to see if the cann indvar is also
+      // It is worth checking to see if the cannonical indvar is also
       // dead, so that we can remove it as well.
       //
       // We can remove a PHI if it is on a cycle in the def-use graph





More information about the llvm-commits mailing list