Skip to content

Commit bd01c59

Browse files
committed
[RISCV] Shrink uses of coalesced vsetvlis
When we coalesce and delete a vsetvli, we should shrink the LiveInterval of its AVL register now that there is one less use. This fixes a -verify-machineinstrs assertion in an MIR test case I found while investigating llvm#97264 (comment). I couldn't recreate this at the LLVM IR level, seemingly because RISCVInsertVSETVLI will just avoid inserting extra vsetvlis that don't need coalesced.
1 parent 8ab19d2 commit bd01c59

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,6 +1727,10 @@ void RISCVInsertVSETVLI::coalesceVSETVLIs(MachineBasicBlock &MBB) const {
17271727
if (LIS)
17281728
LIS->RemoveMachineInstrFromMaps(*MI);
17291729
MI->eraseFromParent();
1730+
if (LIS)
1731+
for (MachineOperand &MO : MI->uses())
1732+
if (MO.isReg() && MO.getReg().isVirtual())
1733+
LIS->shrinkToUses(&LIS->getInterval(MO.getReg()));
17301734
}
17311735
}
17321736

llvm/test/CodeGen/RISCV/rvv/vsetvli-insert.mir

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@
9292
ret void
9393
}
9494

95+
define void @coalesce_shrink_removed_vsetvlis_uses() {
96+
ret void
97+
}
98+
9599
declare <vscale x 1 x i64> @llvm.riscv.vadd.nxv1i64.nxv1i64.i64(<vscale x 1 x i64>, <vscale x 1 x i64>, <vscale x 1 x i64>, i64) #1
96100

97101
declare <vscale x 1 x i64> @llvm.riscv.vle.nxv1i64.i64(<vscale x 1 x i64>, ptr nocapture, i64) #4
@@ -576,3 +580,25 @@ body: |
576580
$v0 = PseudoVADD_VV_M1 $noreg, $noreg, $noreg, 3, 6, 0
577581
PseudoRET
578582
...
583+
---
584+
name: coalesce_shrink_removed_vsetvlis_uses
585+
tracksRegLiveness: true
586+
body: |
587+
bb.0:
588+
liveins: $x10, $v8
589+
; CHECK-LABEL: name: coalesce_shrink_removed_vsetvlis_uses
590+
; CHECK: liveins: $x10, $v8
591+
; CHECK-NEXT: {{ $}}
592+
; CHECK-NEXT: %avl1:gprnox0 = ADDI $x0, 1
593+
; CHECK-NEXT: %avl2:gprnox0 = ADDI $x0, 2
594+
; CHECK-NEXT: dead $x0 = PseudoVSETVLI %avl2, 209 /* e32, m2, ta, ma */, implicit-def $vl, implicit-def $vtype
595+
; CHECK-NEXT: %x:gpr = COPY $x10
596+
; CHECK-NEXT: renamable $v8 = PseudoVMV_S_X undef renamable $v8, %x, 1, 5 /* e32 */, implicit $vl, implicit $vtype
597+
; CHECK-NEXT: PseudoRET implicit $v8
598+
%avl1:gprnox0 = ADDI $x0, 1
599+
dead $x0 = PseudoVSETVLI %avl1:gprnox0, 209, implicit-def dead $vl, implicit-def dead $vtype
600+
%avl2:gprnox0 = ADDI $x0, 2
601+
dead $x0 = PseudoVSETVLI %avl2:gprnox0, 209, implicit-def dead $vl, implicit-def dead $vtype
602+
%x:gpr = COPY $x10
603+
renamable $v8 = PseudoVMV_S_X undef renamable $v8, killed renamable %x, 1, 5
604+
PseudoRET implicit $v8

0 commit comments

Comments
 (0)