Add support for variable argument functions!
[oota-llvm.git] / lib / Transforms / Scalar / ADCE.cpp
index 24ccee60344bd76b9663b9ebbd1e1639d413d780..f7a68e48f8cfe46a716c0dc77a2e88ab609a1e06 100644 (file)
@@ -119,7 +119,7 @@ bool ADCE::dropReferencesOfDeadInstructionsInLiveBlock(BasicBlock *BB) {
   for (BasicBlock::iterator I = BB->begin(), E = --BB->end(); I != E; )
     if (!LiveSet.count(I)) {              // Is this instruction alive?
       I->dropAllReferences();             // Nope, drop references... 
-      if (PHINode *PN = dyn_cast<PHINode>(&*I)) {
+      if (PHINode *PN = dyn_cast<PHINode>(I)) {
         // We don't want to leave PHI nodes in the program that have
         // #arguments != #predecessors, so we remove them now.
         //
@@ -154,7 +154,7 @@ bool ADCE::doADCE() {
        BBI != BBE; ++BBI) {
     BasicBlock *BB = *BBI;
     for (BasicBlock::iterator II = BB->begin(), EI = BB->end(); II != EI; ) {
-      if (II->hasSideEffects() || II->getOpcode() == Instruction::Ret) {
+      if (II->mayWriteToMemory() || II->getOpcode() == Instruction::Ret) {
        markInstructionLive(II);
         ++II;  // Increment the inst iterator if the inst wasn't deleted
       } else if (isInstructionTriviallyDead(II)) {
@@ -310,15 +310,16 @@ bool ADCE::doADCE() {
               // should be identical to the incoming values for LastDead.
               //
               for (BasicBlock::iterator II = NextAlive->begin();
-                   PHINode *PN = dyn_cast<PHINode>(&*II); ++II) {
-                // Get the incoming value for LastDead...
-                int OldIdx = PN->getBasicBlockIndex(LastDead);
-                assert(OldIdx != -1 && "LastDead is not a pred of NextAlive!");
-                Value *InVal = PN->getIncomingValue(OldIdx);
-                
-                // Add an incoming value for BB now...
-                PN->addIncoming(InVal, BB);
-              }
+                   PHINode *PN = dyn_cast<PHINode>(II); ++II)
+                if (LiveSet.count(PN)) {  // Only modify live phi nodes
+                  // Get the incoming value for LastDead...
+                  int OldIdx = PN->getBasicBlockIndex(LastDead);
+                  assert(OldIdx != -1 &&"LastDead is not a pred of NextAlive!");
+                  Value *InVal = PN->getIncomingValue(OldIdx);
+                  
+                  // Add an incoming value for BB now...
+                  PN->addIncoming(InVal, BB);
+                }
             }
           }