IT lexicon › Programming › Shrink-wrapping

Shrink-wrapping

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

An optimisation that moves a function's prologue and epilogue so they only run on the paths that actually need them.

A typical function opens with a quick check — if (p == NULL) return; — and does the heavy lifting afterwards. Without shrink-wrapping, the prologue still saves every callee-saved register and builds the stack frame before the check, only for the epilogue to restore it all again. With it, the saving moves to where the registers first get used, and the early return becomes nearly free.

Fred Chow described the technique at PLDI in 1988. GCC has it behind -fshrink-wrap, and LLVM runs it as a dedicated backend pass. The hard part is that the new placements must dominate and post-dominate everything that uses the registers, and the unwind information for exceptions has to describe a stack that looks different depending on where in the function you are.

← Back to the lexicon