[PATCH] D37940: Peel off the dominant case in switch statement

Rong Xu via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 15 17:05:30 PDT 2017


On Fri, Sep 15, 2017 at 3:56 PM, Hans Wennborg via Phabricator <
reviews at reviews.llvm.org> wrote:

> hans added inline comments.
>
>
> ================
> Comment at: lib/Transforms/Utils/SimplifyCFG.cpp:5680
>
> +  if (PeelDominantCase(SI, Builder))
> +    return SimplifyCFG(BB, TTI, BonusInstThreshold, AC) | true;
> ----------------
> I don't think we should do this if SwitchToLookupTable (the call below)
> can turn the swich into a lookup instead.
>
If there is a dominant case, I think it should be peeled to branch rather
using a  lookup table.

>
> 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::visitSwitch()
> would be a better place.
>
> 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.)

The snippet I included in the description shows BST kind of branch does not
generate the optimal code because of extra branchs.
BST will generate code that improves the worst case scenarios and good for
evenly distributed targets.

This code snippet is from extracted from real application (a network packet
parser). Extra compares bring excessive retired instruction and cause
significant performance penalty.

>


>
> https://reviews.llvm.org/D37940
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170915/c5757db7/attachment.html>


More information about the llvm-commits mailing list