Skip to content

Commit bd748b3

Browse files
authored
[RISCV] Add implicit operand {VL, VTYPE} in RISCVInsertVSETVLI when u… (#130733)
…sing inline assembly. Fixing [#128636](#128636). This patch has RISCVInsertVSETVLI to add implicit use operand to inline assembly, this approach is suggested by @preames and the implementation I referenced is from @topperc . The purpose of adding vl, vtype implicit operand is to prevent Post-RA scheduler moving vsetvl across inline assembly.
1 parent 6345b00 commit bd748b3

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,6 +1531,13 @@ void RISCVInsertVSETVLI::emitVSETVLIs(MachineBasicBlock &MBB) {
15311531
/*isImp*/ true));
15321532
}
15331533

1534+
if (MI.isInlineAsm()) {
1535+
MI.addOperand(MachineOperand::CreateReg(RISCV::VL, /*isDef*/ true,
1536+
/*isImp*/ true));
1537+
MI.addOperand(MachineOperand::CreateReg(RISCV::VTYPE, /*isDef*/ true,
1538+
/*isImp*/ true));
1539+
}
1540+
15341541
if (MI.isCall() || MI.isInlineAsm() ||
15351542
MI.modifiesRegister(RISCV::VL, /*TRI=*/nullptr) ||
15361543
MI.modifiesRegister(RISCV::VTYPE, /*TRI=*/nullptr))
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc -mtriple=riscv64 -mcpu=sifive-x280 -verify-machineinstrs < %s | FileCheck %s
3+
4+
define void @foo(<vscale x 8 x half> %0) {
5+
; CHECK-LABEL: foo:
6+
; CHECK: # %bb.0: # %entry
7+
; CHECK-NEXT: vsetvli a0, zero, e32, m1, ta, ma
8+
; CHECK-NEXT: vmv.v.i v10, 0
9+
; CHECK-NEXT: lui a0, 1
10+
; CHECK-NEXT: addiw a0, a0, -1096
11+
; CHECK-NEXT: vmv.v.i v11, 0
12+
; CHECK-NEXT: vsetvli zero, a0, e8, m1, ta, ma
13+
; CHECK-NEXT: #APP
14+
; CHECK-NEXT: vfmadd.vv v11, v10, v10
15+
; CHECK-NEXT: #NO_APP
16+
; CHECK-NEXT: #APP
17+
; CHECK-NEXT: vfmadd.vv v11, v10, v10
18+
; CHECK-NEXT: #NO_APP
19+
; CHECK-NEXT: vsetvli zero, a0, e16, m2, ta, ma
20+
; CHECK-NEXT: vse16.v v8, (zero)
21+
; CHECK-NEXT: ret
22+
entry:
23+
%2 = tail call i64 @llvm.riscv.vsetvli.i64(i64 3000, i64 0, i64 0)
24+
%3 = tail call <vscale x 2 x float> asm sideeffect "vfmadd.vv $0, $1, $2", "=^vr,^vr,^vr,0"(<vscale x 2 x float> zeroinitializer, <vscale x 2 x float> zeroinitializer, <vscale x 2 x float> zeroinitializer)
25+
%4 = tail call <vscale x 2 x float> asm sideeffect "vfmadd.vv $0, $1, $2", "=^vr,^vr,^vr,0"(<vscale x 2 x float> zeroinitializer, <vscale x 2 x float> zeroinitializer, <vscale x 2 x float> %3)
26+
tail call void @llvm.riscv.vse.nxv8f16.i64(<vscale x 8 x half> %0, ptr null, i64 %2)
27+
ret void
28+
}

0 commit comments

Comments
 (0)