IT lexicon › Programming › Constant propagation

Constant propagation

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

The compiler carries known values through variables, so n = 8; x = n * 2 becomes x = 16 without the programmer lifting a finger.

Constant folding evaluates expressions that are already literal constants; propagation is what gets more expressions into that state. The two run in alternation: a propagated value makes an expression foldable, the folded result propagates further. Each variable sits in a small lattice — not yet known, a specific constant, or varying — and is only ever allowed to move downward.

The strong version is Wegman and Zadeck's sparse conditional constant propagation (SCCP) from 1991. It runs on SSA form and ignores branches that a constant condition can never take, which uncovers constants a naive analysis misses. It is also how debug code behind if (DEBUG) disappears entirely, with dead-code elimination sweeping up afterwards.

← Back to the lexicon