IT lexicon › Programming › Loop peeling

Loop peeling

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

The first or last few iterations are split off and emitted as straight-line code, leaving a simpler loop behind.

Plenty of loops have one iteration that behaves differently: the first reads a variable that hasn't been set yet, or the last runs past an edge. While that special case lives inside the loop, every iteration pays to test for it. Peel the odd iteration off and the condition moves outside, leaving a uniform loop body.

These days the main customer is vectorization. Arrays rarely start at an address that suits the SIMD registers, so the compiler peels off a few scalar iterations until the pointer is aligned and runs the rest with wide instructions. Peeling is a cousin of unrolling — both copy the loop body — but the goal is the opposite: not fewer branches, but fewer exceptions.

← Back to the lexicon