[PATCH] Enhance loop rotation with existence of profile data in MachineBlockPlacement pass.

Xinliang David Li davidxl at google.com
Mon Jun 29 11:21:20 PDT 2015


On Mon, Jun 29, 2015 at 11:03 AM, Cong Hou <congh at google.com> wrote:
> In http://reviews.llvm.org/D10717#196064, @davidxl wrote:
>
>> Cong, the proposed cost analysis can not handle diamond shaped or loops with more complicated control flow. To handle those cases, I think you need to generalize it  by computing the complete branch costs for all rotation candidates and select the one with the least cost.  The entry and exit connection cost computation remains the same. To compute taken branch cost, there are only 4 cases to consider: tail BB with 1 successor, tail BB multiple successors, non-tail BB with 1 successor, non-tail BB with multiple successors.
>>
>> B0
>>  do {
>>
>>   B1
>>   if (..) {
>>    B2
>>   } else {
>>    B3
>>   }
>>
>> B4
>>  } while (..);
>>  B5;
>>
>> If the original layout keeps the topo order:
>>  B0 B1 B2 B3 B4 B5
>>
>> The cost analysis should discover the optimal rotation to be
>>  B0 B3 B4 B1 B2 B5
>
>
> As we know, the current LLVM's algorithm always form a chain with all BBs in a loop, which is a drawback. I will propose another patch that changes this behavior. In the new algorithm, the loop chain formation may stop as long as an exit is reached, and only this loop chain will be rotated. This is similar to GCC's strategy. In the above example, once B1->B3->B4 is formed, the loop chain build is complete. Then B1 is the best candidate to be the chain bottom as there is an fall-thru edge from B1 to B2.


There two parts of the problem:

1) form the best base layout for the loop
2) find the best rotation strategy for the base layout.

We are focusing on 2) here.  What I meant is that by enhancing your
cost analysis using the scheme I mentioned, it is possible to find the
best rotation even with the current base loop layout strategy (i.e.,
forming a chain with all BBs) -- I manually verified the example
quoted.

David


>
>
> http://reviews.llvm.org/D10717
>
> EMAIL PREFERENCES
>   http://reviews.llvm.org/settings/panel/emailpreferences/
>
>




More information about the llvm-commits mailing list