How GCC Eliminates Unnecessary Integer Division
Summary
The piece explains GCC's optimization that replaces division by a constant with a multiply-and-compare using magic numbers. It covers the math behind reciprocal multiplication, the round-up/round-down approaches, and provides code and assembly examples, plus references to Libdivide and related papers. The article also includes a practical guide to finding magic numbers and testing divisibility efficiently.