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

match.pd: Index BIT_FIELD_REF of VEC_PERM_EXPR inputs by their length

Fix vector permute and bitfield reference folding to use correct input element counts.

A pattern in match.pd for folding BIT_FIELD_REF applied to VEC_PERM_EXPR was incorrectly using the element count of the VEC_PERM_EXPR’s selector. This led to incorrect code generation when input vectors were wider or narrower than the result. The fix ensures the element count is derived from the actual inputs, preventing silent errors and GIMPLE verification failures. New test cases are added to verify the fix.

In Details

The pattern matching for BIT_FIELD_REF applied to VEC_PERM_EXPR in match.pd previously determined the element count from the sel operand of the VEC_PERM_EXPR. This was incorrect when the input vectors (a, b) had a different element width than the result specified by sel. The fix corrects this by using the element count of the input vectors, resolving issues where out-of-bounds indices led to silent incorrect code or GIMPLE verification failures, particularly after vector lowering and forward propagation.

For Context
BIT_FIELD_REF
A GCC Intermediate Representation (IR) node that accesses a bitfield within a larger value. It specifies an offset and a length for the bitfield.
VEC_PERM_EXPR
A GCC Intermediate Representation (IR) node representing a vector permute operation, which rearranges elements within or between vectors based on a selector.
GIMPLE
GCC's internal three-address code representation. It's a simpler, more structured form of the compiler's Abstract Syntax Tree (AST), used for many optimization passes.
vector lowering
The process of converting high-level vector operations into a sequence of more primitive vector instructions supported by the target architecture. This can sometimes introduce intermediate forms that require careful handling.
forward propagation
An optimization technique where a value computed at one point is propagated forward to subsequent uses, potentially allowing for further optimizations or elimination of redundant computations.
Filed Under: vectorizationcorrectnesspattern-matching