Don't use PN->replaceUsesOfWith() to change a PHINode's incoming blocks,
[oota-llvm.git] / lib / Transforms / Scalar / LoopDeletion.cpp
index 753a558cfe83aa1ebb1aacca811c1ae5afb7072f..f7f32981baa77e6e46c394fa4042e68a7781b05f 100644 (file)
@@ -190,7 +190,9 @@ bool LoopDeletion::runOnLoop(Loop* L, LPPassManager& LPM) {
   BasicBlock* exitingBlock = exitingBlocks[0];
   BasicBlock::iterator BI = exitBlock->begin();
   while (PHINode* P = dyn_cast<PHINode>(BI)) {
-    P->replaceUsesOfWith(exitingBlock, preheader);
+    int j = P->getBasicBlockIndex(exitingBlock);
+    assert(j >= 0 && "Can't find exiting block in exit block's phi node!");
+    P->setIncomingBlock(j, preheader);
     for (unsigned i = 1; i < exitingBlocks.size(); ++i)
       P->removeIncomingValue(exitingBlocks[i]);
     ++BI;