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

Fold same-width signed vector averages when overflow is undefined

Vector averaging pattern matching now handles signed types with undefined overflow.

The pattern matcher for vector averages now folds signed vector additions followed by a right shift into average operations. This applies when the sum does not overflow, which is guaranteed for types with undefined overflow behavior. This optimization can replace multiple instructions with a single rounding halving add, improving performance in vectorized code like DCT butterflies.

In Details

The match.pd pattern vect_recog_average_pattern previously only handled the narrowing form of vector averages. This change extends the folding of (x + y) >> 1 to IFN_AVG_FLOOR(x, y) and ((x + y) + 1) >> 1 to IFN_AVG_CEIL(x, y) for signed types where overflow is undefined. This allows for more efficient vectorization by recognizing patterns that can be mapped to specialized instructions like AArch64's srhadd.

Filed Under: vectorizationoptimizationperformance