From 5b5df1747feac197fd839c956952fd4d79c58e79 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 28 Apr 2002 18:39:46 +0000 Subject: [PATCH] * Fix bug: test/Regression/Transforms/Mem2Reg/2002-03-28-UninitializedVal.ll * Minor cleanup that was missed in last patch git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2373 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Utils/PromoteMemoryToRegister.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp index e9ca9f15c3b..23dd2865a06 100644 --- a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp +++ b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp @@ -146,10 +146,18 @@ bool PromoteInstance::PromoteFunction(Function *F, DominanceFrontier &DF) { } } + // Set the incoming values for the basic block to be null values for all of + // the alloca's. We do this in case there is a load of a value that has not + // been stored yet. In this case, it will get this null value. + // + CurrentValue.push_back(vector(Allocas.size())); + for (unsigned i = 0, e = Allocas.size(); i != e; ++i) + CurrentValue[0][i] = + Constant::getNullValue(Allocas[i]->getType()->getElementType()); + // Walks all basic blocks in the function performing the SSA rename algorithm // and inserting the phi nodes we marked as necessary // - CurrentValue.push_back(vector(Allocas.size())); traverse(F->front(), 0); // there is no predecessor of the root node // Remove all instructions marked by being placed in the KillList... @@ -197,13 +205,13 @@ void PromoteInstance::traverse(BasicBlock *BB, BasicBlock *Pred) { // variable we need phinodes for. vector &BBPNs = NewPhiNodes[BB]; for (unsigned k = 0; k != BBPNs.size(); ++k) - if (BBPNs[k]) { + if (PHINode *PN = BBPNs[k]) { // at this point we can assume that the array has phi nodes.. let's add // the incoming data - BBPNs[k]->addIncoming(TOS[k], Pred); + PN->addIncoming(TOS[k], Pred); // also note that the active variable IS designated by the phi node - TOS[k] = BBPNs[k]; + TOS[k] = PN; } // don't revisit nodes -- 2.34.1