GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
tree-optimization Performance Win

Fold canonicalized vector min/max conditionals

Improves optimization of vector min/max expressions with conditional operations.

This commit enhances GCC’s ability to optimize vector conditional expressions involving minimum and maximum operations. It introduces new pattern matching rules in match.pd to recognize canonicalized forms of VEC_COND_EXPR for min/max, including those resulting from negative signed maximums or positive signed/unsigned minimums. The optimization handles both normal and reversed conditional arms and works with uniform and non-uniform vector constants. New test cases validate the improvements.

In Details

The match.pd and related tree-optimization passes now recognize and fold vector conditional expressions that represent min/max operations, even when they are in a canonicalized form not previously handled. Specifically, patterns are added for VEC_COND_EXPR where the comparison involves GE/LT (for max) or LE/GT (for min) and the result is a vector constant. This allows folding of expressions like X >= { -99, -98 } ? X : { -100, -99 } into MAX_EXPR <X, { -100, -99 }>. The implementation includes helper functions like record_uniform_integer_difference and `uniform_vector_differ…

For Context
VEC_COND_EXPR
GCC's internal representation for a conditional expression operating on vector types. It typically involves a condition, a value if true, and a value if false.
vector constant
A constant value representing multiple elements of a vector type, e.g., {1, 2, 3, 4} for a 4-element vector.
canonicalized form
A standardized or simplified representation of an expression or value, making it easier for the compiler to match and optimize.
uniform vector constant
A vector constant where all elements have the same value.
MAX_EXPR
GCC's internal representation for a maximum expression, similar to VEC_COND_EXPR but specifically for finding the maximum of two values.
Filed Under: optimizationvectorizationSIMDpattern matching