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

Fold masked vector multiply to widening even/odd multiply

Optimizes masked vector multiplies on x86 by using widening multiply instructions.

This commit optimizes masked vector multiplications where only the low halves of vector elements are used. It recognizes that (x & lowhalf_mask) * (y & lowhalf_mask) is equivalent to a widening even or odd multiply operation. On x86, this replaces slower emulation sequences with single pmuludq instructions, or AVX512DQ vpmuludq where available, improving performance.

In Details

For integer vectors, the expression (x & lowhalf_mask) * (y & lowhalf_mask) performs a multiplication on zero-extended low halves of vector elements. This commit adds a pattern in match.pd to recognize this as a VEC_WIDEN_MULT_EVEN_EXPR (or ODD_EXPR on big-endian) of x and y. This allows for simplification to native widening multiply instructions, such as pmuludq on x86, especially when AVX512DQ is enabled.

For Context
vector
A data type that holds multiple values of the same type, allowing for SIMD (Single Instruction, Multiple Data) operations that process all values simultaneously.
VEC_WIDEN_MULT_EVEN_EXPR
An intermediate representation construct in GCC that signifies a widening multiplication of the even-indexed lanes of vector elements. 'Widening' means the result has twice the bit-width of the operands.
VEC_WIDEN_MULT_ODD_EXPR
An intermediate representation construct in GCC that signifies a widening multiplication of the odd-indexed lanes of vector elements. 'Widening' means the result has twice the bit-width of the operands.
pmuludq
An x86 SSE instruction that performs a packed unsigned double quadword multiply, producing a 64-bit result from two 32-bit operands.
AVX512DQ
An extension to the AVX instruction set that provides 512-bit vector registers and advanced integer and floating-point operations, including double quadword multiplication.
Filed Under: vectorizationx86optimizationperformance