IT lexicon › Programming › Instruction selection

Instruction selection

Programming På svenska → Updated: 2026-11-05

The backend stage that turns the intermediate representation into the target processor's actual instructions.

The task is to cover the IR tree with patterns, each matching one machine instruction, using as few and as cheap patterns as possible. On x86, a + b*4 + 12 can become a single lea, and a load, add and store can fuse into one instruction with a memory operand. A naive translation would have produced five.

Early compilers did this with hand-written code and greedy "maximal munch". Later came generators that read a machine description and build the selector automatically; LLVM writes its patterns in TableGen. LLVM's SelectionDAG works one basic block at a time, which misses patterns that span blocks, so its replacement, GlobalISel, works on the whole function.

← Back to the lexicon