GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
risc-v

RISC-V: Model per-LMUL vector permute cost for better vectorization

Vector cost model now accounts for LMUL when estimating permute instruction costs, improving RISC-V vectorization.

The RISC-V vector cost model now differentiates the cost of permute instructions based on the LMUL (vector length multiplier). Previously, a single permute_cost was used, but this commit changes it to an array indexed by LMUL (1, 2, 4, 8). This allows for more accurate cost estimation, particularly modeling non-linear scaling, and defaults to quadratic scaling for generic cores. This change has caused regressions in tests where generic segment costs were previously too cheap, and specific instructions like bswap16 were miscosted.

In Details

The common_vector_cost structure in GCC's RISC-V backend now uses permute_cost[LMUL] instead of a scalar to model the non-linear performance scaling of vector permute operations with different LMUL factors. This change is applied in costs::adjust_stmt_cost for vec_perm and in riscv.cc for various vector cost functions. Regressions were observed in slp tests preferring vlseg8 and bswap16 tests due to the updated cost model.

For Context
LMUL
In RISC-V vector extensions, LMUL (or 'vector length multiplier') specifies the ratio of the vector register length to the native architecture's vector length. Higher LMUL values effectively create wider virtual vector registers.
vector permute
A vector instruction that rearranges elements within or between vector registers. Examples include vec_perm, gather, scatter.
vectorization
The process by which a compiler automatically transforms a scalar loop into a vector (SIMD) loop, executing the same operation on multiple data elements simultaneously.
RISC-V
An open-standard instruction set architecture (ISA) based on Reduced Instruction Set Computing principles. It is modular and extensible, with specific extensions for vector processing (RVV).
cost model
A component within a compiler's optimization passes that estimates the execution cost (e.g., cycles, latency) of different machine instructions or code sequences to guide optimization decisions.
Filed Under: RISC-Vvectorizationoptimizationcost model