IT lexicon › Programming › Global code motion (GCM)

Global code motion (GCM)

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

Cliff Click's 1995 algorithm for assigning free-floating instructions to basic blocks — as late as possible, but outside as many loops as possible.

In a sea-of-nodes graph most computations have no fixed home; they are tied together only by their data dependencies. Before any code can be emitted, every node needs a basic block. GCM makes two sweeps: first it finds the earliest legal block, where all inputs are available, using the dominator tree. Then the latest, the nearest common dominator of all uses. Between the two it picks the block with the shallowest loop nesting.

The upshot is loop-invariant code motion and code sinking in a single pass, with neither needing to run on its own. Click published the method together with global value numbering, and it became the heart of HotSpot's C2 compiler, which he helped build.

← Back to the lexicon