aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/VMCore/Instructions.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp
index d9c20872f8..7de5602f08 100644
--- a/lib/VMCore/Instructions.cpp
+++ b/lib/VMCore/Instructions.cpp
@@ -138,8 +138,11 @@ void PHINode::resizeOperands(unsigned NumOps) {
Value *PHINode::hasConstantValue(bool AllowNonDominatingInstruction) const {
// If the PHI node only has one incoming value, eliminate the PHI node...
if (getNumIncomingValues() == 1)
- return getIncomingValue(0);
-
+ if (getIncomingValue(0) != this) // not X = phi X
+ return getIncomingValue(0);
+ else
+ return UndefValue::get(getType()); // Self cycle is dead.
+
// Otherwise if all of the incoming values are the same for the PHI, replace
// the PHI node with the incoming value.
//