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

match: Simplify min|max(a+|-c,b+|-c) to min|max(a,b)+|-c

The compiler now simplifies `min|max(a+|-c,b+|-c)` to `min|max(a,b)+|-c`, potentially improving code efficiency.

The compiler’s pattern matching infrastructure now simplifies expressions of the form min (a + c, b + c) to min (a, b) + c, and similarly for max and subtraction. This transformation can reduce the number of operations and improve code efficiency, especially in loops or other performance-critical sections. New test cases have been added to verify this simplification.

In Details

This patch adds new simplification patterns to match.pd that transform min|max(a+|-c, b+|-c) into min|max(a, b)+|-c. The match.pd file defines pattern-matching rules for tree optimizations. This change primarily affects the tree-optimization pass and aims to simplify expressions involving minimum/maximum operations.

For Context

This commit introduces a new optimization in the compiler that simplifies certain mathematical expressions. Specifically, it transforms expressions that find the minimum or maximum of two values after adding or subtracting the same constant from both. For example, min(x + 5, y + 5) can now be simplified to min(x, y) + 5. This kind of simplification can help the compiler generate more efficient code, especially in cases where these expressions appear frequently.

Filed Under: optimizationpattern matchingalgebraic simplification