Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1583,7 +1583,10 @@ void RISCVInsertVSETVLI::emitVSETVLIs(MachineBasicBlock &MBB) {
if (!TII->isAddImmediate(*DeadMI, Reg))
continue;
LIS->RemoveMachineInstrFromMaps(*DeadMI);
Register AddReg = DeadMI->getOperand(1).getReg();
DeadMI->eraseFromParent();
if (AddReg.isVirtual())
LIS->shrinkToUses(&LIS->getInterval(AddReg));
}
}
}
Expand Down Expand Up @@ -1869,11 +1872,15 @@ void RISCVInsertVSETVLI::coalesceVSETVLIs(MachineBasicBlock &MBB) const {
// Loop over the dead AVL values, and delete them now. This has
// to be outside the above loop to avoid invalidating iterators.
for (auto *MI : ToDelete) {
assert(MI->getOpcode() == RISCV::ADDI);
Register AddReg = MI->getOperand(1).getReg();
if (LIS) {
LIS->removeInterval(MI->getOperand(0).getReg());
LIS->RemoveMachineInstrFromMaps(*MI);
}
MI->eraseFromParent();
if (LIS && AddReg.isVirtual())
LIS->shrinkToUses(&LIS->getInterval(AddReg));
}
}

Expand Down
16 changes: 16 additions & 0 deletions llvm/test/CodeGen/RISCV/rvv/vsetvli-insert.ll
Original file line number Diff line number Diff line change
Expand Up @@ -863,3 +863,19 @@ entry:
i64 2)
ret <vscale x 1 x double> %2
}

; The two vsetvlis will be coalesced so the add will be made dead and
; removed. Make sure we shrink the live interval of %x.
define void @non_li_addi(i64 %x, ptr %p) {
; CHECK-LABEL: non_li_addi:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: vsetivli zero, 1, e64, m1, ta, ma
; CHECK-NEXT: ret
entry:
%add = add i64 %x, 1
%0 = tail call i64 @llvm.riscv.vsetvli(i64 %add, i64 3, i64 0)
%1 = call <vscale x 8 x i8> @llvm.riscv.vle(<vscale x 8 x i8> poison, ptr %p, i64 %0)
%2 = tail call i64 @llvm.riscv.vsetvli(i64 1, i64 3, i64 0)
%3 = tail call { <vscale x 8 x i8>, i64 } @llvm.riscv.vleff(<vscale x 8 x i8> poison, ptr %p, i64 %2)
ret void
}
24 changes: 24 additions & 0 deletions llvm/test/CodeGen/RISCV/rvv/vsetvli-insert.mir
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@
ret void
}

define void @non_li_addi() {
ret void
}

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

declare <vscale x 1 x i64> @llvm.riscv.vle.nxv1i64.i64(<vscale x 1 x i64>, ptr nocapture, i64) #4
Expand Down Expand Up @@ -664,3 +668,23 @@ body: |
bb.2:
$x10 = COPY %vl
PseudoRET implicit killed $x10
...
---
# The two vsetvlis will be coalesced so the ADDI will be made dead and removed.
# Make sure we shrink the live interval of %0.
name: non_li_addi
tracksRegLiveness: true
body: |
bb.0:
liveins: $x10
; CHECK-LABEL: name: non_li_addi
; CHECK: liveins: $x10
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: dead [[COPY:%[0-9]+]]:gpr = COPY $x10
; CHECK-NEXT: dead [[PseudoVSETIVLI:%[0-9]+]]:gprnox0 = PseudoVSETIVLI 1, 216 /* e64, m1, ta, ma */, implicit-def $vl, implicit-def $vtype
; CHECK-NEXT: PseudoRET
%0:gpr = COPY $x10
%1:gprnox0 = ADDI %0, 1
%2:gprnox0 = PseudoVSETVLI %1, 216 /* e64, m1, ta, ma */, implicit-def $vl, implicit-def $vtype
%3:gprnox0 = PseudoVSETIVLI 1, 216 /* e64, m1, ta, ma */, implicit-def $vl, implicit-def $vtype
PseudoRET
Loading