When PromoteLocallyUsedAllocas promoted allocas, it didn't remember
authorChris Lattner <sabre@nondot.org>
Sat, 4 Aug 2007 20:01:43 +0000 (20:01 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 4 Aug 2007 20:01:43 +0000 (20:01 +0000)
to increment NumLocalPromoted, and didn't actually delete the
dead alloca, leading to an extra iteration of mem2reg.

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

lib/Transforms/Utils/PromoteMemoryToRegister.cpp

index ad09e680228e333657a5beb848558cada694ad3b..c5861832a1af4897e345e0c826fe30063dd2bb40 100644 (file)
@@ -686,10 +686,10 @@ bool PromoteMem2Reg::PromoteLocallyUsedAlloca(BasicBlock *BB, AllocaInst *AI) {
   }
 
   // After traversing the basic block, there should be no more uses of the
-  // alloca, remove it now.
+  // alloca: remove it now.
   assert(AI->use_empty() && "Uses of alloca from more than one BB??");
   if (AST) AST->deleteValue(AI);
-  AI->getParent()->getInstList().erase(AI);
+  AI->eraseFromParent();
   
   ++NumLocalPromoted;
   return false;
@@ -739,6 +739,17 @@ PromoteLocallyUsedAllocas(BasicBlock *BB, const std::vector<AllocaInst*> &AIs) {
       }
     }
   }
+  
+  // At the end of the block scan, all allocas in CurValues are dead.
+  for (DenseMap<AllocaInst*, Value*>::iterator I = CurValues.begin(),
+       E = CurValues.end(); I != E; ++I) {
+    AllocaInst *AI = I->first;
+    assert(AI->use_empty() && "Uses of alloca from more than one BB??");
+    if (AST) AST->deleteValue(AI);
+    AI->eraseFromParent();
+  }
+
+  NumLocalPromoted += CurValues.size();
 }