GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
gcc/match Performance Win

Expose constant factors through signed widening conversions

GCC can now combine constant factors across signed widening conversions for multiplication and division.

GCC’s match pass can now expose constant factors hidden by signed widening conversions in multiplication and division chains. This allows for more aggressive optimization, transforming expressions like (long long) (a * 30) * b / 6 into ((long long) a * b) * 5. The optimization applies to signed integral types with undefined overflow and non-narrowing conversions, with specific checks for division and multiplication to ensure correctness and prevent overflow.

In Details

The match.pd pattern matching file in GCC has been extended to recognize and simplify constant factors across signed integral widening conversions. Previously, conversions like (long long)(a * C) could prevent constant propagation and reassociation rules from applying. This change enables simplification by directly combining constants in multiply/multiply or multiply/divide chains, provided the intermediate and final results fit the destination type and no overflow is flagged.

For Context
signed widening conversion
A type conversion that increases the range of representable values for a signed integer type, typically from a smaller type to a larger one (e.g., int to long long). It preserves the value if it's representable in the larger type.
multiplication reassociation
An algebraic transformation that allows regrouping of operands in a chain of multiplications, e.g., (a * b) * c is equivalent to a * (b * c).
constant propagation
A compiler optimization that replaces variables holding constant values with their actual constant values throughout the code.
pattern matching (GCC)
A phase in GCC's optimization passes where the compiler searches for specific code patterns in the intermediate representation (tree) and applies transformations or simplifications based on predefined rules.
Filed Under: optimizationgcc