Skip to content

Commit 80d11cc

Browse files
committed
[llvm][RISCV] Handle fpround and fpextend for zvfbfa without zvfbfmin
Add codegen support for fpround and fpextend for zvfbfa.
1 parent d10af9d commit 80d11cc

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfoZvfbf.td

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,4 +668,38 @@ foreach vti = NoGroupBF16Vectors in {
668668
def : Pat<(vti.Scalar (extractelt (vti.Vector vti.RegClass:$rs2), 0)),
669669
(vfmv_f_s_inst vti.RegClass:$rs2, vti.Log2SEW)>;
670670
}
671+
672+
let Predicates = [HasStdExtZvfbfa] in {
673+
foreach fvtiToFWti = AllWidenableBF16ToFloatVectors in {
674+
defvar fvti = fvtiToFWti.Vti;
675+
defvar fwti = fvtiToFWti.Wti;
676+
def : Pat<(fwti.Vector (any_riscv_fpextend_vl
677+
(fvti.Vector fvti.RegClass:$rs1),
678+
(fvti.Mask VMV0:$vm),
679+
VLOpFrag)),
680+
(!cast<Instruction>("PseudoVFWCVT_F_F_ALT_V_"#fvti.LMul.MX#"_E"#fvti.SEW#"_MASK")
681+
(fwti.Vector (IMPLICIT_DEF)), fvti.RegClass:$rs1,
682+
(fvti.Mask VMV0:$vm),
683+
GPR:$vl, fvti.Log2SEW, TA_MA)>;
684+
685+
def : Pat<(fvti.Vector (any_riscv_fpround_vl
686+
(fwti.Vector fwti.RegClass:$rs1),
687+
(fwti.Mask VMV0:$vm), VLOpFrag)),
688+
(!cast<Instruction>("PseudoVFNCVT_F_F_ALT_W_"#fvti.LMul.MX#"_E"#fvti.SEW#"_MASK")
689+
(fvti.Vector (IMPLICIT_DEF)), fwti.RegClass:$rs1,
690+
(fwti.Mask VMV0:$vm),
691+
// Value to indicate no rounding mode change in
692+
// RISCVInsertReadWriteCSR
693+
FRM_DYN,
694+
GPR:$vl, fvti.Log2SEW, TA_MA)>;
695+
def : Pat<(fvti.Vector (fpround (fwti.Vector fwti.RegClass:$rs1))),
696+
(!cast<Instruction>("PseudoVFNCVT_F_F_ALT_W_"#fvti.LMul.MX#"_E"#fvti.SEW)
697+
(fvti.Vector (IMPLICIT_DEF)),
698+
fwti.RegClass:$rs1,
699+
// Value to indicate no rounding mode change in
700+
// RISCVInsertReadWriteCSR
701+
FRM_DYN,
702+
fvti.AVL, fvti.Log2SEW, TA_MA)>;
703+
}
704+
}
671705
} // Predicates = [HasStdExtZvfbfa]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: sed 's/iXLen/i32/g' %s | llc -mtriple=riscv32 -mattr=+v,+zvfh,+experimental-zvfbfa \
3+
; RUN: -verify-machineinstrs -target-abi=ilp32d | FileCheck %s
4+
; RUN: sed 's/iXLen/i64/g' %s | llc -mtriple=riscv64 -mattr=+v,+zvfh,+experimental-zvfbfa \
5+
; RUN: -verify-machineinstrs -target-abi=lp64d | FileCheck %s
6+
7+
define <vscale x 8 x bfloat> @intrinsic_vfadd_vv_nxv1bf16_nxv1bf16_nxv1bf16(<vscale x 8 x bfloat> %0, <vscale x 8 x bfloat> %1) nounwind {
8+
; CHECK-LABEL: intrinsic_vfadd_vv_nxv1bf16_nxv1bf16_nxv1bf16:
9+
; CHECK: # %bb.0: # %entry
10+
; CHECK-NEXT: vsetvli a0, zero, e16alt, m2, ta, ma
11+
; CHECK-NEXT: vfwcvt.f.f.v v12, v10
12+
; CHECK-NEXT: vfwcvt.f.f.v v16, v8
13+
; CHECK-NEXT: vsetvli zero, zero, e32, m4, ta, ma
14+
; CHECK-NEXT: vfadd.vv v12, v16, v12
15+
; CHECK-NEXT: vsetvli zero, zero, e16alt, m2, ta, ma
16+
; CHECK-NEXT: vfncvt.f.f.w v8, v12
17+
; CHECK-NEXT: ret
18+
entry:
19+
%a = fadd <vscale x 8 x bfloat> %0, %1
20+
21+
ret <vscale x 8 x bfloat> %a
22+
}

0 commit comments

Comments
 (0)