Skip to content

Commit 44d1221

Browse files
authored
[RISCV] Expand bf16 vector truncstores and extloads (#108235)
Previously they were legal by default, so the truncstore/extload test cases would get combined and crash during selection. These are set to expand for f16 so do the same for bf16.
1 parent 480f07f commit 44d1221

File tree

3 files changed

+144
-0
lines changed

3 files changed

+144
-0
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,7 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
11281128
continue;
11291129
SetCommonVFPActions(VT);
11301130
SetCommonVFPExtLoadTruncStoreActions(VT, F16VecVTs);
1131+
SetCommonVFPExtLoadTruncStoreActions(VT, BF16VecVTs);
11311132
}
11321133
}
11331134

@@ -1137,6 +1138,7 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
11371138
continue;
11381139
SetCommonVFPActions(VT);
11391140
SetCommonVFPExtLoadTruncStoreActions(VT, F16VecVTs);
1141+
SetCommonVFPExtLoadTruncStoreActions(VT, BF16VecVTs);
11401142
SetCommonVFPExtLoadTruncStoreActions(VT, F32VecVTs);
11411143
}
11421144
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc < %s -mtriple=riscv32 -mattr=+v,+zvfbfmin -verify-machineinstrs | FileCheck %s
3+
; RUN: llc < %s -mtriple=riscv64 -mattr=+v,+zvfbfmin -verify-machineinstrs | FileCheck %s
4+
5+
define <vscale x 1 x bfloat> @load_nxv1bf16(ptr %p) {
6+
; CHECK-LABEL: load_nxv1bf16:
7+
; CHECK: # %bb.0:
8+
; CHECK-NEXT: vsetvli a1, zero, e16, mf4, ta, ma
9+
; CHECK-NEXT: vle16.v v8, (a0)
10+
; CHECK-NEXT: ret
11+
%x = load <vscale x 1 x bfloat>, ptr %p
12+
ret <vscale x 1 x bfloat> %x
13+
}
14+
15+
define <vscale x 2 x bfloat> @load_nxv2bf16(ptr %p) {
16+
; CHECK-LABEL: load_nxv2bf16:
17+
; CHECK: # %bb.0:
18+
; CHECK-NEXT: vsetvli a1, zero, e16, mf2, ta, ma
19+
; CHECK-NEXT: vle16.v v8, (a0)
20+
; CHECK-NEXT: ret
21+
%x = load <vscale x 2 x bfloat>, ptr %p
22+
ret <vscale x 2 x bfloat> %x
23+
}
24+
25+
define <vscale x 4 x bfloat> @load_nxv4bf16(ptr %p) {
26+
; CHECK-LABEL: load_nxv4bf16:
27+
; CHECK: # %bb.0:
28+
; CHECK-NEXT: vl1re16.v v8, (a0)
29+
; CHECK-NEXT: ret
30+
%x = load <vscale x 4 x bfloat>, ptr %p
31+
ret <vscale x 4 x bfloat> %x
32+
}
33+
34+
define <vscale x 8 x bfloat> @load_nxv8bf16(ptr %p) {
35+
; CHECK-LABEL: load_nxv8bf16:
36+
; CHECK: # %bb.0:
37+
; CHECK-NEXT: vl2re16.v v8, (a0)
38+
; CHECK-NEXT: ret
39+
%x = load <vscale x 8 x bfloat>, ptr %p
40+
ret <vscale x 8 x bfloat> %x
41+
}
42+
43+
define <vscale x 16 x bfloat> @load_nxv16bf16(ptr %p) {
44+
; CHECK-LABEL: load_nxv16bf16:
45+
; CHECK: # %bb.0:
46+
; CHECK-NEXT: vl4re16.v v8, (a0)
47+
; CHECK-NEXT: ret
48+
%x = load <vscale x 16 x bfloat>, ptr %p
49+
ret <vscale x 16 x bfloat> %x
50+
}
51+
52+
define <vscale x 32 x bfloat> @load_nxv32bf16(ptr %p) {
53+
; CHECK-LABEL: load_nxv32bf16:
54+
; CHECK: # %bb.0:
55+
; CHECK-NEXT: vl8re16.v v8, (a0)
56+
; CHECK-NEXT: ret
57+
%x = load <vscale x 32 x bfloat>, ptr %p
58+
ret <vscale x 32 x bfloat> %x
59+
}
60+
61+
define <vscale x 4 x float> @extload(ptr %p) {
62+
; CHECK-LABEL: extload:
63+
; CHECK: # %bb.0:
64+
; CHECK-NEXT: vl1re16.v v10, (a0)
65+
; CHECK-NEXT: vsetvli a0, zero, e16, m1, ta, ma
66+
; CHECK-NEXT: vfwcvtbf16.f.f.v v8, v10
67+
; CHECK-NEXT: ret
68+
%x = load <vscale x 4 x bfloat>, ptr %p
69+
%y = fpext <vscale x 4 x bfloat> %x to <vscale x 4 x float>
70+
ret <vscale x 4 x float> %y
71+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc < %s -mtriple=riscv32 -mattr=+v,+zvfbfmin -verify-machineinstrs | FileCheck %s
3+
; RUN: llc < %s -mtriple=riscv64 -mattr=+v,+zvfbfmin -verify-machineinstrs | FileCheck %s
4+
5+
define void @store_nxv1bf16(<vscale x 1 x bfloat> %v, ptr %p) {
6+
; CHECK-LABEL: store_nxv1bf16:
7+
; CHECK: # %bb.0:
8+
; CHECK-NEXT: vsetvli a1, zero, e16, mf4, ta, ma
9+
; CHECK-NEXT: vse16.v v8, (a0)
10+
; CHECK-NEXT: ret
11+
store <vscale x 1 x bfloat> %v, ptr %p
12+
ret void
13+
}
14+
15+
define void @store_nxv2bf16(<vscale x 2 x bfloat> %v, ptr %p) {
16+
; CHECK-LABEL: store_nxv2bf16:
17+
; CHECK: # %bb.0:
18+
; CHECK-NEXT: vsetvli a1, zero, e16, mf2, ta, ma
19+
; CHECK-NEXT: vse16.v v8, (a0)
20+
; CHECK-NEXT: ret
21+
store <vscale x 2 x bfloat> %v, ptr %p
22+
ret void
23+
}
24+
25+
define void @store_nxv4bf16(<vscale x 4 x bfloat> %v, ptr %p) {
26+
; CHECK-LABEL: store_nxv4bf16:
27+
; CHECK: # %bb.0:
28+
; CHECK-NEXT: vs1r.v v8, (a0)
29+
; CHECK-NEXT: ret
30+
store <vscale x 4 x bfloat> %v, ptr %p
31+
ret void
32+
}
33+
34+
define void @store_nxv8bf16(<vscale x 8 x bfloat> %v, ptr %p) {
35+
; CHECK-LABEL: store_nxv8bf16:
36+
; CHECK: # %bb.0:
37+
; CHECK-NEXT: vs2r.v v8, (a0)
38+
; CHECK-NEXT: ret
39+
store <vscale x 8 x bfloat> %v, ptr %p
40+
ret void
41+
}
42+
43+
define void @store_nxv16bf16(<vscale x 16 x bfloat> %v, ptr %p) {
44+
; CHECK-LABEL: store_nxv16bf16:
45+
; CHECK: # %bb.0:
46+
; CHECK-NEXT: vs4r.v v8, (a0)
47+
; CHECK-NEXT: ret
48+
store <vscale x 16 x bfloat> %v, ptr %p
49+
ret void
50+
}
51+
52+
define void @store_nxv32bf32(<vscale x 32 x bfloat> %v, ptr %p) {
53+
; CHECK-LABEL: store_nxv32bf32:
54+
; CHECK: # %bb.0:
55+
; CHECK-NEXT: vs8r.v v8, (a0)
56+
; CHECK-NEXT: ret
57+
store <vscale x 32 x bfloat> %v, ptr %p
58+
ret void
59+
}
60+
61+
define void @truncstore(<vscale x 4 x float> %v, ptr %p) {
62+
; CHECK-LABEL: truncstore:
63+
; CHECK: # %bb.0:
64+
; CHECK-NEXT: vsetvli a1, zero, e16, m1, ta, ma
65+
; CHECK-NEXT: vfncvtbf16.f.f.w v10, v8
66+
; CHECK-NEXT: vs1r.v v10, (a0)
67+
; CHECK-NEXT: ret
68+
%w = fptrunc <vscale x 4 x float> %v to <vscale x 4 x bfloat>
69+
store <vscale x 4 x bfloat> %w, ptr %p
70+
ret void
71+
}

0 commit comments

Comments
 (0)