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

Duncan Sands baldrick at free.fr
Tue Jul 3 11:17:05 PDT 2012


Hi Nuno,

> improve PHINode::hasConstantValue() to detect recursive cases like %phi = phi(%phi,42) as constant

if every entry is the phi node itself, maybe you should return undef rather
than the phi.

Ciao, Duncan.

>
> 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;
>   }
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>





More information about the llvm-commits mailing list