Skip to content

Commit cc30fba

Browse files
authored
[Docs][RISCV] Update RISCVVectorExtension.rst to reflect RISCVVMV0Elimination. NFC (#133058)
Also correct the old name of RISCVFoldMasks to RISCVVectorPeephole
1 parent 16d1942 commit cc30fba

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

llvm/docs/RISCV/RISCVVectorExtension.rst

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -239,20 +239,13 @@ the ratio between SEW and LMUL needed in vtype. These instructions always operat
239239
Mask patterns
240240
-------------
241241

242-
For masked pseudos the mask operand is copied to the physical ``$v0`` register during instruction selection with a glued ``CopyToReg`` node:
243-
244-
.. code-block::
245-
246-
t23: ch,glue = CopyToReg t0, Register:nxv4i1 $v0, t6
247-
t25: nxv4i32 = PseudoVADD_VV_M2_MASK Register:nxv4i32 $noreg, t2, t4, Register:nxv4i1 $v0, TargetConstant:i64<8>, TargetConstant:i64<5>, TargetConstant:i64<1>, t23:1
248-
249242
The patterns in ``RISCVInstrInfoVVLPatterns.td`` only match masked pseudos to reduce the size of the match table, even if the node's mask is all ones and could be an unmasked pseudo.
250-
``RISCVFoldMasks::convertToUnmasked`` will detect if the mask is all ones and convert it into its unmasked form.
243+
``RISCVVectorPeephole::convertToUnmasked`` will detect if the mask is all ones and convert it into its unmasked form.
251244

252245
.. code-block::
253246
254-
$v0 = PseudoVMSET_M_B16 -1, 32
255-
%rd:vrm2 = PseudoVADD_VV_M2_MASK %passthru:vrm2(tied-def 0), %rs2:vrm2, %rs1:vrm2, $v0, %avl:gpr, sew:imm, policy:imm
247+
%mask:vmv0 = PseudoVMSET_M_B16 -1, 32
248+
%rd:vrm2 = PseudoVADD_VV_M2_MASK %passthru:vrm2(tied-def 0), %rs2:vrm2, %rs1:vrm2, %mask:vmv0, %avl:gpr, sew:imm, policy:imm
256249
257250
// gets optimized to:
258251
@@ -262,6 +255,28 @@ The patterns in ``RISCVInstrInfoVVLPatterns.td`` only match masked pseudos to re
262255

263256
Any ``vmset.m`` can be treated as an all ones mask since the tail elements past AVL are ``undef`` and can be replaced with ones.
264257

258+
VMV0 elimination
259+
=================
260+
261+
Because masked instructions must have the mask register in ``v0``, a specific register class ``vmv0`` is used that contains only one register, ``v0``.
262+
263+
However register coalescing may end up coleascing copies into ``vmv0``, resulting in instructions with multiple uses of ``vmv0`` that the register allocator can't allocate:
264+
265+
.. code-block::
266+
267+
%x:vrnov0 = PseudoVADD_VV_M1_MASK %0:vrnov0, %1:vr, %2:vmv0, %3:vmv0, ...
268+
269+
To avoid this, ``RISCVVMV0Elimination`` replaces any uses of ``vmv0`` with physical copies to ``v0`` before register coalescing and allocation:
270+
271+
.. code-block::
272+
273+
%x:vrnov0 = PseudoVADD_VV_M1_MASK %0:vrnov0, %1:vr, %2:vr, %3:vmv0, ...
274+
275+
// vmv0 gets eliminated to:
276+
277+
$v0 = COPY %3:vr
278+
%x:vrnov0 = PseudoVADD_VV_M1_MASK %0:vrnov0, %1:vr, %2:vr, $v0, ...
279+
265280
.. _rvv_register_allocation:
266281

267282
Register allocation

0 commit comments

Comments
 (0)