Merge VEC_PERMs whose combined inputs are only a and b
Optimizes chains of VEC_PERM_EXPR operations by merging them when inputs are limited to two sources.
This commit enhances the match.pd patterns to merge consecutive VEC_PERM_EXPR operations when their combined inputs are limited to two sources, a and b. This optimization is particularly effective for scenarios where vectors are built element by element, reducing a chain of eleven instructions to a single shufps on x86-64. The change also resolves a spurious “variable used uninitialized” warning by correctly folding the permutation expressions.
In Details
The match.pd patterns for vec_perm have been updated to better handle nested VEC_PERM_EXPR. When an outer VEC_PERM_EXPR uses one of the inner permute's inputs (e.g., c = VEC_PERM_EXPR <a, b, ...>; d = VEC_PERM_EXPR <a, c, ...>;), and d only depends on a and b, the pattern now merges these into a single VEC_PERM_EXPR <a, b, NEW_VCST>. This optimization is applied when the intermediate permute c has a single use and its elements can be sourced from a or b without requiring new mask logic beyond what the target can handle. This collapses complex element-wise assignments i…
- match.pd
- A file containing pattern definitions for the GCC matcher, used to recognize and optimize specific instruction sequences or expressions.
- VEC_PERM_EXPR
- An expression representing a vector permutation operation, which rearranges elements within or between vectors according to a specified mask.
- SIMD
- Single Instruction, Multiple Data. A type of parallel processing where a single instruction operates on multiple data points simultaneously, often implemented using vector registers.
- shufps
- A specific x86 SIMD instruction (Shuffle Packed Single-Precision) used to permute and interleave data elements within SSE registers.