IT lexicon › Programming › freeze (LLVM)

freeze (LLVM)

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

The LLVM instruction that takes a possibly poisoned value and pins it to something arbitrary but consistent, so the optimizer can move code around without inventing undefined behaviour.

A poison value is harmless until it steers a branch. That becomes a problem for any transformation that moves a condition somewhere it gets evaluated more often than in the original. Loop unswitching is the textbook case: a condition that was only tested if the loop ran at least once is suddenly tested every time, and if it was poison, the compiler has just created undefined behaviour the program never had. freeze fixes that. Given an ordinary value it returns it unchanged; given poison it returns something arbitrary, but the same thing at every use.

The instruction was proposed by Juneyoung Lee, Nuno Lopes and colleagues in their PLDI 2017 paper on taming undefined behaviour in LLVM, and landed in LLVM 10 in 2020. The catch is that freeze blocks some simplifications, so the optimizer tries to prove it isn't needed before inserting one.

← Back to the lexicon