GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
match Performance Win

Match: Fold min/max patterns for integral types only.

Restricts the "min|max(a+|-c,b+|-c) -> min|max(a,b)+|-c" folding pattern to integral types to fix powerpc test failures.

This commit restricts the “min|max(a+|-c,b+|-c) -> min|max(a,b)+|-c” optimization pattern in the GCC match system to only apply to integral types. The original patch lacked type checks, leading to failures in powerpc tests (PR125214). The fix adds an integral type check to the pattern.

In Details

The GCC match system uses pattern matching to simplify expressions during optimization. The original implementation of the "min|max(a+|-c,b+|-c) -> min|max(a,b)+|-c" pattern lacked checks, causing incorrect folding for non-integral types. This commit adds a check for integral types to the match.pd file to resolve this issue.

For Context

Compilers often perform optimizations by recognizing patterns in the code and replacing them with simpler, equivalent expressions. This commit addresses an issue in GCC's pattern-matching system where a specific optimization for min and max functions was being incorrectly applied to non-integer types. By adding a type check, the compiler now only applies this optimization to integer types, preventing incorrect code generation.

Filed Under: optimizationmatch systemintegral types