[llvm-commits] CVS: llvm/lib/Transforms/Scalar/CondPropagate.cpp

Chris Lattner lattner at cs.uiuc.edu
Mon Aug 14 14:38:19 PDT 2006



Changes in directory llvm/lib/Transforms/Scalar:

CondPropagate.cpp updated: 1.4 -> 1.5
---
Log message:

Handle single-entry PHI nodes correctly.  This fixes PR877: http://llvm.org/PR877  and
Transforms/CondProp/2006-08-14-SingleEntryPhiCrash.ll


---
Diffs of the changes:  (+11 -1)

 CondPropagate.cpp |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletion(-)


Index: llvm/lib/Transforms/Scalar/CondPropagate.cpp
diff -u llvm/lib/Transforms/Scalar/CondPropagate.cpp:1.4 llvm/lib/Transforms/Scalar/CondPropagate.cpp:1.5
--- llvm/lib/Transforms/Scalar/CondPropagate.cpp:1.4	Thu Aug  4 18:24:19 2005
+++ llvm/lib/Transforms/Scalar/CondPropagate.cpp	Mon Aug 14 16:38:05 2006
@@ -87,8 +87,18 @@
   // If this block ends with an unconditional branch and the only successor has
   // only this block as a predecessor, merge the two blocks together.
   if (BranchInst *BI = dyn_cast<BranchInst>(BB->getTerminator()))
-    if (BI->isUnconditional() && BI->getSuccessor(0)->getSinglePredecessor()) {
+    if (BI->isUnconditional() && BI->getSuccessor(0)->getSinglePredecessor() &&
+        BB != BI->getSuccessor(0)) {
       BasicBlock *Succ = BI->getSuccessor(0);
+      
+      // If Succ has any PHI nodes, they are all single-entry PHI's.
+      while (PHINode *PN = dyn_cast<PHINode>(Succ->begin())) {
+        assert(PN->getNumIncomingValues() == 1 &&
+               "PHI doesn't match parent block");
+        PN->replaceAllUsesWith(PN->getIncomingValue(0));
+        PN->eraseFromParent();
+      }
+      
       // Remove BI.
       BI->eraseFromParent();
 






More information about the llvm-commits mailing list