[llvm-commits] CVS: llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp

Chris Lattner lattner at cs.uiuc.edu
Thu Apr 24 19:56:00 PDT 2003


Changes in directory llvm/lib/Transforms/Utils:

PromoteMemoryToRegister.cpp updated: 1.40 -> 1.41

---
Log message:

Fix bug: mem2reg/2003-04-24-MultipleIdenticalSuccessors.ll


---
Diffs of the changes:

Index: llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
diff -u llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp:1.40 llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp:1.41
--- llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp:1.40	Thu Apr 24 12:52:20 2003
+++ llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp	Thu Apr 24 19:54:58 2003
@@ -222,13 +222,14 @@
   std::vector<PHINode *> &BBPNs = NewPhiNodes[BB];
   for (unsigned k = 0; k != BBPNs.size(); ++k)
     if (PHINode *PN = BBPNs[k]) {
-      int BBI = PN->getBasicBlockIndex(Pred);
-      assert(BBI >= 0 && "Predecessor not in basic block yet!");
-
-      // At this point we can assume that the array has phi nodes.. let's update
-      // the incoming data.
-      PN->setIncomingValue(BBI, IncomingVals[k]);
-
+      // The PHI node may have multiple entries for this predecessor.  We must
+      // make sure we update all of them.
+      for (unsigned i = 0, e = PN->getNumOperands(); i != e; i += 2) {
+        if (PN->getOperand(i+1) == Pred)
+          // At this point we can assume that the array has phi nodes.. let's
+          // update the incoming data.
+          PN->setOperand(i, IncomingVals[k]);
+      }
       // also note that the active variable IS designated by the phi node
       IncomingVals[k] = PN;
     }





More information about the llvm-commits mailing list