<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Jun 29, 2015 at 3:48 PM, 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:39 AM, Cong Hou <<a href="mailto:congh@google.com">congh@google.com</a>> wrote:<br>
> On Mon, Jun 29, 2015 at 11:21 AM, Xinliang David Li <<a href="mailto:davidxl@google.com">davidxl@google.com</a>><br>
> wrote:<br>
>><br>
>> 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=H8jRSoeVe-4r5z4oSEQ0uImyPC6XJHSlVnD5ZZa0HWc&s=4WnUj-WyyKPBbIMYj_Smkwp7Ua8XdsGgBsxPtdluntk&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<br>
>> >> with more complicated control flow. To handle those cases, I think you need<br>
>> >> to generalize it  by computing the complete branch costs for all rotation<br>
>> >> candidates and select the one with the least cost.  The entry and exit<br>
>> >> connection cost computation remains the same. To compute taken branch cost,<br>
>> >> there are only 4 cases to consider: tail BB with 1 successor, tail BB<br>
>> >> multiple successors, non-tail BB with 1 successor, non-tail BB with multiple<br>
>> >> 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<br>
>> > BBs in a loop, which is a drawback. I will propose another patch that<br>
>> > changes this behavior. In the new algorithm, the loop chain formation may<br>
>> > stop as long as an exit is reached, and only this loop chain will be<br>
>> > rotated. This is similar to GCC's strategy. In the above example, once<br>
>> > B1->B3->B4 is formed, the loop chain build is complete. Then B1 is the best<br>
>> > candidate to be the chain bottom as there is an fall-thru edge from B1 to<br>
>> > B2.<br>
>><br>
>><br>
>> 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>
><br>
><br>
> The patch here can handle the example proposed by you. We consider to rotate<br>
> the chain B1 B2 B3 B4, and the result B3 B4 B1 B2 is best. This is because<br>
> there is no edge from B2 to B3, so in our "benifit" analysis this won't<br>
> become a negative contribution to the benefit.<br>
<br>
</div></div>True, but It is unclear whether it works by accident or by design?  We<br>
need to be able to prove that the current benefit analysis is good for<br>
arbitrary control flow in loop.<br>
<br></blockquote><div><br></div><div>When rotating the loop, all impacts in terms of our cost model are considered, so this patch should not hurt the performance if our cost model is correct. In some cases, with the current LLVM's bb-layout algorithm, rotating loop could not give us the best result: this is not the fault of the loop rotation, but how we build chains for loops. In other words, in the future if we improve the loop chain builds in LLVM, we can still use the same loop rotation algorithm.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
A new test case like this one or other cases are useful in the patch too.<br></blockquote><div><br></div><div>I will add a new test case with diamond CFG to this patch.</div><div><br></div><div><br></div><div>Cong</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>
><br>
>><br>
>><br>
>> David<br>
>><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=H8jRSoeVe-4r5z4oSEQ0uImyPC6XJHSlVnD5ZZa0HWc&s=JBzmKs3hXmtNRuiHxV-Pz7SKZnabutCDgzMi2Ksy6r0&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=H8jRSoeVe-4r5z4oSEQ0uImyPC6XJHSlVnD5ZZa0HWc&s=Q4GO6jcj63zQ8pDZBU72s7N0wn61TKq77IcoCay9OWk&e=" rel="noreferrer" target="_blank">http://reviews.llvm.org/settings/panel/emailpreferences/</a><br>
>> ><br>
>> ><br>
><br>
><br>
</div></div></blockquote></div><br></div></div>