IT lexicon › Programming › Local value numbering (LVN)

Local value numbering (LVN)

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

The optimization that walks a basic block top to bottom, assigns every computed value a number, and notices when the same computation happens twice.

The algorithm is a hash table plus some discipline. For each instruction, look up the value numbers of its operands and use the operator plus those numbers as a key. If the key is already in the table, the value has been computed before and the instruction becomes a copy. Commutative operators sort their operands first, so a + b and b + a land on the same key. Constant folding and algebraic simplification come along for free, since the table is looking at every expression anyway.

John Cocke and Jacob Schwartz described the technique around 1970. The limitation is right there in the name: the table is thrown away at the block boundary. Extended basic blocks and then global value numbering over SSA form pushed that boundary outward, but the local version is still all that many fast JIT compilers bother with.

← Back to the lexicon