Value numbering

Value numbering is a technique of determining when two computations in a program are equivalent and eliminating one of them with a semantics-preserving optimization.

Global value numbering (GVN) is a compiler optimization based on the static single assignment form (SSA) intermediate representation.

At the same time, however, CSE may eliminate code that GVN does not, so both are often found in modern compilers.

Global value numbering is distinct from local value numbering in that the value-number mappings hold across basic block boundaries as well, and different algorithms are used to compute the mappings.

In IRs and source languages where rebinding (assigning to the same variable more than once) is possible, SSA form is required to perform GVN so that false

LVN is a local optimization, meaning that unlike global value numbering, it operates on a single basic block at a time.

For example: By assigning numbers to instructions, comparing for duplicates is turned into simple integer comparisons.

A simple implementation might also be unable to catch all equivalent expressions, even when they only differ by the order of their operands.

[1] Local value numbering optimizers may also be aware of mathematical identities.