aboutsummaryrefslogtreecommitdiff
path: root/lib/VMCore/Instructions.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-08-05 01:00:58 +0000
committerChris Lattner <sabre@nondot.org>2005-08-05 01:00:58 +0000
commitb3b48e11dad271bd236aaec1a601f4a02bfb5374 (patch)
treeb6ca0b71850ed9fad32384d93d183da599101948 /lib/VMCore/Instructions.cpp
parent2733b30195f1681141576b5463778ffa625516d4 (diff)
Use the bool argument to hasConstantValue to decide whether the client is
prepared to deal with return values that do not dominate the PHI. If we cannot prove that the result dominates the PHI node, do not return it if the client can't cope. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22669 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Instructions.cpp')
-rw-r--r--lib/VMCore/Instructions.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp
index a3bd468fcc..efeb2c3766 100644
--- a/lib/VMCore/Instructions.cpp
+++ b/lib/VMCore/Instructions.cpp
@@ -144,9 +144,11 @@ Value *PHINode::hasConstantValue(bool AllowNonDominatingInstruction) const {
// the PHI node with the incoming value.
//
Value *InVal = 0;
+ bool HasUndefInput = false;
for (unsigned i = 0, e = getNumIncomingValues(); i != e; ++i)
- if (getIncomingValue(i) != this && // Not the PHI node itself...
- !isa<UndefValue>(getIncomingValue(i)))
+ if (isa<UndefValue>(getIncomingValue(i)))
+ HasUndefInput = true;
+ else if (getIncomingValue(i) != this) // Not the PHI node itself...
if (InVal && getIncomingValue(i) != InVal)
return 0; // Not the same, bail out.
else
@@ -158,6 +160,16 @@ Value *PHINode::hasConstantValue(bool AllowNonDominatingInstruction) const {
//
if (InVal == 0) InVal = UndefValue::get(getType());
+ // If we have a PHI node like phi(X, undef, X), where X is defined by some
+ // instruction, we cannot always return X as the result of the PHI node. Only
+ // do this if X is not an instruction (thus it must dominate the PHI block),
+ // or if the client is prepared to deal with this possibility.
+ if (HasUndefInput && !AllowNonDominatingInstruction)
+ if (Instruction *IV = dyn_cast<Instruction>(InVal))
+ // If it's in the entry block, it dominates everything.
+ if (IV->getParent() != &IV->getParent()->getParent()->front())
+ return 0; // Cannot guarantee that InVal dominates this PHINode.
+
// All of the incoming values are the same, return the value now.
return InVal;
}