<div dir="ltr"><div><br></div><div>The answer is, in this case, it is better not to choose BB->Succ as the fall through.</div><div><br></div><div>Let's take a look at an example: suppose BB and Pred2 in example C has a predecessor 'S'. With your choice, the layout is</div><div><br></div><div>S, BB, Succ, Pred2, Pred1 with cost F2 + F3 + F2 + F3</div><div><br></div><div>The optimal layout is in fact</div><div><br></div><div>S, BB, P1, P2, Succ with cost F1 + F2 + F3</div><div><br></div><div>David</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jun 23, 2016 at 9:51 PM, Dehao Chen <span dir="ltr"><<a href="mailto:danielcdh@gmail.com" target="_blank">danielcdh@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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="HOEnZb"><div class="h5"><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><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>danielcdh wrote:<br>
> You mean in (C), right?<br>
</span>yes.<br>
<span><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>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>
</div></div></blockquote></div><br></div>