fix a bug in r121680 that upset the various buildbots.
[oota-llvm.git] / lib / Transforms / Utils / SimplifyCFG.cpp
index e16125e8326b9e9e36e4b6dc59229d4f5f3f60f9..9187a0f1752227ab487284f483288ab6021edf91 100644 (file)
@@ -1899,6 +1899,13 @@ static bool SimplifyBranchOnICmpChain(BranchInst *BI, const TargetData *TD) {
     
     BranchInst::Create(EdgeBB, NewBB, ExtraCase, OldTI);
     OldTI->eraseFromParent();
+    
+    // If there are PHI nodes in EdgeBB, then we need to add a new entry to them
+    // for the edge we just added.
+    for (BasicBlock::iterator I = EdgeBB->begin(); isa<PHINode>(I); ++I) {
+      PHINode *PN = cast<PHINode>(I);
+      PN->addIncoming(PN->getIncomingValueForBlock(NewBB), BB);
+    }    
     BB = NewBB;
   }