<div dir="ltr">If we assume that the trip count will always be the same, then if back edge taken probability falls in the range of (0, 0.5), then it already broke this assumption. So we do not have enough info to infer both branch probabilities. So probably we should simply set the inner probability as "0". And when we estimate loop trip count, we will always return 0 if the latch probability is 0. Something like:<div><br></div><div>rotate_update_probability(float orig_prob) {</div><div>  branch_prob_outside = orig_prob;<br></div><div>  if (orig_prob >= 0 && orig_prob < 0.5) {</div><div>    branch_prob_inside = 0;</div><div>  } else {</div><div>    branch_prob_inside = 2 - 1/orig_prob;<br></div><div>  }</div><div>}</div><div><br></div><div>int estimate_trip_count(float latch_probability) {</div><div>   if (latch_probability == 0)</div><div>     return 0;</div><div>   else</div><div>     return 1/(1-latch_probability)</div><div>}</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 12, 2017 at 12:59 PM, Michael Kuperstein via Phabricator <span dir="ltr"><<a href="mailto:reviews@reviews.llvm.org" target="_blank">reviews@reviews.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">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>
+    BI->setMetadata(LLVMContext::<wbr>MD_prof, nullptr);<br>
----------------<br>
Also, regardless of the rest of the discussion - I don't think we should 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 general case, but that's arguable. Specifically here, though, we're imprecise even if updateLoopEstimatedBranchWeigh<wbr>t() succeeds, because of the 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>
</blockquote></div><br></div>