<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Jun 29, 2015 at 11:21 AM, Xinliang David Li <span dir="ltr"><<a href="mailto:davidxl@google.com" target="_blank">davidxl@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Mon, Jun 29, 2015 at 11:03 AM, Cong Hou <<a href="mailto:congh@google.com">congh@google.com</a>> wrote:<br>
> In <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_D10717-23196064&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=wXxIvJ2vKKcAYwTEb_OLSeYYTkJi3EPhtuMg1DEMde4&s=JsPDymzfMWtMZAzTNlpSj6vUxrUzqjK_uChKAsPerO8&e=" rel="noreferrer" target="_blank">http://reviews.llvm.org/D10717#196064</a>, @davidxl wrote:<br>
><br>
>> 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.<br>
>><br>
>> B0<br>
>>  do {<br>
>><br>
>>   B1<br>
>>   if (..) {<br>
>>    B2<br>
>>   } else {<br>
>>    B3<br>
>>   }<br>
>><br>
>> B4<br>
>>  } while (..);<br>
>>  B5;<br>
>><br>
>> If the original layout keeps the topo order:<br>
>>  B0 B1 B2 B3 B4 B5<br>
>><br>
>> The cost analysis should discover the optimal rotation to be<br>
>>  B0 B3 B4 B1 B2 B5<br>
><br>
><br>
> 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.<br>
<br>
<br>
</div></div>There two parts of the problem:<br>
<br>
1) form the best base layout for the loop<br>
2) find the best rotation strategy for the base layout.<br>
<br>
We are focusing on 2) here.  What I meant is that by enhancing your<br>
cost analysis using the scheme I mentioned, it is possible to find the<br>
best rotation even with the current base loop layout strategy (i.e.,<br>
forming a chain with all BBs) -- I manually verified the example<br>
quoted.<br></blockquote><div><br></div><div>The patch here can handle the example proposed by you. We consider to rotate the chain B1 B2 B3 B4, and the result B3 B4 B1 B2 is best. This is because there is no edge from B2 to B3, so in our "benifit" analysis this won't become a negative contribution to the benefit.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span class="HOEnZb"><font color="#888888"><br>
David<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
><br>
><br>
> <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_D10717&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=wXxIvJ2vKKcAYwTEb_OLSeYYTkJi3EPhtuMg1DEMde4&s=a6GlG281WrQvX00poVQ6EEB34ib-jEviM2iQxKn3K4g&e=" rel="noreferrer" target="_blank">http://reviews.llvm.org/D10717</a><br>
><br>
> EMAIL PREFERENCES<br>
>   <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_settings_panel_emailpreferences_&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=wXxIvJ2vKKcAYwTEb_OLSeYYTkJi3EPhtuMg1DEMde4&s=s9w7rVOI3MbsbA5g7BU65uxAvhuZCVDUGUiuYNvVTro&e=" rel="noreferrer" target="_blank">http://reviews.llvm.org/settings/panel/emailpreferences/</a><br>
><br>
><br>
</div></div></blockquote></div><br></div></div>