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

match.pd: Extend MIN/MAX narrowing through vector casts.

Allows MIN/MAX operations on wide vector types to be narrowed through a cast, simplifying code generation.

This change extends the MIN/MAX narrowing optimization in match.pd to handle vector types. It enables folding comparisons on wide vector types, like v2di, directly into MIN/MAX operations on narrower vector types, like v2si, after a __builtin_convertvector cast. This optimization requires that the wide vector MIN or MAX operation has only one use to avoid introducing redundant operations, significantly simplifying code for operations involving type conversions and MIN/MAX.

In Details

This commit modifies the match.pd rules for scalar minmax folding to accept vector types. The rule (type) minmax ((wide_type) a, (wide_type) b) is now applicable when a and b are vectors. This works because the extension operation (__builtin_convertvector to a wider type) is monotone and commutes with comparison, and the subsequent truncation is exact. The key condition is that the narrow operation (e.g., v2si MIN/MAX) must be supported by the target, otherwise, the optimization would prevent scalarization of a single wide instruction. It also adds a constraint that the wide vec…

For Context
match.pd
A file within GCC that defines pattern matching rules for the tree-SSA intermediate representation. These rules are used by optimization passes to simplify and transform code.
MIN/MAX narrowing
An optimization that simplifies comparisons and selections involving wider integer types cast down to narrower types. For example, comparing two 64-bit integers and then casting the result to 32-bit can sometimes be simplified.
vector types
Data types that represent collections of elements, processed in parallel by SIMD instructions. Examples include int32x4_t (four 32-bit integers) or v2si (two single-precision integers).
__builtin_convertvector
A GCC intrinsic function used for explicit conversion between vector types, often involving widening or narrowing element sizes.
tree-SSA
GCC's intermediate representation (IR) that combines features of abstract syntax trees (AST) and Static Single Assignment (SSA) form, used for performing optimizations.
Filed Under: optimizationvectorizationarm