GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
range-op.cc Performance Win

Add division and modulo relation effects for equal operands

Optimizes division and modulo by zero when operands are equal.

This commit enhances range analysis by introducing relation effects for division and modulo operations when the operands are equal. Specifically, if a == b, then a / b is now known to result in 1, and a % b is known to result in 0. This optimization is applied earlier in the compilation process, potentially improving code generated by -O2 and later.

In Details

This change adds VREL_EQ relation effects to the operator_div::op1_op2_relation_effect method in range-op.cc. When op1 == op2, it now establishes that the result of op1 / op2 is 1 and the result of op1 % op2 is 0. These effects are propagated by the evrp (Evaluation of Values in Range Propagation) pass, similar to how dom2/dom3 already handle such cases, but enabling earlier optimization.

For Context
range analysis
A compiler optimization technique that determines the possible range of values a variable can hold during program execution. This information is used to prove properties about the code and enable further optimizations.
relation effect
Information about how an operation affects the relationship between variables or values, used by compiler analysis passes like range analysis. For example, VREL_EQ indicates equality.
division
An arithmetic operation that divides one number by another.
modulo
An arithmetic operation that returns the remainder of a division.
evrp
Evaluation of Values in Range Propagation. A GCC optimization pass that computes and propagates information about the possible range of values for expressions and variables.
Filed Under: optimizationrange-analysistree-optimization