[LLVMdev] Eliminating PHI with Identical Inputs

Duncan Sands baldrick at free.fr
Tue Jul 30 08:28:56 PDT 2013


Hi John,

On 30/07/13 17:23, John Criswell wrote:
> On 7/30/13 9:46 AM, Duncan Sands wrote:
>> Hi John,
>>
>> On 30/07/13 16:12, John Criswell wrote:
>>> Dear All,
>>>
>>> Is there a pass (or set of passes) that will replace a phi whose input operands
>>> all compute the same value with an instruction that computes that value?  In
>>> other words, something that will convert:
>>>
>>> define internal i32 @function(i32 %x) {
>>> ...
>>> bb1:
>>> %y = add %x, 10
>>> ...
>>> bb2:
>>> %z = add %x, 10
>>> ...
>>> bb3:
>>> %phi = [bb1, %y], [bb2, %z]
>>>
>>> into
>>>
>>> define internal i32 @function(i32 %x) {
>>> ...
>>> bb1:
>>> ...
>>> bb2:
>>> ...
>>> bb3:
>>> %phi = add %x, 10
>>
>> yes, GVN should replace %y and %z with the same register, giving something like
>>
>>  %same = add %x, 10
>> ...
>>  bb1:
>>  ...
>>  bb2:
>>  ...
>>  bb3:
>>  %phi = [bb1, %same], [bb2, %same]
>>
>> at which point the instcombine pass should zap the phi, though maybe GVN will
>> get it already.
>
> Odd.  I'm running GVN and then InstCombine, and it doesn't fix the problem.
>
> Is this new behavior added since LLVM 3.2, or is this something that GVN has
> been doing for awhile?

I think it's been doing it forever.  If it isn't doing it, then maybe I'm wrong
about GVN doing this, but it could also be due to the topology of the CFG.
After all, it has to put %same somewhere.  If there isn't a good basic block to
drop it in, then it may just give up.  Can you provide a complete example that
shows this problem?

Ciao, Duncan.

>
> -- John T.
>
>>
>> Ciao, Duncan.
>> _______________________________________________
>> LLVM Developers mailing list
>> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>




More information about the llvm-dev mailing list