RISC-V: Fix register overlap for widening float reduction.
RISC-V widening float reduction instructions now correctly constrain register usage to prevent overlap.
This commit addresses a register overlap issue in RISC-V widening floating-point reduction instructions (vfwredosum.vs and vfwredusum.vs). The vs1 operand is read with a wider element width than vs2, and the RISC-V vector specification reserves encodings where one register supplies operands with different widths. The change enforces a Wn3 constraint on the vs1 operand to ensure it does not fall within the vs2 register group, preventing invalid instruction encodings.
In Details
This change modifies config/riscv/vector.md to apply a Wn3 constraint to the operand 4 (vs1) of widening float reduction instructions (vfwredosum.vs and vfwredusum.vs). This constraint prevents vs1 from being allocated in the same register group as vs2 when vs1's EEW (2x SEW) differs from vs2's SEW, aligning with section 5.2 of the RISC-V vector specification that prohibits such overlaps. This fixes potential incorrect instruction generation.
- vfwredosum.vs / vfwredusum.vs
- RISC-V vector instructions for widening floating-point sum reductions. The '.vs' suffix indicates the destination and second source register are the same. These operations involve differing element widths for source operands.
- SEW (Standard Element Width)
- The base element width for vector operations in RISC-V, which can be 8, 16, 32, or 64 bits.
- EEW (Extended Element Width)
- The element width used for operations that require a wider data path than the SEW, such as widening reductions in RISC-V.
- Wn3 constraint
- A constraint in GCC's machine description that restricts an operand to a specific register class or group, in this case, related to vector register widths.
- Register Group
- In the RISC-V vector extension, a set of consecutive vector registers that are treated as a unit for certain operations or constraints.