[LLVMdev] Lowering switch statements with PGO

Duncan P. N. Exon Smith dexonsmith at apple.com
Thu Dec 18 21:01:28 PST 2014


> On 2014 Dec 18, at 04:18, Chandler Carruth <chandlerc at google.com> wrote:
> 
> (this is a total side-note)
> 
> On Mon, Dec 15, 2014 at 10:18 PM, Bob Wilson <bob.wilson at apple.com> wrote:
> I don’t remember any static heuristics for switches.
> 
> We should probably bias slightly toward a single case for switches where one dominates the value range space of the input, and that one doesn't have some other heuristic (such as we provide for an unreachable-terminated block) applied to it.

(Still off-topic...)

I'm not convinced.  I imagine there's enough code like this:

    int state = ...;
    switch (state) {
    default:
      return make_error("unexpected state", state);
    case StateStart:
      // ...
      break;
    case StateA:
      // ...
      break;
    case StateB:
      // ...
      break;
    case StateC:
      // ...
      break;
    }

that the heuristic could do a fair bit of harm.

I'm not sure you can do much good without a profile.



More information about the llvm-dev mailing list