IT lexicon › Programming › Register spilling

Register spilling

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

What the register allocator does when values don't fit: park one in a stack slot and fetch it back when it's needed again.

Each spilled value gets a spill slot in the function's stack frame. A store goes in after the definition and a load — a reload — before every use. The mechanics are trivial; picking the victim is not. Classic allocators weigh each value's uses by loop depth, often by a factor of ten per nesting level, and evict whatever is cheapest to move out and most in the way.

Modern allocators try hard not to spill at all. A value that is cheap to compute can be rematerialised instead, and a long live range can be split so that only its hot part keeps a register. LLVM's greedy allocator splits first and spills last. For plenty of programs, x86-64 doubling the general-purpose registers from eight to sixteen was worth more than a new CPU generation.

← Back to the lexicon