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

RISC-V: Fix reg overlap for vs1 of vwsub[u].wv

RISC-V vwsub[u].wv instruction corrected to prevent vs1 register overlap with vs2.

This commit addresses a register overlap issue in the RISC-V vwsub[u].wv instruction. The instruction’s specification requires that vs1 (with EEW = SEW) must not fall within the register group of vs2 (which uses EEW = 2 * SEW). This commit enforces this rule by applying the Wn4 constraint to the vs2 operand, similar to how it’s handled for vfwsub.wv, thus preventing incorrect assembly when vs1 is allocated from the vs2 register group.

In Details

RISC-V vector instruction vwsub[u].wv corrected for operand register aliasing. The commit applies the Wn4 constraint to operand 3 (vs2) to enforce that it does not overlap with operand 2 (vs1), adhering to spec section 5.2 which disallows source operands with different EEWs from occupying the same register group. This mirrors the fix applied to vfwsub.wv.

For Context
vwsub.wv
A RISC-V vector instruction for wide subtract with a scalar value in the second source register. It performs element-wise subtraction, widening the elements of the first source vector by the second source register's elements.
vwsubu.wv
A RISC-V unsigned vector instruction for wide subtract with a scalar value in the second source register. It performs element-wise unsigned subtraction, widening the elements of the first source vector by the second source register's elements.
vs1
The first source vector register in a RISC-V vector instruction. It holds one of the operands for the vector operation.
vs2
The second source vector register in a RISC-V vector instruction. It holds the other operand for the vector operation, often with a different element width (EEW) than the destination (vd) or vs1.
EEW
Element Extension Width. In RISC-V vector operations, EEW determines the width of elements being processed, which can be different from the SEW (Standard Element Width) for certain widening or narrowing operations.
SEW
Standard Element Width. The base width of elements in a vector register, typically 8, 16, 32, or 64 bits.
Wn4 constraint
A constraint in RISC-V vector instruction assembly that relates to the register group size. 'Wn4' likely refers to a constraint involving a group of 4 vector registers.
register overlap
A situation in instruction scheduling and register allocation where two or more registers are required to hold values simultaneously, but the hardware or instruction encoding imposes constraints that prevent certain overlaps, potentially leading to miscompiles or incorrect behavior.
Filed Under: risc-vvectorcompiler