IT lexicon › Programming › Guard widening

Guard widening

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

Two nearby guard conditions are merged into a single stronger one checked earlier — legal because giving up too soon is fine when the fallback is deoptimisation.

A guard in JIT-compiled code says: carry on if the condition holds, otherwise leave optimised code and resume in the interpreter. If guard(i < len) is followed by guard(i + 1 < len), the second alone suffices, moved up to where the first was. The odd part is that this stays correct even when the first condition would have held and the second would not: deoptimisation re-executes everything from the guard with full semantics, so all that is lost is speed.

LLVM gained the pass in 2016 from Azul Systems, alongside the llvm.experimental.guard intrinsic. It is the kind of optimisation that only works with an interpreter standing behind it — a static compiler has nowhere safe to retreat to.

← Back to the lexicon