- Rename AnalysisUsage::preservesAll to getPreservesAll & preservesCFG to
[oota-llvm.git] / lib / Transforms / Utils / SimplifyCFG.cpp
index f7eaa67acf7d9545f7a25d85910758841ab48122..6b642360d6cf0c841e14c04d9c9ba6b226d20d78 100644 (file)
@@ -1,13 +1,6 @@
 //===- SimplifyCFG.cpp - Code to perform CFG simplification ---------------===//
 //
-// SimplifyCFG - This function is used to do simplification of a CFG.  For
-// example, it adjusts branches to branches to eliminate the extra hop, it
-// eliminates unreachable basic blocks, and does other "peephole" optimization
-// of the CFG.  It returns true if a modification was made, and returns an 
-// iterator that designates the first element remaining after the block that
-// was deleted.
-//
-// WARNING:  The entry node of a function may not be simplified.
+// Peephole optimize the CFG.
 //
 //===----------------------------------------------------------------------===//
 
@@ -48,7 +41,7 @@ static bool PropogatePredecessorsForPHIs(BasicBlock *BB, BasicBlock *Succ) {
   // Loop over all of the PHI nodes in the successor BB
   for (BasicBlock::iterator I = Succ->begin();
        PHINode *PN = dyn_cast<PHINode>(&*I); ++I) {
-    Value *OldVal = PN->removeIncomingValue(BB);
+    Value *OldVal = PN->removeIncomingValue(BB, false);
     assert(OldVal && "No entry in PHI for Pred BB!");
 
     for (std::vector<BasicBlock*>::const_iterator PredI = BBPreds.begin(), 
@@ -167,15 +160,16 @@ bool SimplifyCFG(BasicBlock *BB) {
       TerminatorInst *Term = OnlyPred->getTerminator();
 
       // Resolve any PHI nodes at the start of the block.  They are all
-      // guaranteed to have exactly one entry if they exist.
+      // guaranteed to have exactly one entry if they exist, unless there are
+      // multiple duplicate (but guaranteed to be equal) entries for the
+      // incoming edges.  This occurs when there are multiple edges from
+      // OnlyPred to OnlySucc.
       //
       while (PHINode *PN = dyn_cast<PHINode>(&BB->front())) {
-        assert(PN->getNumIncomingValues() == 1 && "Only one pred!");
         PN->replaceAllUsesWith(PN->getIncomingValue(0));
         BB->getInstList().pop_front();  // Delete the phi node...
       }
 
-
       // Delete the unconditional branch from the predecessor...
       OnlyPred->getInstList().pop_back();