RISC-V vectorizer uses dedicated gather/scatter costs
RISC-V vectorizer now correctly uses specific costs for gather/scatter loads and stores.
The RISC-V vectorizer previously treated gather and scatter vector operations as scalar loads and stores, leading to inaccurate cost estimations. This commit enables the use of dedicated gather_load_cost and scatter_store_cost by overriding the add_slp_cost function. It ensures that vector loads/stores with the VMAT_GATHER_SCATTER_IFN kind are correctly identified as vector gather/scatter operations, improving vectorization cost modeling.
In Details
This patch modifies RISC-V's vector cost model in riscv-vector-costs.cc. It overrides add_slp_cost to correctly map VMAT_GATHER_SCATTER_IFN scalar loads/stores to dedicated vector operations (vector_gather_load, vector_scatter_store) and adjusts their cost scaling by skipping LMUL scaling when the item count is per-element. It also updates per-element gather/scatter costs for generic RVV and xt_c9501, aligning the cost model with the actual hardware capabilities for these operations.
- vectorizer
- A compiler component that transforms scalar code into equivalent vector code, using special CPU instructions that operate on multiple data elements simultaneously.
- RISC-V
- An open-standard instruction set architecture (ISA) based on Reduced Instruction Set Computing principles.
- gather/scatter
- Vector operations that load data from (gather) or store data to (scatter) non-contiguous memory locations based on indices, enabling efficient handling of irregular data access patterns.
- cost model
- A component of the compiler that estimates the performance cost (e.g., cycles, latency) of different code sequences to guide optimization decisions.
- SLP (Superword Level Parallelism)
- A vectorization technique that identifies and groups independent scalar operations that can be executed in parallel on vector registers.
- LMUL
- In RISC-V vector extensions, LMUL (Legalization Multiply) is a factor that scales the number of elements processed by a vector instruction beyond the base vector length.