AArch64 SVE constant vector generation optimized
Improved AArch64 SVE code generation for constant vectors, reducing overhead and matching loop vectorization efficiency.
This change optimizes the generation of constant SVE vectors on AArch64, particularly for cases with trailing zeros. It replaces inefficient sequence of predicate masks and conditional selects with direct loads or scalar constructions, bringing its efficiency closer to that of loop vectorization.
In Details
The aarch64_expand_sve_const_vector function was inefficiently generating constant SVE vectors, especially those with trailing zeros, by using predicate masks and SEL instructions. This commit introduces a new function that detects when the second element of patterns is always zero. If so, it generates a non-scalable vector from the first elements or directly uses a scalar constant if only one pattern exists. This optimizes cases like {1,2,1,2,1,2,0,0} which previously involved unnecessary operations, aligning performance with loop-generated code.
- SVE
- Scalable Vector Extension, an instruction set for ARM processors that provides vector processing capabilities with a vector length that can vary at runtime.
- SLP vectorizer
- Superword-Level Parallelism vectorizer. This is a compiler optimization pass that identifies and vectorizes sequences of identical scalar operations that are independent of each other and operate on consecutive memory locations.
- predicate mask
- In SIMD and vector architectures, a mask that controls which lanes of a vector operation are active or affected. Only the lanes corresponding to set bits in the mask are processed.
- lane
- An individual element within a vector register. For example, a 128-bit vector register holding 32-bit integers has four lanes.