Skip to content

Commit 7317a6e

Browse files
authored
[RISCV][MachineVerifier] Use RegUnit for register liveness checking (#115980)
For the RISC-V target, V14_V15 are not subregisters of v14m4, even though they share some registers. Currently, the MachineVerifier reports an error when checking register liveness for segment load/store operations. This patch adds additional register liveness checking, using RegUnit instead of subregisters, to prevent this error.
1 parent 2523439 commit 7317a6e

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

llvm/lib/CodeGen/MachineVerifier.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3033,7 +3033,11 @@ void MachineVerifier::checkLiveness(const MachineOperand *MO, unsigned MONum) {
30333033
if (!MOP.getReg().isPhysical())
30343034
continue;
30353035

3036-
if (llvm::is_contained(TRI->subregs(MOP.getReg()), Reg))
3036+
if (MOP.getReg() != Reg &&
3037+
all_of(TRI->regunits(Reg), [&](const MCRegUnit RegUnit) {
3038+
return llvm::is_contained(TRI->regunits(MOP.getReg()),
3039+
RegUnit);
3040+
}))
30373041
Bad = false;
30383042
}
30393043
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 5
2+
# RUN: llc -mtriple=riscv64 -mattr=+v -run-pass=none %s -o - | FileCheck %s
3+
4+
# During the MachineVerifier, it assumes that used registers have been defined
5+
# In this test case, while $v12_v13_v14_v15_v16 covers $v14_v15,
6+
# $v14_v15 is not a sub-register of $v14m2 even though they share the same register.
7+
# This corner case can be resolved by checking the register using RegUnit.
8+
9+
...
10+
---
11+
name: func
12+
tracksRegLiveness: true
13+
tracksDebugUserValues: true
14+
body: |
15+
bb.0:
16+
liveins: $v0, $v8, $v9, $v10, $v11
17+
18+
; CHECK-LABEL: name: func
19+
; CHECK: liveins: $v0, $v8, $v9, $v10, $v11
20+
; CHECK-NEXT: {{ $}}
21+
; CHECK-NEXT: renamable $v16m2 = PseudoVMV_V_I_M2 undef renamable $v16m2, 0, -1, 3 /* e8 */, 0 /* tu, mu */, implicit $vl, implicit $vtype
22+
; CHECK-NEXT: $v20m2 = VMV2R_V $v14m2, implicit $v12_v13_v14_v15_v16
23+
renamable $v16m2 = PseudoVMV_V_I_M2 undef renamable $v16m2, 0, -1, 3 /* e8 */, 0 /* tu, mu */, implicit $vl, implicit $vtype
24+
$v20m2 = VMV2R_V $v14m2, implicit $v12_v13_v14_v15_v16
25+
26+
...

0 commit comments

Comments
 (0)