IT lexicon › Programming › Natural loop

Natural loop

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

The definition of a loop compilers actually use: a back edge to a block that dominates its source, plus everything that reaches the edge without passing through that block.

Source code has for and while; the optimizer only sees a control-flow graph. An edge n→h where h dominates n is a back edge, h is the loop header, and the loop is h plus every block that can reach n without going through h. The header is the only way in, so the compiler can slip a preheader block in front of it and hoist invariant computations there. Frances Allen formalised it around 1970.

Structured code always yields reducible graphs in which every loop is natural. With goto you can build a loop with two entrances, and then many optimizations simply give up — or duplicate blocks until the graph is reducible again.

← Back to the lexicon