<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Sep 15, 2017 at 4:25 PM, David Li 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">davidxl added inline comments.<br>
<span class=""><br>
<br>
================<br>
Comment at: lib/Transforms/Utils/<wbr>SimplifyCFG.cpp:5680<br>
<br>
+  if (PeelDominantCase(SI, Builder))<br>
+    return SimplifyCFG(BB, TTI, BonusInstThreshold, AC) | true;<br>
----------------<br>
</span><span class="">hans wrote:<br>
> I don't think we should do this if SwitchToLookupTable (the call below) can turn the swich into a lookup instead.<br>
><br>
> In fact, I don't think this should be done at the IR level at all, since it's more of a switch lowering issue. SelectionDAGBuilder::<wbr>visitSwitch() would be a better place.<br>
><br>
> That code already takes case weights into account, and when lowering to a binary search tree, it will balance it based on weight, favoring cases that are hot. Do you find that that's not sufficient? (I'm willing to believe that's the case, but I'd like to see it argued.)<br>
</span>Peeling the  dominating case avoids a memory read (table lookup). Besides it trades a indirect branch for a a highly biased direct branch (which is usually highly predictable by the branch predictor).<br>
<br>
Like looping which happens at higher level,  switch peeling can also enable more possible surrounding optimizations (eg like jump threading).  Peeling it out also probably also makes it easier to for better code layout.<br>
<br>
On the other hand, this should not be done when size optimization is on.<br></blockquote><div>Yes. I agree.  Will update the patch with this. </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
<br>
<br>
<br>
<a href="https://reviews.llvm.org/D37940" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D37940</a><br>
<br>
<br>
<br>
</blockquote></div><br></div></div>