* Fix bug: test/Regression/Transforms/Mem2Reg/2002-03-28-UninitializedVal.ll
authorChris Lattner <sabre@nondot.org>
Sun, 28 Apr 2002 18:39:46 +0000 (18:39 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 28 Apr 2002 18:39:46 +0000 (18:39 +0000)
* 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

index e9ca9f15c3bc2ba408d650416b4211fc0eb5b911..23dd2865a06120dbf64cb77da08b9868873de3d0 100644 (file)
@@ -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<Value *>(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<Value *>(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<PHINode *> &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