Don't use PN->replaceUsesOfWith() to change a PHINode's incoming blocks,
authorJay Foad <jay.foad@gmail.com>
Tue, 21 Jun 2011 10:02:43 +0000 (10:02 +0000)
committerJay Foad <jay.foad@gmail.com>
Tue, 21 Jun 2011 10:02:43 +0000 (10:02 +0000)
because it won't work after my phi operand changes, because the incoming
blocks will no longer be Uses.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@133512 91177308-0d34-0410-b5e6-96231b3b80d8

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;