[LLVMdev] Doubt in PHI node elimination

Sanjiv Gupta sanjiv.gupta at microchip.com
Tue Jul 7 22:50:13 PDT 2009


Evan Cheng wrote:
> On Jul 3, 2009, at 4:01 AM, Sanjiv Gupta wrote:
>
>   
>> Sachin.Punyani at microchip.com wrote:
>>     
>>> Hi,
>>>
>>>
>>>
>>> In PHI node elimination pass to insert the copy in the predecessor
>>> block, there is a check if terminator is not an invoke instruction
>>> then place the copy there only. However for invoke terminator
>>> instruction a safe position is located for copy insertion.
>>>
>>>
>>>
>>> My doubt is why is this safe location search done only for invoke
>>> instruction and not for other terminators such as branch.
>>>
>>>
>>>
>>> For my target terminator is branch instruction and it uses the
>>> implicit def (STATUS reg) from its predecessor instruction. PHI
>>> elimination pass inserts the copy just between the branch and its
>>> predecessor. Copy instruction on my target affects the same implicit
>>> def (STATUS reg), hence giving improper information to branch.  If
>>> safe location search for copy insertion is done for branch  
>>> instruction
>>> also then this dependency does not break.
>>>
>>>
>>>       
>> The code in question here is:MachineBasicBlock::iterator
>> PNE::FindCopyInsertPoint(MachineBasicBlock &MBB,
>>                                                     unsigned SrcReg) {
>>  // Handle the trivial case trivially.
>>  if (MBB.empty())
>>    return MBB.begin();
>>
>>  // If this basic block does not contain an invoke, then control flow
>> always
>>  // reaches the end of it, so place the copy there.  The logic below
>> works in
>>  // this case too, but is more expensive.
>>  if (!isa<InvokeInst>(MBB.getBasicBlock()->getTerminator()))
>>    return MBB.getFirstTerminator();
>>
>> If the copy insn affects the status flags, then it should not be
>> inserted between the cmp (which also affects the status flags) and the
>> branch insn.
>>
>> So the above piece of code looks incorrect.
>>     
>
> Ok, there are many places in llvm codegen that insert copies. The  
> implicit assumption is a copy would not alter any register or state  
> information. If your target cannot insert a copy which doesn't modify  
> the status flag then a lot of things might not work.
>
> Evan
>
>   
Since we have only one physical register, a copy will always be eliminated.
Regalloc while removing copy inserts some spills/reloads exactly at the 
same place where copy was inserted, and these spill/reload disturbs the 
status.
Currently we have fixed this issues by placing both cmp and branch in 
the terminator group so that a copy is not inserted in between.


- Sanjiv

>> - Sanjiv
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>>     
>
> _______________________________________________
> 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