IT lexicon › Programming › Known-bits analysis

Known-bits analysis

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

An analysis that tracks, for each bit of a value, whether it is definitely zero, definitely one or unknown.

After x & 0xF0 the compiler knows the low four bits are zero, whatever x was. A following & 0x0F can be folded to the constant 0, a comparison against an odd number is always false, and a multiply by eight cannot disturb the low bits. Every operation has a rule for carrying the knowledge along: shifts move it, and spreads zeros, and addition spreads uncertainty upward through the carry chain.

In LLVM the function is computeKnownBits, and InstCombine calls it constantly. GCC keeps the equivalent as bitmasks inside its range analysis. It is abstract interpretation at its most down-to-earth: a little information per bit, cheap enough to ask about thousands of times per function.

← Back to the lexicon