From 7a5745b38ccdf2794a6f04f01a1c8115ec223ad8 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 4 Aug 2007 20:01:43 +0000 Subject: [PATCH] When PromoteLocallyUsedAllocas promoted allocas, it didn't remember 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 | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp index ad09e680228..c5861832a1a 100644 --- a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp +++ b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp @@ -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 &AIs) { } } } + + // At the end of the block scan, all allocas in CurValues are dead. + for (DenseMap::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(); }