summaryrefslogtreecommitdiff
path: root/lib/VMCore/Instructions.cpp
diff options
context:
space:
mode:
authorNuno Lopes <nunoplopes@sapo.pt>2012-07-03 17:10:28 +0000
committerNuno Lopes <nunoplopes@sapo.pt>2012-07-03 17:10:28 +0000
commit44d5c064888aedd70a8f994bd379372d532ab46f (patch)
treedc80f11c102099956b4a05db1076178e3dc33234 /lib/VMCore/Instructions.cpp
parent9ccc83e7f70e63b746cbc7eef9fb06022e758677 (diff)
downloadllvm-44d5c064888aedd70a8f994bd379372d532ab46f.tar.gz
llvm-44d5c064888aedd70a8f994bd379372d532ab46f.tar.bz2
llvm-44d5c064888aedd70a8f994bd379372d532ab46f.tar.xz
improve PHINode::hasConstantValue() to detect recursive cases like %phi = phi(%phi,42) as constant
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@159666 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Instructions.cpp')
-rw-r--r--lib/VMCore/Instructions.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp
index 383994554d..5aef459250 100644
--- a/lib/VMCore/Instructions.cpp
+++ b/lib/VMCore/Instructions.cpp
@@ -161,8 +161,12 @@ Value *PHINode::hasConstantValue() const {
// Exploit the fact that phi nodes always have at least one entry.
Value *ConstantValue = getIncomingValue(0);
for (unsigned i = 1, e = getNumIncomingValues(); i != e; ++i)
- if (getIncomingValue(i) != ConstantValue)
- return 0; // Incoming values not all the same.
+ if (getIncomingValue(i) != ConstantValue && getIncomingValue(i) != this) {
+ if (ConstantValue != this)
+ return 0; // Incoming values not all the same.
+ // The case where the first value is this PHI.
+ ConstantValue = getIncomingValue(i);
+ }
return ConstantValue;
}