IT lexicon › Programming › Code sinking

Code sinking

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

An optimisation that moves a computation downward, closer to — ideally into — the branch where its result is actually used.

If x = a * b is computed before an if but only read in one arm, the other arm pays for a result it throws away. Sinking moves the multiply into the arm that wants it. It is the opposite of hoisting, and the two pull in different directions: loop-invariant code motion lifts work out of loops so it runs less often, sinking pushes it down so it runs on fewer paths.

The side effect often matters more than the saving. A value computed right before its use lives for a shorter time, which lowers register pressure and cuts down on spills. LLVM and GCC both have dedicated sinking passes. The limit is side effects: a load can't be sunk past a store that might hit the same address, which is where the pass needs help from alias analysis.

← Back to the lexicon