1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zfh -verify-machineinstrs \
3 ; RUN: -target-abi ilp32f < %s \
4 ; RUN: | FileCheck -check-prefix=RV32IZFH %s
5 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-zfh -verify-machineinstrs \
6 ; RUN: -target-abi lp64f < %s \
7 ; RUN: | FileCheck -check-prefix=RV64IZFH %s
9 ; These tests are each targeted at a particular RISC-V FPU instruction. Most
10 ; other files in this folder exercise LLVM IR instructions that don't directly
11 ; match a RISC-V instruction.
13 define half @fadd_s(half %a, half %b) nounwind {
14 ; RV32IZFH-LABEL: fadd_s:
16 ; RV32IZFH-NEXT: fadd.h fa0, fa0, fa1
19 ; RV64IZFH-LABEL: fadd_s:
21 ; RV64IZFH-NEXT: fadd.h fa0, fa0, fa1
27 define half @fsub_s(half %a, half %b) nounwind {
28 ; RV32IZFH-LABEL: fsub_s:
30 ; RV32IZFH-NEXT: fsub.h fa0, fa0, fa1
33 ; RV64IZFH-LABEL: fsub_s:
35 ; RV64IZFH-NEXT: fsub.h fa0, fa0, fa1
41 define half @fmul_s(half %a, half %b) nounwind {
42 ; RV32IZFH-LABEL: fmul_s:
44 ; RV32IZFH-NEXT: fmul.h fa0, fa0, fa1
47 ; RV64IZFH-LABEL: fmul_s:
49 ; RV64IZFH-NEXT: fmul.h fa0, fa0, fa1
55 define half @fdiv_s(half %a, half %b) nounwind {
56 ; RV32IZFH-LABEL: fdiv_s:
58 ; RV32IZFH-NEXT: fdiv.h fa0, fa0, fa1
61 ; RV64IZFH-LABEL: fdiv_s:
63 ; RV64IZFH-NEXT: fdiv.h fa0, fa0, fa1
69 declare half @llvm.sqrt.f16(half)
71 define half @fsqrt_s(half %a) nounwind {
72 ; RV32IZFH-LABEL: fsqrt_s:
74 ; RV32IZFH-NEXT: fsqrt.h fa0, fa0
77 ; RV64IZFH-LABEL: fsqrt_s:
79 ; RV64IZFH-NEXT: fsqrt.h fa0, fa0
81 %1 = call half @llvm.sqrt.f16(half %a)
85 declare half @llvm.copysign.f16(half, half)
87 define half @fsgnj_s(half %a, half %b) nounwind {
88 ; RV32IZFH-LABEL: fsgnj_s:
90 ; RV32IZFH-NEXT: fsgnj.h fa0, fa0, fa1
93 ; RV64IZFH-LABEL: fsgnj_s:
95 ; RV64IZFH-NEXT: fsgnj.h fa0, fa0, fa1
97 %1 = call half @llvm.copysign.f16(half %a, half %b)
101 ; This function performs extra work to ensure that
102 ; DAGCombiner::visitBITCAST doesn't replace the fneg with an xor.
103 define i32 @fneg_s(half %a, half %b) nounwind {
104 ; RV32IZFH-LABEL: fneg_s:
106 ; RV32IZFH-NEXT: fadd.h ft0, fa0, fa0
107 ; RV32IZFH-NEXT: fneg.h ft1, ft0
108 ; RV32IZFH-NEXT: feq.h a0, ft0, ft1
111 ; RV64IZFH-LABEL: fneg_s:
113 ; RV64IZFH-NEXT: fadd.h ft0, fa0, fa0
114 ; RV64IZFH-NEXT: fneg.h ft1, ft0
115 ; RV64IZFH-NEXT: feq.h a0, ft0, ft1
117 %1 = fadd half %a, %a
119 %3 = fcmp oeq half %1, %2
120 %4 = zext i1 %3 to i32
124 ; This function performs extra work to ensure that
125 ; DAGCombiner::visitBITCAST doesn't replace the fneg with an xor.
126 define half @fsgnjn_s(half %a, half %b) nounwind {
127 ; RV32IZFH-LABEL: fsgnjn_s:
129 ; RV32IZFH-NEXT: fadd.h ft0, fa0, fa1
130 ; RV32IZFH-NEXT: fsgnjn.h fa0, fa0, ft0
133 ; RV64IZFH-LABEL: fsgnjn_s:
135 ; RV64IZFH-NEXT: fadd.h ft0, fa0, fa1
136 ; RV64IZFH-NEXT: fsgnjn.h fa0, fa0, ft0
138 %1 = fadd half %a, %b
140 %3 = call half @llvm.copysign.f16(half %a, half %2)
144 declare half @llvm.fabs.f16(half)
146 ; This function performs extra work to ensure that
147 ; DAGCombiner::visitBITCAST doesn't replace the fabs with an and.
148 define half @fabs_s(half %a, half %b) nounwind {
149 ; RV32IZFH-LABEL: fabs_s:
151 ; RV32IZFH-NEXT: fadd.h ft0, fa0, fa1
152 ; RV32IZFH-NEXT: fabs.h ft1, ft0
153 ; RV32IZFH-NEXT: fadd.h fa0, ft1, ft0
156 ; RV64IZFH-LABEL: fabs_s:
158 ; RV64IZFH-NEXT: fadd.h ft0, fa0, fa1
159 ; RV64IZFH-NEXT: fabs.h ft1, ft0
160 ; RV64IZFH-NEXT: fadd.h fa0, ft1, ft0
162 %1 = fadd half %a, %b
163 %2 = call half @llvm.fabs.f16(half %1)
164 %3 = fadd half %2, %1
168 declare half @llvm.minnum.f16(half, half)
170 define half @fmin_s(half %a, half %b) nounwind {
171 ; RV32IZFH-LABEL: fmin_s:
173 ; RV32IZFH-NEXT: fmin.h fa0, fa0, fa1
176 ; RV64IZFH-LABEL: fmin_s:
178 ; RV64IZFH-NEXT: fmin.h fa0, fa0, fa1
180 %1 = call half @llvm.minnum.f16(half %a, half %b)
184 declare half @llvm.maxnum.f16(half, half)
186 define half @fmax_s(half %a, half %b) nounwind {
187 ; RV32IZFH-LABEL: fmax_s:
189 ; RV32IZFH-NEXT: fmax.h fa0, fa0, fa1
192 ; RV64IZFH-LABEL: fmax_s:
194 ; RV64IZFH-NEXT: fmax.h fa0, fa0, fa1
196 %1 = call half @llvm.maxnum.f16(half %a, half %b)
200 define i32 @feq_s(half %a, half %b) nounwind {
201 ; RV32IZFH-LABEL: feq_s:
203 ; RV32IZFH-NEXT: feq.h a0, fa0, fa1
206 ; RV64IZFH-LABEL: feq_s:
208 ; RV64IZFH-NEXT: feq.h a0, fa0, fa1
210 %1 = fcmp oeq half %a, %b
211 %2 = zext i1 %1 to i32
215 define i32 @flt_s(half %a, half %b) nounwind {
216 ; RV32IZFH-LABEL: flt_s:
218 ; RV32IZFH-NEXT: flt.h a0, fa0, fa1
221 ; RV64IZFH-LABEL: flt_s:
223 ; RV64IZFH-NEXT: flt.h a0, fa0, fa1
225 %1 = fcmp olt half %a, %b
226 %2 = zext i1 %1 to i32
230 define i32 @fle_s(half %a, half %b) nounwind {
231 ; RV32IZFH-LABEL: fle_s:
233 ; RV32IZFH-NEXT: fle.h a0, fa0, fa1
236 ; RV64IZFH-LABEL: fle_s:
238 ; RV64IZFH-NEXT: fle.h a0, fa0, fa1
240 %1 = fcmp ole half %a, %b
241 %2 = zext i1 %1 to i32
245 declare half @llvm.fma.f16(half, half, half)
247 define half @fmadd_s(half %a, half %b, half %c) nounwind {
248 ; RV32IZFH-LABEL: fmadd_s:
250 ; RV32IZFH-NEXT: fmadd.h fa0, fa0, fa1, fa2
253 ; RV64IZFH-LABEL: fmadd_s:
255 ; RV64IZFH-NEXT: fmadd.h fa0, fa0, fa1, fa2
257 %1 = call half @llvm.fma.f16(half %a, half %b, half %c)
261 define half @fmsub_s(half %a, half %b, half %c) nounwind {
262 ; RV32IZFH-LABEL: fmsub_s:
264 ; RV32IZFH-NEXT: fmv.h.x ft0, zero
265 ; RV32IZFH-NEXT: fadd.h ft0, fa2, ft0
266 ; RV32IZFH-NEXT: fmsub.h fa0, fa0, fa1, ft0
269 ; RV64IZFH-LABEL: fmsub_s:
271 ; RV64IZFH-NEXT: fmv.h.x ft0, zero
272 ; RV64IZFH-NEXT: fadd.h ft0, fa2, ft0
273 ; RV64IZFH-NEXT: fmsub.h fa0, fa0, fa1, ft0
275 %c_ = fadd half 0.0, %c ; avoid negation using xor
276 %negc = fsub half -0.0, %c_
277 %1 = call half @llvm.fma.f16(half %a, half %b, half %negc)
281 define half @fnmadd_s(half %a, half %b, half %c) nounwind {
282 ; RV32IZFH-LABEL: fnmadd_s:
284 ; RV32IZFH-NEXT: fmv.h.x ft0, zero
285 ; RV32IZFH-NEXT: fadd.h ft1, fa0, ft0
286 ; RV32IZFH-NEXT: fadd.h ft0, fa2, ft0
287 ; RV32IZFH-NEXT: fnmadd.h fa0, ft1, fa1, ft0
290 ; RV64IZFH-LABEL: fnmadd_s:
292 ; RV64IZFH-NEXT: fmv.h.x ft0, zero
293 ; RV64IZFH-NEXT: fadd.h ft1, fa0, ft0
294 ; RV64IZFH-NEXT: fadd.h ft0, fa2, ft0
295 ; RV64IZFH-NEXT: fnmadd.h fa0, ft1, fa1, ft0
297 %a_ = fadd half 0.0, %a
298 %c_ = fadd half 0.0, %c
299 %nega = fsub half -0.0, %a_
300 %negc = fsub half -0.0, %c_
301 %1 = call half @llvm.fma.f16(half %nega, half %b, half %negc)
305 define half @fnmadd_s_2(half %a, half %b, half %c) nounwind {
306 ; RV32IZFH-LABEL: fnmadd_s_2:
308 ; RV32IZFH-NEXT: fmv.h.x ft0, zero
309 ; RV32IZFH-NEXT: fadd.h ft1, fa1, ft0
310 ; RV32IZFH-NEXT: fadd.h ft0, fa2, ft0
311 ; RV32IZFH-NEXT: fnmadd.h fa0, ft1, fa0, ft0
314 ; RV64IZFH-LABEL: fnmadd_s_2:
316 ; RV64IZFH-NEXT: fmv.h.x ft0, zero
317 ; RV64IZFH-NEXT: fadd.h ft1, fa1, ft0
318 ; RV64IZFH-NEXT: fadd.h ft0, fa2, ft0
319 ; RV64IZFH-NEXT: fnmadd.h fa0, ft1, fa0, ft0
321 %b_ = fadd half 0.0, %b
322 %c_ = fadd half 0.0, %c
323 %negb = fsub half -0.0, %b_
324 %negc = fsub half -0.0, %c_
325 %1 = call half @llvm.fma.f16(half %a, half %negb, half %negc)
329 define half @fnmsub_s(half %a, half %b, half %c) nounwind {
330 ; RV32IZFH-LABEL: fnmsub_s:
332 ; RV32IZFH-NEXT: fmv.h.x ft0, zero
333 ; RV32IZFH-NEXT: fadd.h ft0, fa0, ft0
334 ; RV32IZFH-NEXT: fnmsub.h fa0, ft0, fa1, fa2
337 ; RV64IZFH-LABEL: fnmsub_s:
339 ; RV64IZFH-NEXT: fmv.h.x ft0, zero
340 ; RV64IZFH-NEXT: fadd.h ft0, fa0, ft0
341 ; RV64IZFH-NEXT: fnmsub.h fa0, ft0, fa1, fa2
343 %a_ = fadd half 0.0, %a
344 %nega = fsub half -0.0, %a_
345 %1 = call half @llvm.fma.f16(half %nega, half %b, half %c)
349 define half @fnmsub_s_2(half %a, half %b, half %c) nounwind {
350 ; RV32IZFH-LABEL: fnmsub_s_2:
352 ; RV32IZFH-NEXT: fmv.h.x ft0, zero
353 ; RV32IZFH-NEXT: fadd.h ft0, fa1, ft0
354 ; RV32IZFH-NEXT: fnmsub.h fa0, ft0, fa0, fa2
357 ; RV64IZFH-LABEL: fnmsub_s_2:
359 ; RV64IZFH-NEXT: fmv.h.x ft0, zero
360 ; RV64IZFH-NEXT: fadd.h ft0, fa1, ft0
361 ; RV64IZFH-NEXT: fnmsub.h fa0, ft0, fa0, fa2
363 %b_ = fadd half 0.0, %b
364 %negb = fsub half -0.0, %b_
365 %1 = call half @llvm.fma.f16(half %a, half %negb, half %c)
369 define half @fmadd_s_contract(half %a, half %b, half %c) nounwind {
370 ; RV32IZFH-LABEL: fmadd_s_contract:
372 ; RV32IZFH-NEXT: fmadd.h fa0, fa0, fa1, fa2
375 ; RV64IZFH-LABEL: fmadd_s_contract:
377 ; RV64IZFH-NEXT: fmadd.h fa0, fa0, fa1, fa2
379 %1 = fmul contract half %a, %b
380 %2 = fadd contract half %1, %c
384 define half @fmsub_s_contract(half %a, half %b, half %c) nounwind {
385 ; RV32IZFH-LABEL: fmsub_s_contract:
387 ; RV32IZFH-NEXT: fmv.h.x ft0, zero
388 ; RV32IZFH-NEXT: fadd.h ft0, fa2, ft0
389 ; RV32IZFH-NEXT: fmsub.h fa0, fa0, fa1, ft0
392 ; RV64IZFH-LABEL: fmsub_s_contract:
394 ; RV64IZFH-NEXT: fmv.h.x ft0, zero
395 ; RV64IZFH-NEXT: fadd.h ft0, fa2, ft0
396 ; RV64IZFH-NEXT: fmsub.h fa0, fa0, fa1, ft0
398 %c_ = fadd half 0.0, %c ; avoid negation using xor
399 %1 = fmul contract half %a, %b
400 %2 = fsub contract half %1, %c_
404 define half @fnmadd_s_contract(half %a, half %b, half %c) nounwind {
405 ; RV32IZFH-LABEL: fnmadd_s_contract:
407 ; RV32IZFH-NEXT: fmv.h.x ft0, zero
408 ; RV32IZFH-NEXT: fadd.h ft1, fa0, ft0
409 ; RV32IZFH-NEXT: fadd.h ft2, fa1, ft0
410 ; RV32IZFH-NEXT: fadd.h ft0, fa2, ft0
411 ; RV32IZFH-NEXT: fnmadd.h fa0, ft1, ft2, ft0
414 ; RV64IZFH-LABEL: fnmadd_s_contract:
416 ; RV64IZFH-NEXT: fmv.h.x ft0, zero
417 ; RV64IZFH-NEXT: fadd.h ft1, fa0, ft0
418 ; RV64IZFH-NEXT: fadd.h ft2, fa1, ft0
419 ; RV64IZFH-NEXT: fadd.h ft0, fa2, ft0
420 ; RV64IZFH-NEXT: fnmadd.h fa0, ft1, ft2, ft0
422 %a_ = fadd half 0.0, %a ; avoid negation using xor
423 %b_ = fadd half 0.0, %b ; avoid negation using xor
424 %c_ = fadd half 0.0, %c ; avoid negation using xor
425 %1 = fmul contract half %a_, %b_
427 %3 = fsub contract half %2, %c_
431 define half @fnmsub_s_contract(half %a, half %b, half %c) nounwind {
432 ; RV32IZFH-LABEL: fnmsub_s_contract:
434 ; RV32IZFH-NEXT: fmv.h.x ft0, zero
435 ; RV32IZFH-NEXT: fadd.h ft1, fa0, ft0
436 ; RV32IZFH-NEXT: fadd.h ft0, fa1, ft0
437 ; RV32IZFH-NEXT: fnmsub.h fa0, ft1, ft0, fa2
440 ; RV64IZFH-LABEL: fnmsub_s_contract:
442 ; RV64IZFH-NEXT: fmv.h.x ft0, zero
443 ; RV64IZFH-NEXT: fadd.h ft1, fa0, ft0
444 ; RV64IZFH-NEXT: fadd.h ft0, fa1, ft0
445 ; RV64IZFH-NEXT: fnmsub.h fa0, ft1, ft0, fa2
447 %a_ = fadd half 0.0, %a ; avoid negation using xor
448 %b_ = fadd half 0.0, %b ; avoid negation using xor
449 %1 = fmul contract half %a_, %b_
450 %2 = fsub contract half %c, %1