aboutsummaryrefslogtreecommitdiffstats
path: root/lib/VMCore/BasicBlock.cpp
diff options
context:
space:
mode:
authorNate Begeman <natebegeman@mac.com>2005-08-04 23:24:19 +0000
committerNate Begeman <natebegeman@mac.com>2005-08-04 23:24:19 +0000
commita83ba0f5c934e2cdbb5724cab365ecc0b5aae6c6 (patch)
treec2f7359039f56fc721dea9838ec9662af10f8ba0 /lib/VMCore/BasicBlock.cpp
parentf065f05397d0a46482f3dd1ebad31cb2d27bd236 (diff)
downloadexternal_llvm-a83ba0f5c934e2cdbb5724cab365ecc0b5aae6c6.zip
external_llvm-a83ba0f5c934e2cdbb5724cab365ecc0b5aae6c6.tar.gz
external_llvm-a83ba0f5c934e2cdbb5724cab365ecc0b5aae6c6.tar.bz2
Fix a fixme in CondPropagate.cpp by moving a PhiNode optimization into
BasicBlock's removePredecessor routine. This requires shuffling around the definition and implementation of hasContantValue from Utils.h,cpp into Instructions.h,cpp git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22664 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/BasicBlock.cpp')
-rw-r--r--lib/VMCore/BasicBlock.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/VMCore/BasicBlock.cpp b/lib/VMCore/BasicBlock.cpp
index 98d12d8..407080c 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();
+ }
+ }
}
}