Skip to content

Commit a020199

Browse files
committed
[RISCV] Assert only valid AVLs in doLocalPostpass are X0 or virtual regs. NFC
In vxrm.mir we were running RISCVInsertVSETVLI on pseudos that already had vsetvlis inserted and their AVLs set to $noreg. (This happened to work since doLocalPostpass got rid of the extra vsetvli) This removes the vsetvlis from the test and enforces that the only valid AVLs we work with are either X0 or virtual registers (or $noreg before emitVSETVLIs), since we don't handle physical registers properly in doLocalPostpass.
1 parent 16b0be6 commit a020199

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ class VSETVLIInfo {
468468
bool isUnknown() const { return State == Unknown; }
469469

470470
void setAVLReg(Register Reg) {
471+
assert(Reg.isVirtual() || Reg == RISCV::X0 || Reg == RISCV::NoRegister);
471472
AVLReg = Reg;
472473
State = AVLIsReg;
473474
}
@@ -1514,12 +1515,9 @@ static bool canMutatePriorConfig(const MachineInstr &PrevMI,
15141515

15151516
// If the AVL is a register, we need to make sure MI's AVL dominates PrevMI.
15161517
// For now just check that PrevMI uses the same virtual register.
1517-
if (AVL.isReg() && AVL.getReg() != RISCV::X0) {
1518-
if (AVL.getReg().isPhysical())
1519-
return false;
1520-
if (!PrevAVL.isReg() || PrevAVL.getReg() != AVL.getReg())
1521-
return false;
1522-
}
1518+
if (AVL.isReg() && AVL.getReg() != RISCV::X0 &&
1519+
(!PrevAVL.isReg() || PrevAVL.getReg() != AVL.getReg()))
1520+
return false;
15231521
}
15241522

15251523
assert(PrevMI.getOperand(2).isImm() && MI.getOperand(2).isImm());
@@ -1543,9 +1541,9 @@ void RISCVInsertVSETVLI::doLocalPostpass(MachineBasicBlock &MBB) {
15431541
continue;
15441542
}
15451543

1546-
Register VRegDef = MI.getOperand(0).getReg();
1547-
if (VRegDef != RISCV::X0 &&
1548-
!(VRegDef.isVirtual() && MRI->use_nodbg_empty(VRegDef)))
1544+
Register RegDef = MI.getOperand(0).getReg();
1545+
assert(RegDef == RISCV::X0 || RegDef.isVirtual());
1546+
if (RegDef != RISCV::X0 && !MRI->use_nodbg_empty(RegDef))
15491547
Used.demandVL();
15501548

15511549
if (NextMI) {

llvm/test/CodeGen/RISCV/rvv/vxrm.mir

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ body: |
1111
; MIR-LABEL: name: verify_vxrm
1212
; MIR: liveins: $v8, $v9, $x10
1313
; MIR-NEXT: {{ $}}
14-
; MIR-NEXT: dead $x0 = PseudoVSETVLI renamable $x10, 197 /* e8, mf8, ta, ma */, implicit-def $vl, implicit-def $vtype
14+
; MIR-NEXT: dead $x0 = PseudoVSETVLI killed renamable $x10, 197 /* e8, mf8, ta, ma */, implicit-def $vl, implicit-def $vtype
1515
; MIR-NEXT: WriteVXRMImm 0, implicit-def $vxrm
16-
; MIR-NEXT: renamable $v8 = PseudoVAADD_VV_MF8 undef $v8, renamable $v8, renamable $v9, 0, $noreg, 3 /* e8 */, 0 /* tu, mu */, implicit $vl, implicit $vtype, implicit $vxrm
16+
; MIR-NEXT: renamable $v8 = PseudoVAADD_VV_MF8 undef $v8, killed renamable $v8, killed renamable $v9, 0, $noreg, 3 /* e8 */, 0 /* tu, mu */, implicit $vl, implicit $vtype, implicit $vxrm
1717
; MIR-NEXT: PseudoRET implicit $v8
1818
; ASM-LABEL: verify_vxrm:
1919
; ASM: # %bb.0:
@@ -23,8 +23,8 @@ body: |
2323
; ASM-NEXT: ret
2424
%0:vr = COPY $v8
2525
%1:vr = COPY $v9
26-
dead $x0 = PseudoVSETVLI killed renamable $x10, 197 /* e8, mf8, ta, ma */, implicit-def $vl, implicit-def $vtype
26+
%2:gprnox0 = COPY $x10
2727
%pt:vr = IMPLICIT_DEF
28-
renamable $v8 = PseudoVAADD_VV_MF8 %pt, killed renamable $v8, killed renamable $v9, 0, $noreg, 3 /* e8 */, 0
28+
renamable $v8 = PseudoVAADD_VV_MF8 %pt, %0, %1, 0, %2, 3 /* e8 */, 0
2929
PseudoRET implicit $v8
3030
...

0 commit comments

Comments
 (0)