diff options
Diffstat (limited to 'lib/VMCore/BasicBlock.cpp')
-rw-r--r-- | lib/VMCore/BasicBlock.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/VMCore/BasicBlock.cpp b/lib/VMCore/BasicBlock.cpp index 98d12d8f13..407080cf68 100644 --- a/lib/VMCore/BasicBlock.cpp +++ b/lib/VMCore/BasicBlock.cpp @@ -189,8 +189,16 @@ void BasicBlock::removePredecessor(BasicBlock *Pred, // Okay, now we know that we need to remove predecessor #pred_idx from all // PHI nodes. Iterate over each PHI node fixing them up PHINode *PN; - for (iterator II = begin(); (PN = dyn_cast<PHINode>(II)); ++II) + for (iterator II = begin(); (PN = dyn_cast<PHINode>(II)); ++II) { PN->removeIncomingValue(Pred, false); + // If all incoming values to the Phi are the same, we can replace the Phi + // with that value. + if (Value *PNV = PN->hasConstantValue()) + if (!isa<Instruction>(PNV)) { + PN->replaceAllUsesWith(PNV); + PN->eraseFromParent(); + } + } } } |