<div dir="ltr">For case C, if F1=50, F2=40, F3=20, it seems it's most beneficial to choose BB->Succ as fall-through than Pred1->Succ or Pred2->Succ, or am I missing something?</div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jun 23, 2016 at 8:38 PM, 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">davidxl added inline comments.<br>
<span class=""><br>
================<br>
Comment at: lib/CodeGen/MachineBlockPlacement.cpp:610<br>
@@ +609,3 @@<br>
+    //         (C)                 (D)<br>
+    //  (D) is a degenerated case of (C) where Pred1 does not exist. In (D),<br>
+    //  Let<br>
----------------<br>
</span><span class="">danielcdh wrote:<br>
> You mean in (C), right?<br>
</span>yes.<br>
<span class=""><br>
================<br>
Comment at: lib/CodeGen/MachineBlockPlacement.cpp:624<br>
@@ +623,3 @@<br>
+    //  order for BB->Succ to be selected, we must have F1 > F2 + F3. So the<br>
+    //  backward probability threshold is (backward checking igores other<br>
+    //  predecessors other than Pred2):<br>
----------------<br>
</span><span class="">danielcdh wrote:<br>
> This is a little confusing, I think the condition should be:<br>
><br>
> F1 > max(2*F3, F2)<br>
><br>
> So when checking Pred1, the backward threhold should be 0.66, when checking Pred2, the backward threshold should be 0.5?<br>
><br>
> But for the current implementation, I tried all testcase, and some other testcases with different triangle-diamond combination, and it always gives me optimal solution.<br>
</span>It is F1 > F2 + F3.<br>
<br>
Basically, we are comparing selecting BB->Succ as fall through vs selecting BB->Pred1 and Pred2->Succ as fall throughs. In order for BB->Succ to succeed, the minimal min(F1) = F2 + F3.<br>
<br>
When computing backward probability, only BB->Succ and Pred2->Succ edges are considered, so the probability threshold<br>
  T = min(F1) /(min(F1) + F2) = (F2 + F3 )/(2*F2 + F3).<br>
<br>
I will update the comments.<br>
<br>
<br>
<a href="http://reviews.llvm.org/D21663" rel="noreferrer" target="_blank">http://reviews.llvm.org/D21663</a><br>
<br>
<br>
<br>
</blockquote></div><br></div>