Fixes for merging VEC_PERM_EXPR with differing vector lengths
A bug causing miscompilation or ICEs when merging vector permutations with different element counts, particularly affecting SVE intrinsics on aarch64, has been…
This commit addresses a bug in GCC’s middle-end where merging VEC_PERM_EXPR operations with inputs of different element counts led to incorrect GIMPLE, miscompilation, or Internal Compiler Errors (ICEs). The issue, present since GCC 14, particularly affected AArch64 SVE intrinsics when combining permutation operations. The fix ensures that each generated selector correctly uses the element count of its respective inputs, preventing invalid GIMPLE and silent code corruption.
In Details
Fixes the match.pd patterns and forwprop's identity check for VEC_PERM_EXPR merges when the permute or its inputs have differing element counts. Since GCC 14, VEC_PERM_EXPR can have inputs with different widths than its output. This leads to ICEs or miscompilation on targets like AArch64 with SVE intrinsics (e.g., svld1rq followed by svrev) when match.pd attempts to merge these operations, assuming uniform widths. The fix ensures selectors are built with the correct element counts, aligning with the input types and resulting vector lengths, resolving issues in both <a, b> into…
- VEC_PERM_EXPR
- An expression in GCC's intermediate representation (GIMPLE) representing a vector permutation operation. It rearranges elements within vectors based on a selector.
- GIMPLE
- GCC's Internal Representation (IR) used in the middle-end of the compiler. It's a three-address code form designed for optimization.
- ICE
- Internal Compiler Error. An unrecoverable error within the compiler itself, typically indicating a bug in the compiler's logic.
- SVE
- Scalable Vector Extension. An ARM architecture extension that provides vector processing capabilities with a vector length that can vary at runtime.
- aarch64
- The 64-bit ARM architecture. Compilers often have specific backends to generate optimal code for this architecture.
- intrinsics
- Special functions or instructions that provide direct access to hardware capabilities, often for performance-critical operations like vector processing.
- forwprop
- Forward propagation, a compiler optimization technique where values or expressions are substituted earlier in the code to enable further optimizations.
- match.pd
- A file containing patterns used by GCC's backend to match intermediate representation code to target-specific instructions.