From 0903331006b1bfffe16c225ffbba2245a5d244ca Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 25 Jun 2003 14:58:56 +0000 Subject: [PATCH] Fix bug: Mem2Reg/2003-06-26-IterativePromote.ll llvm-svn: 6901 --- lib/Transforms/Scalar/Mem2Reg.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/Transforms/Scalar/Mem2Reg.cpp b/lib/Transforms/Scalar/Mem2Reg.cpp index 6bd859a4037..b731ab1a4f7 100644 --- a/lib/Transforms/Scalar/Mem2Reg.cpp +++ b/lib/Transforms/Scalar/Mem2Reg.cpp @@ -40,19 +40,26 @@ bool PromotePass::runOnFunction(Function &F) { BasicBlock &BB = F.getEntryNode(); // Get the entry node for the function - // Find allocas that are safe to promote, by looking at all instructions in - // the entry node - for (BasicBlock::iterator I = BB.begin(), E = --BB.end(); I != E; ++I) - if (AllocaInst *AI = dyn_cast(I)) // Is it an alloca? - if (isAllocaPromotable(AI, TD)) - Allocas.push_back(AI); + bool Changed = false; + + while (1) { + Allocas.clear(); + + // Find allocas that are safe to promote, by looking at all instructions in + // the entry node + for (BasicBlock::iterator I = BB.begin(), E = --BB.end(); I != E; ++I) + if (AllocaInst *AI = dyn_cast(I)) // Is it an alloca? + if (isAllocaPromotable(AI, TD)) + Allocas.push_back(AI); + + if (Allocas.empty()) break; - if (!Allocas.empty()) { PromoteMemToReg(Allocas, getAnalysis(), TD); NumPromoted += Allocas.size(); - return true; + Changed = true; } - return false; + + return Changed; } // createPromoteMemoryToRegister - Provide an entry point to create this pass.