<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Jun 29, 2015 at 6:52 PM, Xinliang David Li <span dir="ltr"><<a href="mailto:davidxl@google.com" target="_blank">davidxl@google.com</a>></span> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Mon, Jun 29, 2015 at 5:14 PM, Xinliang David Li <<a href="mailto:davidxl@google.com">davidxl@google.com</a>> wrote:<br>
>>> > The patch here can handle the example proposed by you. We consider to<br>
>>> > rotate<br>
>>> > the chain B1 B2 B3 B4, and the result B3 B4 B1 B2 is best. This is<br>
>>> > 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>
>>> 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>
>><br>
>> When rotating the loop, all impacts in terms of our cost model are<br>
>> considered, so this patch should not hurt the performance if our cost model<br>
>> is correct.<br>
><br>
> yes -- that is what I'd like to hear but analytically prove it will be better :)<br>
<br>
</span>Thinking about it a little more -- your 3-parts cost function is<br>
actually complete and can be proved. Imagining the ideal base layout<br>
where the tail to head edge is also a fall-through -- this layout has<br>
a fixed cost/benefit. To compute the cost or benefit of a rotation, we<br>
only need to consider the delta between when tail-> head edge converts<br>
from fall-through to non-fall-through edge.<br>
<br>
There is a minor issue with the part-3 computation. It is the case<br>
when tail to head is a conditional branch, and the other edge also<br>
loops back into the loop: in this case should you also consider the<br>
additional cost of needing another unconditional jump ?<br></blockquote><div><br></div><div>This is a good point! In this case we also need to consider the cost of the additional jump. If we assume the cost of misfetch and jmp instruction are identical, then the penalty here should be the frequency of the tail node not the frequency of the edge from tail to head. I will update the patch to reflect this new conclusion. Thanks!</div><div><br></div><div>Cong</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>
>> In some cases, with the current LLVM's bb-layout algorithm,<br>
>> rotating loop could not give us the best result: this is not the fault of<br>
>> the loop rotation, but how we build chains for loops. In other words, in the<br>
>> future if we improve the loop chain builds in LLVM, we can still use the<br>
>> same loop rotation algorithm.<br>
><br>
> yes, because only one dimension of the search space is explored.<br>
> Another dimension will be the base layout (e.g, considering splitting<br>
> etc).  My comment is not about your algorithm to find the optimal<br>
> rotation in this dimension (which is solid), but about where the 3<br>
> component cost function is sufficient.<br>
><br>
> David<br>
>><br>
>><br>
>>><br>
>>> A new test case like this one or other cases are useful in the patch too.<br>
>><br>
>><br>
>> I will add a new test case with diamond CFG to this patch.<br>
>><br>
>><br>
>> Cong<br>
>><br>
>><br>
>>><br>
>>><br>
>>> David<br>
>>><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=1BQMC9paZKOBJsMW1nn-CW1hbFRvSjfleQ09Temrdw8&s=LpvxxZS_VOHVco22bk5yI0aH3guZMF04qyLTJj3JhK8&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=1BQMC9paZKOBJsMW1nn-CW1hbFRvSjfleQ09Temrdw8&s=Aspuh4sD-AHYeeYXF2EoCFvEQBTyMPkEDbZQcvnzQFs&e=" rel="noreferrer" target="_blank">http://reviews.llvm.org/settings/panel/emailpreferences/</a><br>
>>> >> ><br>
>>> >> ><br>
>>> ><br>
>>> ><br>
>><br>
>><br>
</div></div></blockquote></div><br></div></div>