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

Cong Hou congh at google.com
Mon Jun 29 11:03:25 PDT 2015


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.


http://reviews.llvm.org/D10717

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






More information about the llvm-commits mailing list