Switch instruction lowering

Hi,

I’m interested in any information about implementations of switch instruction and its runtime cost. If it’s very target dependent, I’m mostly care about X86. Pointing some LLVM code is also good.

  • Paweł

`grep -r "switch instruction"` under directory llvm/lib shows a lot of stuff you
might have interest. Most of the code related to switch instructions are under
subdirectories IR and Transformation/Utils.

HTH,
chenwj

I don't think there's any documentation besides the comments in the
code, but switch lowering (to binary tree or jump table, etc.) happens
in SelectionDAGBuilder::visitSwitch()

For switches which are used to select from a set of constant values,
SimplifyCFG will attempt to build a lookup table.

- Hans

Some of the early ideas were actually described in
http://llvm.org/pubs/2007-05-31-Switch-Lowering.pdf

Some more general information on switch lowering can be found in the paper “A Superoptimizer Analysis of Multiway Branch Code Generation” in https://gcc.gnu.org/wiki/HomePage?action=AttachFile&do=get&target=gcc-2008-proceedings.pdf

– Sean Silva