RISC-V: Scale RVV integer vector body costs by unit ratio.
RISC-V vector cost model now scales integer vector operations based on scalar/vector unit ratios for better throughput prediction.
The RISC-V vector cost model has been updated to incorporate a scalar-to-vector unit ratio for integer vector operations. This change helps the cost model more accurately reflect actual hardware throughput, preventing vectorization from appearing overly cheap. The update introduces new fields for scalar and vector units in riscv_tune_param and applies the scaling to most vector body costs, excluding reductions and gather/scatter operations.
In Details
The RISC-V backend's cost model in riscv-vector-costs.cc now scales integer vector operation costs by a scalar_units to vector_units ratio defined in riscv_tune_param. This addresses an issue where operations like int64 vadd at VLEN=128 (4 scalar units vs. 2 vector units) would receive identical costs, making vectorization seem disproportionately inexpensive. The scaling is applied in costs::scale_vector_cost and costs::add_stmt_cost, with a default ratio of 4:2 for generic-ooo. Reductions and gather/scatter are excluded.
- RVV
- RISC-V Vector extension. A set of instructions for performing operations on vectors of data.
- VLEN
- Vector Length. The number of elements that can be held in a vector register.
- cost model
- A component of the compiler that estimates the execution cost of different code sequences to guide optimization decisions.
- vectorization
- An optimization technique that transforms scalar code into vector code to process multiple data elements simultaneously.
- gather/scatter
- Memory access operations that retrieve or store data from/to non-contiguous memory locations based on indices.