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

RISC-V: Adjust VLS subreg handling for vector size flexibility

RISC-V VLS subregister handling improved for better vectorization flexibility.

This commit refines how subregisters are handled for Variable Length Scalar (VLS) vectors on RISC-V. Previously, changes in register mode natural sizes caused unnecessary spilling of subregisters, even when they were safe in a VLS context. The update modifies can_change_mode_class and riscv_regmode_natural_size to treat VLS vectors as unsplittable while still allowing safe lowpart subregs, preventing incorrect spills and improving vectorization.

In Details

This change affects RISC-V vector code generation. The interaction between regmode_natural_size and can_change_mode_class was causing suboptimal register allocation for VLS (Variable Length Scalar) vectors. Specifically, subregister accesses like (subreg:V4SI (reg:V8SI) 0) were being spilled due to an overly conservative check in can_change_mode_class that didn't account for the safety of lowpart subregs in VLS contexts. The fix ensures VLS vectors are treated as unsplittable units in riscv_regmode_natural_size but allows lowpart subregs via a more nuanced check in `riscv_can_change…

For Context
VLS
Variable Length Scalar, a type of vector processing where the vector size can vary. In RISC-V, this relates to the Vector Extension.
subregister
A portion of a larger register that can be accessed independently. For example, the lower 32 bits of a 64-bit register can be a subregister.
spill
When a value that is currently held in a register needs to be temporarily stored in memory because the register is required for another value or operation.
RISC-V Vector Extension
An extension to the RISC-V instruction set architecture that provides support for single instruction, multiple data (SIMD) operations on vectors.
Filed Under: risc-vvectorizationoptimizationregister allocation