1 ; RUN: llc < %s -march=nvptx64 -mcpu=sm_80 -mattr=+ptx71 | FileCheck --check-prefixes=CHECK,SM80 %s
2 ; RUN: llc < %s -march=nvptx64 -mcpu=sm_90 -mattr=+ptx78 | FileCheck --check-prefixes=CHECK,SM90 %s
3 ; RUN: %if ptxas-11.8 %{ llc < %s -march=nvptx64 -mcpu=sm_80 -mattr=+ptx71 | %ptxas-verify -arch=sm_80 %}
4 ; RUN: %if ptxas-11.8 %{ llc < %s -march=nvptx64 -mcpu=sm_90 -mattr=+ptx78 | %ptxas-verify -arch=sm_90 %}
6 target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
8 ; CHECK-LABEL: test_ret_const(
9 ; CHECK: mov.b32 [[T:%r[0-9+]]], 1073758080;
10 ; CHECK: st.param.b32 [func_retval0+0], [[T]];
13 define <2 x bfloat> @test_ret_const() #0 {
14 ret <2 x bfloat> <bfloat 1.0, bfloat 2.0>
17 ; Check that we can lower fadd with immediate arguments.
18 ; CHECK-LABEL: test_fadd_imm_0(
19 ; CHECK-DAG: ld.param.b32 [[A:%r[0-9]+]], [test_fadd_imm_0_param_0];
21 ; SM90-DAG: mov.b32 [[I:%r[0-9+]]], 1073758080;
22 ; SM90-DAG: add.rn.bf16x2 [[R:%r[0-9]+]], [[A]], [[I]];
24 ; SM80-DAG: mov.b32 {[[A0:%rs[0-9]+]], [[A1:%rs[0-9]+]]}, [[A]]
25 ; SM80-DAG: cvt.f32.bf16 [[FA0:%f[0-9]+]], [[A0]]
26 ; SM80-DAG: cvt.f32.bf16 [[FA1:%f[0-9]+]], [[A1]]
27 ; SM80-DAG: add.rn.f32 [[FR0:%f[0-9]+]], [[FA0]], 0f3F800000;
28 ; SM80-DAG: add.rn.f32 [[FR1:%f[0-9]+]], [[FA1]], 0f40000000;
29 ; SM80-DAG: cvt.rn.bf16.f32 [[R0:%rs[0-9]+]], [[FR0]]
30 ; SM80-DAG: cvt.rn.bf16.f32 [[R1:%rs[0-9]+]], [[FR1]]
31 ; SM80-DAG: mov.b32 [[R:%r[0-9]+]], {[[R0]], [[R1]]}
33 ; CHECK-NEXT: st.param.b32 [func_retval0+0], [[R]];
36 define <2 x bfloat> @test_fadd_imm_0(<2 x bfloat> %a) #0 {
37 %r = fadd <2 x bfloat> <bfloat 1.0, bfloat 2.0>, %a
41 ; CHECK-LABEL: test_fadd_imm_1(
42 ; CHECK: ld.param.b16 [[A:%rs[0-9]+]], [test_fadd_imm_1_param_0];
43 ; SM90: mov.b16 [[B:%rs[0-9]+]], 0x3F80;
44 ; SM90: add.rn.bf16 [[R:%rs[0-9]+]], [[A]], [[B]];
46 ; SM80-DAG: cvt.f32.bf16 [[FA:%f[0-9]+]], [[A]];
47 ; SM80: add.rn.f32 [[FR:%f[0-9]+]], [[FA]], 0f3F800000;
48 ; SM80: cvt.rn.bf16.f32 [[R:%rs[0-9]+]], [[FR]];
50 ; CHECK: st.param.b16 [func_retval0+0], [[R]];
53 define bfloat @test_fadd_imm_1(bfloat %a) #0 {
54 %r = fadd bfloat %a, 1.0
58 ; CHECK-LABEL: test_fsubx2(
59 ; CHECK-DAG: ld.param.b32 [[A:%r[0-9]+]], [test_fsubx2_param_0];
60 ; CHECK-DAG: ld.param.b32 [[B:%r[0-9]+]], [test_fsubx2_param_1];
61 ; SM90: sub.rn.bf16x2 [[R:%r[0-9]+]], [[A]], [[B]];
63 ; SM80-DAG: mov.b32 {[[A0:%rs[0-9]+]], [[A1:%rs[0-9]+]]}, [[A]];
64 ; SM80-DAG: mov.b32 {[[B0:%rs[0-9]+]], [[B1:%rs[0-9]+]]}, [[B]];
65 ; SM80-DAG: cvt.f32.bf16 [[FA1:%f[0-9]+]], [[A1]];
66 ; SM80-DAG: cvt.f32.bf16 [[FA0:%f[0-9]+]], [[A0]];
67 ; SM80-DAG: cvt.f32.bf16 [[FB0:%f[0-9]+]], [[B0]];
68 ; SM80-DAG: cvt.f32.bf16 [[FB1:%f[0-9]+]], [[B1]];
69 ; SM80-DAG: sub.rn.f32 [[FR0:%f[0-9]+]], [[FA0]], [[FB0]];
70 ; SM80-DAG: sub.rn.f32 [[FR1:%f[0-9]+]], [[FA1]], [[FB1]];
71 ; SM80-DAG: cvt.rn.bf16.f32 [[R0:%rs[0-9]+]], [[FR0]];
72 ; SM80-DAG: cvt.rn.bf16.f32 [[R1:%rs[0-9]+]], [[FR1]];
73 ; SM80: mov.b32 [[R:%r[0-9]+]], {[[R0]], [[R1]]};
75 ; CHECK: st.param.b32 [func_retval0+0], [[R]];
78 define <2 x bfloat> @test_fsubx2(<2 x bfloat> %a, <2 x bfloat> %b) #0 {
79 %r = fsub <2 x bfloat> %a, %b
83 ; CHECK-LABEL: test_fmulx2(
84 ; CHECK-DAG: ld.param.b32 [[A:%r[0-9]+]], [test_fmulx2_param_0];
85 ; CHECK-DAG: ld.param.b32 [[B:%r[0-9]+]], [test_fmulx2_param_1];
86 ; SM90: mul.rn.bf16x2 [[R:%r[0-9]+]], [[A]], [[B]];
88 ; SM80-DAG: mov.b32 {[[A0:%rs[0-9]+]], [[A1:%rs[0-9]+]]}, [[A]];
89 ; SM80-DAG: mov.b32 {[[B0:%rs[0-9]+]], [[B1:%rs[0-9]+]]}, [[B]];
90 ; SM80-DAG: cvt.f32.bf16 [[FA1:%f[0-9]+]], [[A1]];
91 ; SM80-DAG: cvt.f32.bf16 [[FA0:%f[0-9]+]], [[A0]];
92 ; SM80-DAG: cvt.f32.bf16 [[FB0:%f[0-9]+]], [[B0]];
93 ; SM80-DAG: cvt.f32.bf16 [[FB1:%f[0-9]+]], [[B1]];
94 ; SM80-DAG: mul.rn.f32 [[FR0:%f[0-9]+]], [[FA0]], [[FB0]];
95 ; SM80-DAG: mul.rn.f32 [[FR1:%f[0-9]+]], [[FA1]], [[FB1]];
96 ; SM80-DAG: cvt.rn.bf16.f32 [[R0:%rs[0-9]+]], [[FR0]];
97 ; SM80-DAG: cvt.rn.bf16.f32 [[R1:%rs[0-9]+]], [[FR1]];
98 ; SM80: mov.b32 [[R:%r[0-9]+]], {[[R0]], [[R1]]};
100 ; CHECK: st.param.b32 [func_retval0+0], [[R]];
103 define <2 x bfloat> @test_fmulx2(<2 x bfloat> %a, <2 x bfloat> %b) #0 {
104 %r = fmul <2 x bfloat> %a, %b
108 ; CHECK-LABEL: test_fdiv(
109 ; CHECK-DAG: ld.param.b32 [[A:%r[0-9]+]], [test_fdiv_param_0];
110 ; CHECK-DAG: ld.param.b32 [[B:%r[0-9]+]], [test_fdiv_param_1];
111 ; CHECK-DAG: mov.b32 {[[A0:%rs[0-9]+]], [[A1:%rs[0-9]+]]}, [[A]]
112 ; CHECK-DAG: mov.b32 {[[B0:%rs[0-9]+]], [[B1:%rs[0-9]+]]}, [[B]]
113 ; CHECK-DAG: cvt.f32.bf16 [[FA0:%f[0-9]+]], [[A0]];
114 ; CHECK-DAG: cvt.f32.bf16 [[FA1:%f[0-9]+]], [[A1]];
115 ; CHECK-DAG: cvt.f32.bf16 [[FB0:%f[0-9]+]], [[B0]];
116 ; CHECK-DAG: cvt.f32.bf16 [[FB1:%f[0-9]+]], [[B1]];
117 ; CHECK-DAG: div.rn.f32 [[FR0:%f[0-9]+]], [[FA0]], [[FB0]];
118 ; CHECK-DAG: div.rn.f32 [[FR1:%f[0-9]+]], [[FA1]], [[FB1]];
119 ; CHECK-DAG: cvt.rn.bf16.f32 [[R0:%rs[0-9]+]], [[FR0]];
120 ; CHECK-DAG: cvt.rn.bf16.f32 [[R1:%rs[0-9]+]], [[FR1]];
121 ; CHECK-NEXT: mov.b32 [[R:%r[0-9]+]], {[[R0]], [[R1]]}
122 ; CHECK-NEXT: st.param.b32 [func_retval0+0], [[R]];
125 define <2 x bfloat> @test_fdiv(<2 x bfloat> %a, <2 x bfloat> %b) #0 {
126 %r = fdiv <2 x bfloat> %a, %b
130 ; CHECK-LABEL: test_fneg(
131 ; CHECK-DAG: ld.param.u32 [[A:%r[0-9]+]], [test_fneg_param_0];
133 ; CHECK-DAG: xor.b32 [[IHH0:%r[0-9]+]], [[A]], -2147450880;
134 ; CHECK-NEXT: st.param.b32 [func_retval0+0], [[IHH0]];
136 define <2 x bfloat> @test_fneg(<2 x bfloat> %a) #0 {
137 %r = fneg <2 x bfloat> %a
141 ; CHECK-LABEL: .func test_ldst_v2bf16(
142 ; CHECK-DAG: ld.param.u64 %[[A:rd[0-9]+]], [test_ldst_v2bf16_param_0];
143 ; CHECK-DAG: ld.param.u64 %[[B:rd[0-9]+]], [test_ldst_v2bf16_param_1];
144 ; CHECK-DAG: ld.b32 [[E:%r[0-9]+]], [%[[A]]]
145 ; CHECK-DAG: st.b32 [%[[B]]], [[E]];
147 define void @test_ldst_v2bf16(ptr %a, ptr %b) {
148 %t1 = load <2 x bfloat>, ptr %a
149 store <2 x bfloat> %t1, ptr %b, align 16
153 ; CHECK-LABEL: .func test_ldst_v3bf16(
154 ; CHECK-DAG: ld.param.u64 %[[A:rd[0-9]+]], [test_ldst_v3bf16_param_0];
155 ; CHECK-DAG: ld.param.u64 %[[B:rd[0-9]+]], [test_ldst_v3bf16_param_1];
156 ; -- v3 is inconvenient to capture as it's lowered as ld.b64 + fair
157 ; number of bitshifting instructions that may change at llvm's whim.
158 ; So we only verify that we only issue correct number of writes using
159 ; correct offset, but not the values we write.
161 ; CHECK-DAG: st.u32 [%[[B]]],
162 ; CHECK-DAG: st.b16 [%[[B]]+4],
164 define void @test_ldst_v3bf16(ptr %a, ptr %b) {
165 %t1 = load <3 x bfloat>, ptr %a
166 store <3 x bfloat> %t1, ptr %b, align 16
170 declare <2 x bfloat> @test_callee(<2 x bfloat> %a, <2 x bfloat> %b) #0
172 ; CHECK-LABEL: test_call(
173 ; CHECK-DAG: ld.param.b32 [[A:%r[0-9]+]], [test_call_param_0];
174 ; CHECK-DAG: ld.param.b32 [[B:%r[0-9]+]], [test_call_param_1];
176 ; CHECK-DAG: .param .align 4 .b8 param0[4];
177 ; CHECK-DAG: .param .align 4 .b8 param1[4];
178 ; CHECK-DAG: st.param.b32 [param0+0], [[A]];
179 ; CHECK-DAG: st.param.b32 [param1+0], [[B]];
180 ; CHECK-DAG: .param .align 4 .b8 retval0[4];
181 ; CHECK: call.uni (retval0),
182 ; CHECK-NEXT: test_callee,
184 ; CHECK-NEXT: ld.param.b32 [[R:%r[0-9]+]], [retval0+0];
186 ; CHECK-NEXT: st.param.b32 [func_retval0+0], [[R]];
189 define <2 x bfloat> @test_call(<2 x bfloat> %a, <2 x bfloat> %b) #0 {
190 %r = call <2 x bfloat> @test_callee(<2 x bfloat> %a, <2 x bfloat> %b)
194 ; CHECK-LABEL: test_select(
195 ; CHECK-DAG: ld.param.b32 [[A:%r[0-9]+]], [test_select_param_0];
196 ; CHECK-DAG: ld.param.b32 [[B:%r[0-9]+]], [test_select_param_1];
197 ; CHECK-DAG: ld.param.u8 [[C:%rs[0-9]+]], [test_select_param_2]
198 ; CHECK-DAG: setp.eq.b16 [[PRED:%p[0-9]+]], %rs{{.*}}, 1;
199 ; CHECK-NEXT: selp.b32 [[R:%r[0-9]+]], [[A]], [[B]], [[PRED]];
200 ; CHECK-NEXT: st.param.b32 [func_retval0+0], [[R]];
203 define <2 x bfloat> @test_select(<2 x bfloat> %a, <2 x bfloat> %b, i1 zeroext %c) #0 {
204 %r = select i1 %c, <2 x bfloat> %a, <2 x bfloat> %b
208 ; CHECK-LABEL: test_select_cc(
209 ; CHECK-DAG: ld.param.b32 [[A:%r[0-9]+]], [test_select_cc_param_0];
210 ; CHECK-DAG: ld.param.b32 [[B:%r[0-9]+]], [test_select_cc_param_1];
211 ; CHECK-DAG: ld.param.b32 [[C:%r[0-9]+]], [test_select_cc_param_2];
212 ; CHECK-DAG: ld.param.b32 [[D:%r[0-9]+]], [test_select_cc_param_3];
214 ; SM90: setp.neu.bf16x2 [[P0:%p[0-9]+]]|[[P1:%p[0-9]+]], [[C]], [[D]]
216 ; SM80-DAG: mov.b32 {[[C0:%rs[0-9]+]], [[C1:%rs[0-9]+]]}, [[C]]
217 ; SM80-DAG: mov.b32 {[[D0:%rs[0-9]+]], [[D1:%rs[0-9]+]]}, [[D]]
218 ; SM80-DAG: cvt.f32.bf16 [[DF0:%f[0-9]+]], [[D0]];
219 ; SM80-DAG: cvt.f32.bf16 [[CF0:%f[0-9]+]], [[C0]];
220 ; SM80-DAG: cvt.f32.bf16 [[DF1:%f[0-9]+]], [[D1]];
221 ; SM80-DAG: cvt.f32.bf16 [[CF1:%f[0-9]+]], [[C1]];
222 ; SM80-DAG: setp.neu.f32 [[P0:%p[0-9]+]], [[CF0]], [[DF0]]
223 ; SM80-DAG: setp.neu.f32 [[P1:%p[0-9]+]], [[CF1]], [[DF1]]
225 ; CHECK-DAG: mov.b32 {[[A0:%rs[0-9]+]], [[A1:%rs[0-9]+]]}, [[A]]
226 ; CHECK-DAG: mov.b32 {[[B0:%rs[0-9]+]], [[B1:%rs[0-9]+]]}, [[B]]
227 ; CHECK-DAG: selp.b16 [[R0:%rs[0-9]+]], [[A0]], [[B0]], [[P0]];
228 ; CHECK-DAG: selp.b16 [[R1:%rs[0-9]+]], [[A1]], [[B1]], [[P1]];
229 ; CHECK: mov.b32 [[R:%r[0-9]+]], {[[R0]], [[R1]]}
230 ; CHECK-NEXT: st.param.b32 [func_retval0+0], [[R]];
233 define <2 x bfloat> @test_select_cc(<2 x bfloat> %a, <2 x bfloat> %b, <2 x bfloat> %c, <2 x bfloat> %d) #0 {
234 %cc = fcmp une <2 x bfloat> %c, %d
235 %r = select <2 x i1> %cc, <2 x bfloat> %a, <2 x bfloat> %b
240 ; CHECK-LABEL: test_select_cc_f32_bf16(
241 ; CHECK-DAG: ld.param.v2.f32 {[[A0:%f[0-9]+]], [[A1:%f[0-9]+]]}, [test_select_cc_f32_bf16_param_0];
242 ; CHECK-DAG: ld.param.b32 [[C:%r[0-9]+]], [test_select_cc_f32_bf16_param_2];
243 ; CHECK-DAG: ld.param.b32 [[D:%r[0-9]+]], [test_select_cc_f32_bf16_param_3];
244 ; SM90: setp.neu.bf16x2 [[P0:%p[0-9]+]]|[[P1:%p[0-9]+]], [[C]], [[D]]
245 ; CHECK-DAG: ld.param.v2.f32 {[[B0:%f[0-9]+]], [[B1:%f[0-9]+]]}, [test_select_cc_f32_bf16_param_1];
247 ; SM80-DAG: mov.b32 {[[C0:%rs[0-9]+]], [[C1:%rs[0-9]+]]}, [[C]]
248 ; SM80-DAG: mov.b32 {[[D0:%rs[0-9]+]], [[D1:%rs[0-9]+]]}, [[D]]
249 ; SM80-DAG: cvt.f32.bf16 [[DF0:%f[0-9]+]], [[D0]];
250 ; SM80-DAG: cvt.f32.bf16 [[CF0:%f[0-9]+]], [[C0]];
251 ; SM80-DAG: cvt.f32.bf16 [[DF1:%f[0-9]+]], [[D1]];
252 ; SM80-DAG: cvt.f32.bf16 [[CF1:%f[0-9]+]], [[C1]];
253 ; SM80-DAG: setp.neu.f32 [[P0:%p[0-9]+]], [[CF0]], [[DF0]]
254 ; SM80-DAG: setp.neu.f32 [[P1:%p[0-9]+]], [[CF1]], [[DF1]]
256 ; CHECK-DAG: selp.f32 [[R0:%f[0-9]+]], [[A0]], [[B0]], [[P0]];
257 ; CHECK-DAG: selp.f32 [[R1:%f[0-9]+]], [[A1]], [[B1]], [[P1]];
258 ; CHECK-NEXT: st.param.v2.f32 [func_retval0+0], {[[R0]], [[R1]]};
260 define <2 x float> @test_select_cc_f32_bf16(<2 x float> %a, <2 x float> %b,
261 <2 x bfloat> %c, <2 x bfloat> %d) #0 {
262 %cc = fcmp une <2 x bfloat> %c, %d
263 %r = select <2 x i1> %cc, <2 x float> %a, <2 x float> %b
267 ; CHECK-LABEL: test_select_cc_bf16_f32(
268 ; CHECK-DAG: ld.param.b32 [[A:%r[0-9]+]], [test_select_cc_bf16_f32_param_0];
269 ; CHECK-DAG: ld.param.b32 [[B:%r[0-9]+]], [test_select_cc_bf16_f32_param_1];
270 ; CHECK-DAG: ld.param.v2.f32 {[[C0:%f[0-9]+]], [[C1:%f[0-9]+]]}, [test_select_cc_bf16_f32_param_2];
271 ; CHECK-DAG: ld.param.v2.f32 {[[D0:%f[0-9]+]], [[D1:%f[0-9]+]]}, [test_select_cc_bf16_f32_param_3];
272 ; CHECK-DAG: setp.neu.f32 [[P0:%p[0-9]+]], [[C0]], [[D0]]
273 ; CHECK-DAG: setp.neu.f32 [[P1:%p[0-9]+]], [[C1]], [[D1]]
274 ; CHECK-DAG: mov.b32 {[[A0:%rs[0-9]+]], [[A1:%rs[0-9]+]]}, [[A]]
275 ; CHECK-DAG: mov.b32 {[[B0:%rs[0-9]+]], [[B1:%rs[0-9]+]]}, [[B]]
276 ; CHECK-DAG: selp.b16 [[R0:%rs[0-9]+]], [[A0]], [[B0]], [[P0]];
277 ; CHECK-DAG: selp.b16 [[R1:%rs[0-9]+]], [[A1]], [[B1]], [[P1]];
278 ; CHECK: mov.b32 [[R:%r[0-9]+]], {[[R0]], [[R1]]}
279 ; CHECK-NEXT: st.param.b32 [func_retval0+0], [[R]];
281 define <2 x bfloat> @test_select_cc_bf16_f32(<2 x bfloat> %a, <2 x bfloat> %b,
282 <2 x float> %c, <2 x float> %d) #0 {
283 %cc = fcmp une <2 x float> %c, %d
284 %r = select <2 x i1> %cc, <2 x bfloat> %a, <2 x bfloat> %b
288 ; CHECK-LABEL: test_fptrunc_2xfloat(
289 ; CHECK: ld.param.v2.f32 {[[A0:%f[0-9]+]], [[A1:%f[0-9]+]]}, [test_fptrunc_2xfloat_param_0];
290 ; CHECK-DAG: cvt.rn.bf16.f32 [[R0:%rs[0-9]+]], [[A0]];
291 ; CHECK-DAG: cvt.rn.bf16.f32 [[R1:%rs[0-9]+]], [[A1]];
292 ; CHECK: mov.b32 [[R:%r[0-9]+]], {[[R0]], [[R1]]}
293 ; CHECK: st.param.b32 [func_retval0+0], [[R]];
295 define <2 x bfloat> @test_fptrunc_2xfloat(<2 x float> %a) #0 {
296 %r = fptrunc <2 x float> %a to <2 x bfloat>
300 ; CHECK-LABEL: test_fpext_2xfloat(
301 ; CHECK: ld.param.b32 [[A:%r[0-9]+]], [test_fpext_2xfloat_param_0];
302 ; CHECK: mov.b32 {[[A0:%rs[0-9]+]], [[A1:%rs[0-9]+]]}, [[A]]
303 ; CHECK-DAG: cvt.f32.bf16 [[R0:%f[0-9]+]], [[A0]];
304 ; CHECK-DAG: cvt.f32.bf16 [[R1:%f[0-9]+]], [[A1]];
305 ; CHECK-NEXT: st.param.v2.f32 [func_retval0+0], {[[R0]], [[R1]]};
307 define <2 x float> @test_fpext_2xfloat(<2 x bfloat> %a) #0 {
308 %r = fpext <2 x bfloat> %a to <2 x float>
312 ; CHECK-LABEL: test_bitcast_2xbf16_to_2xi16(
313 ; CHECK: ld.param.u32 [[A:%r[0-9]+]], [test_bitcast_2xbf16_to_2xi16_param_0];
314 ; CHECK: st.param.b32 [func_retval0+0], [[A]]
316 define <2 x i16> @test_bitcast_2xbf16_to_2xi16(<2 x bfloat> %a) #0 {
317 %r = bitcast <2 x bfloat> %a to <2 x i16>
322 ; CHECK-LABEL: test_bitcast_2xi16_to_2xbf16(
323 ; CHECK: ld.param.b32 [[R]], [test_bitcast_2xi16_to_2xbf16_param_0];
324 ; CHECK: st.param.b32 [func_retval0+0], [[R]];
326 define <2 x bfloat> @test_bitcast_2xi16_to_2xbf16(<2 x i16> %a) #0 {
327 %r = bitcast <2 x i16> %a to <2 x bfloat>
331 declare <2 x bfloat> @llvm.sqrt.f16(<2 x bfloat> %a) #0
332 declare <2 x bfloat> @llvm.powi.f16(<2 x bfloat> %a, <2 x i32> %b) #0
333 declare <2 x bfloat> @llvm.sin.f16(<2 x bfloat> %a) #0
334 declare <2 x bfloat> @llvm.cos.f16(<2 x bfloat> %a) #0
335 declare <2 x bfloat> @llvm.pow.f16(<2 x bfloat> %a, <2 x bfloat> %b) #0
336 declare <2 x bfloat> @llvm.exp.f16(<2 x bfloat> %a) #0
337 declare <2 x bfloat> @llvm.exp2.f16(<2 x bfloat> %a) #0
338 declare <2 x bfloat> @llvm.log.f16(<2 x bfloat> %a) #0
339 declare <2 x bfloat> @llvm.log10.f16(<2 x bfloat> %a) #0
340 declare <2 x bfloat> @llvm.log2.f16(<2 x bfloat> %a) #0
341 declare <2 x bfloat> @llvm.fma.f16(<2 x bfloat> %a, <2 x bfloat> %b, <2 x bfloat> %c) #0
342 declare <2 x bfloat> @llvm.fabs.f16(<2 x bfloat> %a) #0
343 declare <2 x bfloat> @llvm.minnum.f16(<2 x bfloat> %a, <2 x bfloat> %b) #0
344 declare <2 x bfloat> @llvm.maxnum.f16(<2 x bfloat> %a, <2 x bfloat> %b) #0
345 declare <2 x bfloat> @llvm.copysign.f16(<2 x bfloat> %a, <2 x bfloat> %b) #0
346 declare <2 x bfloat> @llvm.floor.f16(<2 x bfloat> %a) #0
347 declare <2 x bfloat> @llvm.ceil.f16(<2 x bfloat> %a) #0
348 declare <2 x bfloat> @llvm.trunc.f16(<2 x bfloat> %a) #0
349 declare <2 x bfloat> @llvm.rint.f16(<2 x bfloat> %a) #0
350 declare <2 x bfloat> @llvm.nearbyint.f16(<2 x bfloat> %a) #0
351 declare <2 x bfloat> @llvm.round.f16(<2 x bfloat> %a) #0
352 declare <2 x bfloat> @llvm.fmuladd.f16(<2 x bfloat> %a, <2 x bfloat> %b, <2 x bfloat> %c) #0
355 ; CHECK-LABEL: test_sqrt(
356 ; CHECK: ld.param.b32 [[A:%r[0-9]+]], [test_sqrt_param_0];
357 ; CHECK: mov.b32 {[[A0:%rs[0-9]+]], [[A1:%rs[0-9]+]]}, [[A]]
358 ; CHECK-DAG: cvt.f32.bf16 [[AF0:%f[0-9]+]], [[A0]];
359 ; CHECK-DAG: cvt.f32.bf16 [[AF1:%f[0-9]+]], [[A1]];
360 ; CHECK-DAG: sqrt.rn.f32 [[RF0:%f[0-9]+]], [[AF0]];
361 ; CHECK-DAG: sqrt.rn.f32 [[RF1:%f[0-9]+]], [[AF1]];
362 ; CHECK-DAG: cvt.rn.bf16.f32 [[R0:%rs[0-9]+]], [[RF0]];
363 ; CHECK-DAG: cvt.rn.bf16.f32 [[R1:%rs[0-9]+]], [[RF1]];
364 ; CHECK: mov.b32 [[R:%r[0-9]+]], {[[R0]], [[R1]]}
365 ; CHECK: st.param.b32 [func_retval0+0], [[R]];
367 define <2 x bfloat> @test_sqrt(<2 x bfloat> %a) #0 {
368 %r = call <2 x bfloat> @llvm.sqrt.f16(<2 x bfloat> %a)
372 ; CHECK-LABEL: test_fmuladd(
373 ; CHECK-DAG: ld.param.b32 [[A:%r[0-9]+]], [test_fmuladd_param_0];
374 ; CHECK-DAG: ld.param.b32 [[B:%r[0-9]+]], [test_fmuladd_param_1];
375 ; CHECK-DAG: ld.param.b32 [[C:%r[0-9]+]], [test_fmuladd_param_2];
377 ; CHECK: fma.rn.bf16x2 [[RA:%r[0-9]+]], [[A]], [[B]], [[C]];
378 ; CHECK-NEXT: st.param.b32 [func_retval0+0], [[RA]];
380 define <2 x bfloat> @test_fmuladd(<2 x bfloat> %a, <2 x bfloat> %b, <2 x bfloat> %c) #0 {
381 %r = call <2 x bfloat> @llvm.fmuladd.f16(<2 x bfloat> %a, <2 x bfloat> %b, <2 x bfloat> %c)
385 ; CHECK-LABEL: test_fabs(
386 ; CHECK: ld.param.u32 [[A:%r[0-9]+]], [test_fabs_param_0];
387 ; CHECK: and.b32 [[R:%r[0-9]+]], [[A]], 2147450879;
388 ; CHECK: st.param.b32 [func_retval0+0], [[R]];
390 define <2 x bfloat> @test_fabs(<2 x bfloat> %a) #0 {
391 %r = call <2 x bfloat> @llvm.fabs.f16(<2 x bfloat> %a)
395 ; CHECK-LABEL: test_fabs_add(
398 define <2 x bfloat> @test_fabs_add(<2 x bfloat> %a, <2 x bfloat> %b) #0 {
399 %s = fadd <2 x bfloat> %a, %a
400 %r = call <2 x bfloat> @llvm.fabs.f16(<2 x bfloat> %s)
401 %d = fadd <2 x bfloat> %r, %b
406 ; CHECK-LABEL: test_minnum(
407 ; CHECK-DAG: ld.param.b32 [[AF0:%r[0-9]+]], [test_minnum_param_0];
408 ; CHECK-DAG: ld.param.b32 [[BF0:%r[0-9]+]], [test_minnum_param_1];
409 ; CHECK-DAG: min.bf16x2 [[RF0:%r[0-9]+]], [[AF0]], [[BF0]];
410 ; CHECK: st.param.b32 [func_retval0+0], [[RF0]];
412 define <2 x bfloat> @test_minnum(<2 x bfloat> %a, <2 x bfloat> %b) #0 {
413 %r = call <2 x bfloat> @llvm.minnum.f16(<2 x bfloat> %a, <2 x bfloat> %b)
417 ; CHECK-LABEL: test_maxnum(
418 ; CHECK-DAG: ld.param.b32 [[AF0:%r[0-9]+]], [test_maxnum_param_0];
419 ; CHECK-DAG: ld.param.b32 [[BF0:%r[0-9]+]], [test_maxnum_param_1];
420 ; CHECK-DAG: max.bf16x2 [[RF0:%r[0-9]+]], [[AF0]], [[BF0]];
421 ; CHECK: st.param.b32 [func_retval0+0], [[RF0]];
423 define <2 x bfloat> @test_maxnum(<2 x bfloat> %a, <2 x bfloat> %b) #0 {
424 %r = call <2 x bfloat> @llvm.maxnum.f16(<2 x bfloat> %a, <2 x bfloat> %b)
430 ; CHECK-LABEL: test_floor(
431 ; CHECK: ld.param.b32 [[A:%r[0-9]+]], [test_floor_param_0];
432 ; CHECK-DAG: mov.b32 {[[A0:%rs[0-9]+]], [[A1:%rs[0-9]+]]}, [[A]];
433 ; SM90: cvt.rmi.bf16.bf16 [[R1:%rs[0-9]+]], [[A1]];
434 ; SM90: cvt.rmi.bf16.bf16 [[R0:%rs[0-9]+]], [[A0]];
435 ; SM80-DAG: cvt.f32.bf16 [[FA0:%f[0-9]+]], [[A0]];
436 ; SM80-DAG: cvt.f32.bf16 [[FA1:%f[0-9]+]], [[A1]];
437 ; SM80-DAG: cvt.rmi.f32.f32 [[RF0:%f[0-9]+]], [[FA0]];
438 ; SM80-DAG: cvt.rmi.f32.f32 [[RF1:%f[0-9]+]], [[FA1]];
439 ; SM80-DAG: cvt.rn.bf16.f32 [[R0:%rs[0-9]+]], [[RF0]];
440 ; SM80-DAG: cvt.rn.bf16.f32 [[R1:%rs[0-9]+]], [[RF1]];
441 ; CHECK: mov.b32 [[R:%r[0-9]+]], {[[R0]], [[R1]]}
442 ; CHECK: st.param.b32 [func_retval0+0], [[R]];
444 define <2 x bfloat> @test_floor(<2 x bfloat> %a) #0 {
445 %r = call <2 x bfloat> @llvm.floor.f16(<2 x bfloat> %a)
449 ; CHECK-LABEL: test_ceil(
450 ; CHECK: ld.param.b32 [[A:%r[0-9]+]], [test_ceil_param_0];
451 ; CHECK-DAG: mov.b32 {[[A0:%rs[0-9]+]], [[A1:%rs[0-9]+]]}, [[A]];
452 ; SM90: cvt.rpi.bf16.bf16 [[R1:%rs[0-9]+]], [[A1]];
453 ; SM90: cvt.rpi.bf16.bf16 [[R0:%rs[0-9]+]], [[A0]];
454 ; SM80-DAG: cvt.f32.bf16 [[FA0:%f[0-9]+]], [[A0]];
455 ; SM80-DAG: cvt.f32.bf16 [[FA1:%f[0-9]+]], [[A1]];
456 ; SM80-DAG: cvt.rpi.f32.f32 [[RF0:%f[0-9]+]], [[FA0]];
457 ; SM80-DAG: cvt.rpi.f32.f32 [[RF1:%f[0-9]+]], [[FA1]];
458 ; SM80-DAG: cvt.rn.bf16.f32 [[R0:%rs[0-9]+]], [[RF0]];
459 ; SM80-DAG: cvt.rn.bf16.f32 [[R1:%rs[0-9]+]], [[RF1]];
460 ; CHECK: mov.b32 [[R:%r[0-9]+]], {[[R0]], [[R1]]}
461 ; CHECK: st.param.b32 [func_retval0+0], [[R]];
463 define <2 x bfloat> @test_ceil(<2 x bfloat> %a) #0 {
464 %r = call <2 x bfloat> @llvm.ceil.f16(<2 x bfloat> %a)
468 ; CHECK-LABEL: test_trunc(
469 ; CHECK: ld.param.b32 [[A:%r[0-9]+]], [test_trunc_param_0];
470 ; CHECK-DAG: mov.b32 {[[A0:%rs[0-9]+]], [[A1:%rs[0-9]+]]}, [[A]];
471 ; SM90: cvt.rzi.bf16.bf16 [[R1:%rs[0-9]+]], [[A1]];
472 ; SM90: cvt.rzi.bf16.bf16 [[R0:%rs[0-9]+]], [[A0]];
473 ; CHECK: mov.b32 [[R:%r[0-9]+]], {[[R0]], [[R1]]}
474 ; CHECK: st.param.b32 [func_retval0+0], [[R]];
476 define <2 x bfloat> @test_trunc(<2 x bfloat> %a) #0 {
477 %r = call <2 x bfloat> @llvm.trunc.f16(<2 x bfloat> %a)
481 ; CHECK-LABEL: test_rint(
482 ; CHECK: ld.param.b32 [[A:%r[0-9]+]], [test_rint_param_0];
483 ; CHECK-DAG: mov.b32 {[[A0:%rs[0-9]+]], [[A1:%rs[0-9]+]]}, [[A]];
484 ; SM90: cvt.rni.bf16.bf16 [[R1:%rs[0-9]+]], [[A1]];
485 ; SM90: cvt.rni.bf16.bf16 [[R0:%rs[0-9]+]], [[A0]];
486 ; CHECK: mov.b32 [[R:%r[0-9]+]], {[[R0]], [[R1]]}
487 ; CHECK: st.param.b32 [func_retval0+0], [[R]];
489 define <2 x bfloat> @test_rint(<2 x bfloat> %a) #0 {
490 %r = call <2 x bfloat> @llvm.rint.f16(<2 x bfloat> %a)
494 ; CHECK-LABEL: test_round(
495 ; CHECK: ld.param.b32 {{.*}}, [test_round_param_0];
496 ; check the use of sign mask and 0.5 to implement round
497 ; CHECK: and.b32 [[R1:%r[0-9]+]], {{.*}}, -2147483648;
498 ; CHECK: or.b32 {{.*}}, [[R1]], 1056964608;
499 ; CHECK: and.b32 [[R2:%r[0-9]+]], {{.*}}, -2147483648;
500 ; CHECK: or.b32 {{.*}}, [[R2]], 1056964608;
501 ; CHECK: st.param.b32 [func_retval0+0], {{.*}};
503 define <2 x bfloat> @test_round(<2 x bfloat> %a) #0 {
504 %r = call <2 x bfloat> @llvm.round.f16(<2 x bfloat> %a)
508 ; CHECK-LABEL: test_copysign(
509 ; CHECK-DAG: ld.param.b32 [[A:%r[0-9]+]], [test_copysign_param_0];
510 ; CHECK-DAG: ld.param.b32 [[B:%r[0-9]+]], [test_copysign_param_1];
511 ; CHECK-DAG: mov.b32 {[[A0:%rs[0-9]+]], [[A1:%rs[0-9]+]]}, [[A]]
512 ; CHECK-DAG: mov.b32 {[[B0:%rs[0-9]+]], [[B1:%rs[0-9]+]]}, [[B]]
513 ; CHECK-DAG: abs.bf16 [[AW1:%rs[0-9]+]], [[A1]];
514 ; CHECK-DAG: neg.bf16 [[AY1:%rs[0-9]+]], [[AW1]];
515 ; CHECK-DAG: shr.u16 [[BS1:%rs[0-9]+]], [[B1]], 15;
516 ; CHECK-DAG: and.b16 [[BR1:%rs[0-9]+]], [[BS1]], 1;
517 ; CHECK-DAG: setp.eq.b16 [[P1:%p[0-9]+]], [[BR1]], 1;
518 ; CHECK-DAG: selp.b16 [[RS1:%rs[0-9]+]], [[AY1]], [[AW1]], [[P1]]
519 ; CHECK-DAG: abs.bf16 [[AW0:%rs[0-9]+]], [[A0]];
520 ; CHECK-DAG: neg.bf16 [[AY0:%rs[0-9]+]], [[AW0]];
521 ; CHECK-DAG: shr.u16 [[BS0:%rs[0-9]+]], [[B0]], 15;
522 ; CHECK-DAG: and.b16 [[BR0:%rs[0-9]+]], [[BS0]], 1;
523 ; CHECK-DAG: setp.eq.b16 [[P0:%p[0-9]+]], [[BR0]], 1;
524 ; CHECK-DAG: selp.b16 [[RS0:%rs[0-9]+]], [[AY0]], [[AW0]], [[P0]]
525 ; CHECK-DAG: mov.b32 [[R:%r[0-9]+]], {[[RS0]], [[RS1]]}
526 ; CHECK: st.param.b32 [func_retval0+0], [[R]];
528 define <2 x bfloat> @test_copysign(<2 x bfloat> %a, <2 x bfloat> %b) #0 {
529 %r = call <2 x bfloat> @llvm.copysign.f16(<2 x bfloat> %a, <2 x bfloat> %b)