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

Nuno Lopes nunoplopes at sapo.pt
Tue Jul 3 14:17:40 PDT 2012


Quoting Duncan Sands <baldrick at free.fr>:

> 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.

Ah, sounds like a good idea to me. Just implemented that in r159687.

Thanks,
Nuno

> 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;
>>   }
>>



More information about the llvm-commits mailing list