Skip to content

Commit edbeae3

Browse files
committed
[RISCV] Explicitly bail if something modifies VL/VTYPE in doLocalPostpass
If an instruction between MI and NextMI uses VL or VTYPE we demand the respective fields so as to not clobber them at their uses. But we don't consider if something might modify VL or VTYPE, and will happily coalesce two vsetvlis when we need to preserve them. This fixes this by skipping to the next vsetvli. Demanding the fields isn't enough, as we need to preserve the VL and VTYPE values even if no fields are demanded. In practice this doesn't happen, presumably due to there not being any instructions that write to VL or VTYPE without reading them. But I noticed this whilst working on a separate patch and split it out.
1 parent 76ad289 commit edbeae3

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,6 +1538,9 @@ void RISCVInsertVSETVLI::doLocalPostpass(MachineBasicBlock &MBB) {
15381538

15391539
if (!isVectorConfigInstr(MI)) {
15401540
doUnion(Used, getDemanded(MI, MRI, ST));
1541+
if (MI.isCall() || MI.isInlineAsm() || MI.modifiesRegister(RISCV::VL) ||
1542+
MI.modifiesRegister(RISCV::VTYPE))
1543+
NextMI = nullptr;
15411544
continue;
15421545
}
15431546

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,9 +516,10 @@ body: |
516516
; CHECK-LABEL: name: postpass_modify_vl
517517
; CHECK: liveins: $x1
518518
; CHECK-NEXT: {{ $}}
519-
; CHECK-NEXT: $x0 = PseudoVSETIVLI 3, 216 /* e64, m1, ta, ma */, implicit-def $vl, implicit-def $vtype
519+
; CHECK-NEXT: dead $x0 = PseudoVSETIVLI 3, 216 /* e64, m1, ta, ma */, implicit-def $vl, implicit-def $vtype
520520
; CHECK-NEXT: [[COPY:%[0-9]+]]:gpr = COPY $vtype
521521
; CHECK-NEXT: $vl = COPY $x1
522+
; CHECK-NEXT: dead $x0 = PseudoVSETIVLI 3, 216 /* e64, m1, ta, ma */, implicit-def $vl, implicit-def $vtype
522523
; CHECK-NEXT: [[PseudoVADD_VV_M1_:%[0-9]+]]:vr = PseudoVADD_VV_M1 $noreg, $noreg, $noreg, 3, 6 /* e64 */, 0 /* tu, mu */, implicit $vl, implicit $vtype
523524
; CHECK-NEXT: PseudoRET
524525
dead $x0 = PseudoVSETIVLI 3, 216, implicit-def $vl, implicit-def $vtype

0 commit comments

Comments
 (0)