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

match.pd: Use ssizetype masks for merged VEC_PERM_EXPR

Fixes incorrect indexing in merged VEC_PERM_EXPR operations by using ssizetype masks.

A bug in match.pd caused incorrect indexing when merging two VEC_PERM_EXPR operations. The issue arose because the new selector’s element type was derived from the outer permute’s mask, leading to truncation for large indices (256+ elements). This resulted in the merged permute accessing the wrong input data. The fix ensures that new constant permute masks are built with ssizetype elements, resolving the indexing truncation and correcting the behavior for large vectors.

In Details

This commit addresses an issue in match.pd where patterns merging two VEC_PERM_EXPR operations incorrectly determined the element type of the resulting selector mask. When the merged permute's indices exceeded the capacity of an 8-bit mask (e.g., for vectors with 256 or more byte elements), build_int_cst would truncate the index, causing the permute to access incorrect input elements. The fix modifies the three relevant patterns to construct the new mask using ssizetype elements, consistent with the vectorizer and forwprop's approach to constant permute masks, thereby preventing ind…

For Context
match.pd
A file in GCC containing pattern matching rules used to optimize the GENERIC intermediate representation.
VEC_PERM_EXPR
An expression representing a vector permute operation, which rearranges elements of one or more vectors based on a selector mask.
ssizetype
An integer type in GCC used for sizes and counts, typically equivalent to size_t.
vectorizer
A compiler optimization pass that transforms loops or sequences of operations to use vector (SIMD) instructions, processing multiple data elements simultaneously.
forwprop
Forward propagation, a compiler optimization technique that replaces variables with their constant values or expressions derived from their assignments.
GENERIC
The first compiler intermediate representation (IR) in GCC, representing code in a tree-like structure before further optimizations and target-specific lowering.
Filed Under: optimizationvectorizationpattern matching