<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 12, 2017 at 2:14 PM, Xin Tong <span dir="ltr"><<a href="mailto:trent.xin.tong@gmail.com" target="_blank">trent.xin.tong@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="gmail-HOEnZb"><div class="gmail-h5">On Thu, Jan 12, 2017 at 2:10 PM, Dehao Chen <<a href="mailto:danielcdh@gmail.com">danielcdh@gmail.com</a>> wrote:<br>
><br>
><br>
> On Thu, Jan 12, 2017 at 2:02 PM, Xin Tong <<a href="mailto:trent.xin.tong@gmail.com">trent.xin.tong@gmail.com</a>> wrote:<br>
>><br>
>> On Thu, Jan 12, 2017 at 1:34 PM, Dehao Chen <<a href="mailto:danielcdh@gmail.com">danielcdh@gmail.com</a>> wrote:<br>
>> > If we assume that the trip count will always be the same, then if back<br>
>> > edge<br>
>> > taken probability falls in the range of (0, 0.5), then it already broke<br>
>> > this<br>
>> > assumption. So we do not have enough info to infer both branch<br>
>> > probabilities. So probably we should simply set the inner probability as<br>
>> > "0". And when we estimate loop trip count, we will always return 0 if<br>
>> > the<br>
>> > latch probability is 0. Something like:<br>
>> ><br>
>> > rotate_update_probability(<wbr>float orig_prob) {<br>
>> >   branch_prob_outside = orig_prob;<br>
>> >   if (orig_prob >= 0 && orig_prob < 0.5) {<br>
>> >     branch_prob_inside = 0;<br>
>> >   } else {<br>
>> >     branch_prob_inside = 2 - 1/orig_prob;<br>
>> >   }<br>
>> > }<br>
>> ><br>
>> > int estimate_trip_count(float latch_probability) {<br>
>> >    if (latch_probability == 0)<br>
>> >      return 0;<br>
>> >    else<br>
>> >      return 1/(1-latch_probability)<br>
>> > }<br>
>><br>
>> We assume the trip count will be close to each other, they do not have<br>
>> to be identical =). And that assumption has implications, I addressed<br>
>> the implications when we have polarized loop tripcounts in an earlier<br>
>> response. I feel we need to make assumptions and also reason about the<br>
>> fallouts if that assumption turns out to be not true as Michael said.<br>
><br>
><br>
> Yes, the above code is trying to address one case where the assumption is<br>
> untrue.<br>
><br>
>><br>
>><br>
>> Back to your example, I am not sure i understand it fully, is<br>
>> orig_prob the probability of branching outside before rotation ?<br>
><br>
><br>
> Yes, orig_prob is the original probability of the branch before loop<br>
> rotation.<br>
<br>
</div></div>If orig_prob == 0.5, the branch_prob_inside is 0. (branch_prob_inside<br>
is the probability that the loop body is branched to before rotation<br>
?).<br></blockquote><div><br></div><div>Sorry about the confusion. Let me use my original example:</div><div><br></div><div>Before loop rotation</div><div><br></div><div><span style="font-size:12.8px">L1:</span><br style="font-size:12.8px"><span style="font-size:12.8px">if (cond) { // "orig_prob"</span><br style="font-size:12.8px"><span style="font-size:12.8px">  stmt;</span><br style="font-size:12.8px"><span style="font-size:12.8px">  goto L1;</span><br style="font-size:12.8px"><span style="font-size:12.8px">}</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">After loop rotation:</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">if (cond) { // "</span>branch_prob_outside"<br style="font-size:12.8px"><span style="font-size:12.8px">L1:</span><br style="font-size:12.8px"><span style="font-size:12.8px">  stmt;</span><br style="font-size:12.8px"><span style="font-size:12.8px">  if (cond) { // "</span>branch_prob_inside" // and also "latch_probability"<br style="font-size:12.8px"><span style="font-size:12.8px">    goto L1;</span><br style="font-size:12.8px"><span style="font-size:12.8px">  }</span><br style="font-size:12.8px"><span style="font-size:12.8px">}</span></div><div><br></div><div>Note that all probability are for when "cond" is true.<br style="font-size:12.8px"><br></div><div>Thanks,</div><div>Dehao</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Thanks,<br>
-Xin<br>
<div class="gmail-HOEnZb"><div class="gmail-h5">><br>
>><br>
>><br>
>> Thanks,<br>
>> -Xin<br>
>><br>
>> ><br>
>> ><br>
>> > On Thu, Jan 12, 2017 at 12:59 PM, Michael Kuperstein via Phabricator<br>
>> > <<a href="mailto:reviews@reviews.llvm.org">reviews@reviews.llvm.org</a>> wrote:<br>
>> >><br>
>> >> mkuper added inline comments.<br>
>> >><br>
>> >><br>
>> >> ================<br>
>> >> Comment at: lib/Transforms/Scalar/<wbr>LoopRotation.cpp:476<br>
>> >> +  // data.<br>
>> >> +  if (!<wbr>updateLoopEstimatedBranchWeigh<wbr>t(L, GBI, BI /* OrigHeader BR<br>
>> >> */)) {<br>
>> >> +    BI->setMetadata(LLVMContext::<wbr>MD_prof, nullptr);<br>
>> >> ----------------<br>
>> >> Also, regardless of the rest of the discussion - I don't think we<br>
>> >> should<br>
>> >> drop the metadata on the floor if we fail.<br>
>> >><br>
>> >> I don't think "No data is better than imprecise data" is right in the<br>
>> >> general case, but that's arguable. Specifically here, though, we're<br>
>> >> imprecise even if updateLoopEstimatedBranchWeigh<wbr>t() succeeds, because<br>
>> >> of the<br>
>> >> assumptions we make on the distribution.<br>
>> >><br>
>> >><br>
>> >> <a href="https://reviews.llvm.org/D28593" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D28593</a><br>
>> >><br>
>> >><br>
>> >><br>
>> ><br>
><br>
><br>
</div></div></blockquote></div><br></div></div>