[llvm-commits] [llvm] r159666 - /llvm/trunk/lib/VMCore/Instructions.cpp

Nuno Lopes nunoplopes at sapo.pt
Tue Jul 3 10:10:28 PDT 2012


Author: nlopes
Date: Tue Jul  3 12:10:28 2012
New Revision: 159666

URL: http://llvm.org/viewvc/llvm-project?rev=159666&view=rev
Log:
improve PHINode::hasConstantValue() to detect recursive cases like %phi = phi(%phi,42) as constant

Modified:
    llvm/trunk/lib/VMCore/Instructions.cpp

Modified: llvm/trunk/lib/VMCore/Instructions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Instructions.cpp?rev=159666&r1=159665&r2=159666&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Instructions.cpp (original)
+++ llvm/trunk/lib/VMCore/Instructions.cpp Tue Jul  3 12:10:28 2012
@@ -161,8 +161,12 @@
   // 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;
 }
 





More information about the llvm-commits mailing list