[PATCH] D39262: [CodeGen] Peel off the dominant case in switch statement in lowering

Hans Wennborg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 25 03:31:05 PDT 2017


hans added a comment.

Thanks! I think doing it here rather than in SimplifyCFG is much better.

I think this can be made both more powerful and simpler, though.

First, I think we want to peel a little later, at least after adjacent cases have been merged into clusters. For example if we have `case 0: case 1: case 2: foo;` and the three together dominate the switch, we probably want to peel that whole cluster instead of only peeling one case. We could even do this after clustering for jump tables, but maybe we don't want to do that. I.e. if one case dominates heavily, maybe it's worth peeling the case separately rather than peeling the jump table out of the switch. On the other hand, if it dominates completely, that jump table should be well predicted...

In any case, to do the peeling I think we should re-use the current lowering mechanism. This should be done at some point before creating the WorkList. Loop through Clusters to find one that dominates. If we find it, call lowerWorkItem with a single work item which represents that cluster to lower it, update the blocks etc. Then remove the peeled cluster from Clusters and proceed as usual.

What do you think?



================
Comment at: lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:139
+    "peel-dominant-case-in-lowering", cl::Hidden, cl::init(true),
+    cl::desc("Peel the dominant case in switch statement in lowering"));
+static cl::opt<unsigned> DominantCasePercentThreshold(
----------------
Could we have just one flag instead of two separate ones? I.e. one flag that enables peeling and sets the threshold (and setting it to 0 would turn it off or something)?


================
Comment at: lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:141
+static cl::opt<unsigned> DominantCasePercentThreshold(
+    "dominant-case-percent-threshold", cl::Hidden, cl::init(66),
+    cl::desc("Set the case probability threshold (<=100) for peeling out from "
----------------
How was the value 66 chosen?


https://reviews.llvm.org/D39262





More information about the llvm-commits mailing list