match.pd: Eliminate dead operand in vector permute and insert patterns
Optimizes vector permute and insert operations on AArch64 by avoiding unnecessary zero-vector materialization.
This commit optimizes vector permute and insert operations, particularly for AArch64, by eliminating a dead operand. When a vector is shifted and a new element is inserted, the previous GCC code generated an unnecessary zero vector. The new match.pd pattern detects when the permute’s result only depends on one source operand and replaces the unused operand with that source, avoiding the creation of a temporary zero vector and producing more efficient machine code.
In Details
This change affects gcc/match.pd by introducing a new pattern for vector VEC_PERM_EXPR followed by BIT_INSERT_EXPR. It targets cases where the VEC_PERM_EXPR's result is effectively a permutation of a single input vector, often used to create space for an insertion. The new pattern detects when the second operand of VEC_PERM_EXPR (the permutation mask) is effectively unused, and if the permutation is still valid, it replaces the unused input vector operand with itself. This specifically avoids materializing placeholder zero vectors for the permute operation on targets like AArch64, l…
- VEC_PERM_EXPR
- A GIMPLE expression representing a vector permutation. It rearranges elements within a vector or combines elements from multiple vectors according to a specified mask.
- BIT_INSERT_EXPR
- A GIMPLE expression that inserts bits from a source into a destination vector at a specified position. This is often used for manipulating individual elements or sub-elements within vectors.
- match.pd
- A file containing pattern matching definitions used by GCC's internal representation (RTL) to optimize code. These patterns describe common instruction sequences and allow the compiler to replace them with more efficient ones.
- AArch64
- The 64-bit ARM architecture, widely used in mobile devices and increasingly in servers and desktops. GCC supports code generation for this architecture.
- GIMPLE
- GCC's internal representation (IR) used between the front-end and the RTL optimizer. It's a three-address code form designed for easier optimization analysis.