summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-08-20 15:35:35 +0000
committerChris Lattner <sabre@nondot.org>2002-08-20 15:35:35 +0000
commit9cd1e661554f99a31e7f31b5018f0b2aa80dcfda (patch)
treea27a1c5d99df8b12c8ddfaabc5bdbd9bca943f6e /llvm/lib/Transforms
parent019783b1bfa06d685b4d3e16471848e3d7041a64 (diff)
downloadbcm5719-llvm-9cd1e661554f99a31e7f31b5018f0b2aa80dcfda.tar.gz
bcm5719-llvm-9cd1e661554f99a31e7f31b5018f0b2aa80dcfda.zip
- implemented instcombine of phi (X, X, X) -> X
llvm-svn: 3397
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/InstructionCombining.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
index 088a758c7f5..71c2cc6e3f5 100644
--- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -594,10 +594,21 @@ Instruction *InstCombiner::visitCastInst(CastInst &CI) {
//
Instruction *InstCombiner::visitPHINode(PHINode &PN) {
// If the PHI node only has one incoming value, eliminate the PHI node...
+ if (PN.getNumIncomingValues() == 0)
+ return ReplaceInstUsesWith(PN, Constant::getNullValue(PN.getType()));
if (PN.getNumIncomingValues() == 1)
return ReplaceInstUsesWith(PN, PN.getIncomingValue(0));
+
+ // Otherwise if all of the incoming values are the same for the PHI, replace
+ // the PHI node with the incoming value.
+ //
+ Value *InVal = PN.getIncomingValue(0);
+ for (unsigned i = 1, e = PN.getNumIncomingValues(); i != e; ++i)
+ if (PN.getIncomingValue(i) != InVal)
+ return 0; // Not the same, bail out.
- return 0;
+ // All of the incoming values are the same, replace the PHI node now.
+ return ReplaceInstUsesWith(PN, InVal);
}
OpenPOWER on IntegriCloud