Skip to content

Commit 2023a23

Browse files
authored
[RISCV] Move V0 to the end of register allocation order (#82967)
According to https://riscv-optimization-guide-riseproject-c94355ae3e6872252baa952524.gitlab.io/riscv-optimization-guide.html: > The v0 register defined by the RISC-V vector extension is special in > that it can be used both as a general purpose vector register and also > as a mask register. As a preference, use registers other than v0 for > non-mask values. Otherwise data will have to be moved out of v0 when a > mask is required in an operation. v0 may be used when all other > registers are in use, and using v0 would avoid spilling register state > to memory. And using V0 register may stall masking pipeline and stop chaining for some microarchitectures. So we should try to not use V0 and register groups contained it as much as possible. We achieve this via moving V0 to the end of RA order.
1 parent 8171f6d commit 2023a23

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+516
-520
lines changed

llvm/lib/Target/RISCV/RISCVRegisterInfo.td

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,19 +508,23 @@ defvar VM8VTs = [vint8m8_t, vint16m8_t, vint32m8_t, vint64m8_t,
508508
vfloat16m8_t, vbfloat16m8_t,
509509
vfloat32m8_t, vfloat64m8_t];
510510

511+
// We reverse the order of last 8 registers so that we don't needlessly prevent
512+
// allocation of higher lmul register groups while still putting v0 last in the
513+
// allocation order.
514+
511515
def VR : VReg<!listconcat(VM1VTs, VMaskVTs),
512516
(add (sequence "V%u", 8, 31),
513-
(sequence "V%u", 0, 7)), 1>;
517+
(sequence "V%u", 7, 0)), 1>;
514518

515519
def VRNoV0 : VReg<!listconcat(VM1VTs, VMaskVTs), (sub VR, V0), 1>;
516520

517521
def VRM2 : VReg<VM2VTs, (add (sequence "V%uM2", 8, 31, 2),
518-
(sequence "V%uM2", 0, 7, 2)), 2>;
522+
(sequence "V%uM2", 6, 0, 2)), 2>;
519523

520524
def VRM2NoV0 : VReg<VM2VTs, (sub VRM2, V0M2), 2>;
521525

522526
def VRM4 : VReg<VM4VTs, (add V8M4, V12M4, V16M4, V20M4,
523-
V24M4, V28M4, V0M4, V4M4), 4>;
527+
V24M4, V28M4, V4M4, V0M4), 4>;
524528

525529
def VRM4NoV0 : VReg<VM4VTs, (sub VRM4, V0M4), 4>;
526530

0 commit comments

Comments
 (0)