GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
middle-end Performance Win

Expand divisions with near-power-of-two divisors

Divisions by divisors near powers of two are now expanded using conditional moves for potential speedups.

GCC can now expand division operations where the divisor is proven to be close to a power of two. The compiler replaces a single division with two constant divisions selected by a conditional move. This optimization is applied only when it is determined to be faster than the original division, and when conditional move instructions are available on the target architecture.

In Details

When range information proves a TRUNC_DIV_EXPR divisor is N or N+1, and one of those values is a power of two, the expand pass can now replace the division with a conditional move selecting between two constant divisions. This is a peephole optimization on GIMPLE, performed if the cost model indicates a speedup over a direct DIV/UDIV.

For Context
TRUNC_DIV_EXPR
A GIMPLE expression representing a division operation where the result is truncated towards zero.
GIMPLE
GCC's internal representation of code between the parses and the final machine code generation. It's a three-address-like code format.
conditional move
A CPU instruction that moves data from one location to another only if a specified condition is met. This can avoid control flow branching, potentially improving performance.
Filed Under: optimizationrisc-v