GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
match

Fix min/max patterns for signed comparisons

Corrected min/max pattern matching to accurately handle signed comparisons involving types with differing precision.

A recent change in pattern matching for min/max operations introduced a bug when comparing signed types that differed only in precision. This fix ensures that the comparison correctly uses the precision of the constant zero, preventing incorrect min/max detection and potential miscompilation.

In Details

The match.pd file's min/max detection logic incorrectly identified values as min/max when the precision of the two operands differed. Specifically, SIGNED_TYPE_MIN was formed using the wrong type, leading to misinterpretations when operand types had only a one-bit precision difference. This change corrects the precision calculation by using the precision of the constant 0 instead of the final type.

For Context
pattern matching
A compiler technique where specific code structures or patterns are recognized and replaced with optimized equivalents.
min/max patterns
Specific code patterns recognized by the compiler that can be optimized into efficient min or max operations.
precision
In the context of numeric types, precision refers to the number of bits used to represent a value, affecting the range and accuracy.
Filed Under: optimizationcompiler internals