1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv32 -mattr=+f -verify-machineinstrs < %s \
3 ; RUN: | FileCheck -check-prefix=RV32IF %s
4 ; RUN: llc -mtriple=riscv32 -mattr=+d -verify-machineinstrs < %s \
5 ; RUN: | FileCheck -check-prefix=RV32IF %s
6 ; RUN: llc -mtriple=riscv64 -mattr=+f -verify-machineinstrs < %s \
7 ; RUN: | FileCheck -check-prefix=RV64IF %s
8 ; RUN: llc -mtriple=riscv64 -mattr=+d -verify-machineinstrs < %s \
9 ; RUN: | FileCheck -check-prefix=RV64IF %s
11 declare float @llvm.sqrt.f32(float)
13 define float @sqrt_f32(float %a) nounwind {
14 ; RV32IF-LABEL: sqrt_f32:
16 ; RV32IF-NEXT: fmv.w.x ft0, a0
17 ; RV32IF-NEXT: fsqrt.s ft0, ft0
18 ; RV32IF-NEXT: fmv.x.w a0, ft0
21 ; RV64IF-LABEL: sqrt_f32:
23 ; RV64IF-NEXT: fmv.w.x ft0, a0
24 ; RV64IF-NEXT: fsqrt.s ft0, ft0
25 ; RV64IF-NEXT: fmv.x.w a0, ft0
27 %1 = call float @llvm.sqrt.f32(float %a)
31 declare float @llvm.powi.f32(float, i32)
33 define float @powi_f32(float %a, i32 %b) nounwind {
34 ; RV32IF-LABEL: powi_f32:
36 ; RV32IF-NEXT: addi sp, sp, -16
37 ; RV32IF-NEXT: sw ra, 12(sp)
38 ; RV32IF-NEXT: call __powisf2
39 ; RV32IF-NEXT: lw ra, 12(sp)
40 ; RV32IF-NEXT: addi sp, sp, 16
43 ; RV64IF-LABEL: powi_f32:
45 ; RV64IF-NEXT: addi sp, sp, -16
46 ; RV64IF-NEXT: sd ra, 8(sp)
47 ; RV64IF-NEXT: sext.w a1, a1
48 ; RV64IF-NEXT: call __powisf2
49 ; RV64IF-NEXT: ld ra, 8(sp)
50 ; RV64IF-NEXT: addi sp, sp, 16
52 %1 = call float @llvm.powi.f32(float %a, i32 %b)
56 declare float @llvm.sin.f32(float)
58 define float @sin_f32(float %a) nounwind {
59 ; RV32IF-LABEL: sin_f32:
61 ; RV32IF-NEXT: addi sp, sp, -16
62 ; RV32IF-NEXT: sw ra, 12(sp)
63 ; RV32IF-NEXT: call sinf
64 ; RV32IF-NEXT: lw ra, 12(sp)
65 ; RV32IF-NEXT: addi sp, sp, 16
68 ; RV64IF-LABEL: sin_f32:
70 ; RV64IF-NEXT: addi sp, sp, -16
71 ; RV64IF-NEXT: sd ra, 8(sp)
72 ; RV64IF-NEXT: call sinf
73 ; RV64IF-NEXT: ld ra, 8(sp)
74 ; RV64IF-NEXT: addi sp, sp, 16
76 %1 = call float @llvm.sin.f32(float %a)
80 declare float @llvm.cos.f32(float)
82 define float @cos_f32(float %a) nounwind {
83 ; RV32IF-LABEL: cos_f32:
85 ; RV32IF-NEXT: addi sp, sp, -16
86 ; RV32IF-NEXT: sw ra, 12(sp)
87 ; RV32IF-NEXT: call cosf
88 ; RV32IF-NEXT: lw ra, 12(sp)
89 ; RV32IF-NEXT: addi sp, sp, 16
92 ; RV64IF-LABEL: cos_f32:
94 ; RV64IF-NEXT: addi sp, sp, -16
95 ; RV64IF-NEXT: sd ra, 8(sp)
96 ; RV64IF-NEXT: call cosf
97 ; RV64IF-NEXT: ld ra, 8(sp)
98 ; RV64IF-NEXT: addi sp, sp, 16
100 %1 = call float @llvm.cos.f32(float %a)
104 ; The sin+cos combination results in an FSINCOS SelectionDAG node.
105 define float @sincos_f32(float %a) nounwind {
106 ; RV32IF-LABEL: sincos_f32:
108 ; RV32IF-NEXT: addi sp, sp, -16
109 ; RV32IF-NEXT: sw ra, 12(sp)
110 ; RV32IF-NEXT: sw s0, 8(sp)
111 ; RV32IF-NEXT: sw s1, 4(sp)
112 ; RV32IF-NEXT: mv s0, a0
113 ; RV32IF-NEXT: call sinf
114 ; RV32IF-NEXT: mv s1, a0
115 ; RV32IF-NEXT: mv a0, s0
116 ; RV32IF-NEXT: call cosf
117 ; RV32IF-NEXT: fmv.w.x ft0, a0
118 ; RV32IF-NEXT: fmv.w.x ft1, s1
119 ; RV32IF-NEXT: fadd.s ft0, ft1, ft0
120 ; RV32IF-NEXT: fmv.x.w a0, ft0
121 ; RV32IF-NEXT: lw s1, 4(sp)
122 ; RV32IF-NEXT: lw s0, 8(sp)
123 ; RV32IF-NEXT: lw ra, 12(sp)
124 ; RV32IF-NEXT: addi sp, sp, 16
127 ; RV64IF-LABEL: sincos_f32:
129 ; RV64IF-NEXT: addi sp, sp, -32
130 ; RV64IF-NEXT: sd ra, 24(sp)
131 ; RV64IF-NEXT: sd s0, 16(sp)
132 ; RV64IF-NEXT: sd s1, 8(sp)
133 ; RV64IF-NEXT: mv s0, a0
134 ; RV64IF-NEXT: call sinf
135 ; RV64IF-NEXT: mv s1, a0
136 ; RV64IF-NEXT: mv a0, s0
137 ; RV64IF-NEXT: call cosf
138 ; RV64IF-NEXT: fmv.w.x ft0, a0
139 ; RV64IF-NEXT: fmv.w.x ft1, s1
140 ; RV64IF-NEXT: fadd.s ft0, ft1, ft0
141 ; RV64IF-NEXT: fmv.x.w a0, ft0
142 ; RV64IF-NEXT: ld s1, 8(sp)
143 ; RV64IF-NEXT: ld s0, 16(sp)
144 ; RV64IF-NEXT: ld ra, 24(sp)
145 ; RV64IF-NEXT: addi sp, sp, 32
147 %1 = call float @llvm.sin.f32(float %a)
148 %2 = call float @llvm.cos.f32(float %a)
149 %3 = fadd float %1, %2
153 declare float @llvm.pow.f32(float, float)
155 define float @pow_f32(float %a, float %b) nounwind {
156 ; RV32IF-LABEL: pow_f32:
158 ; RV32IF-NEXT: addi sp, sp, -16
159 ; RV32IF-NEXT: sw ra, 12(sp)
160 ; RV32IF-NEXT: call powf
161 ; RV32IF-NEXT: lw ra, 12(sp)
162 ; RV32IF-NEXT: addi sp, sp, 16
165 ; RV64IF-LABEL: pow_f32:
167 ; RV64IF-NEXT: addi sp, sp, -16
168 ; RV64IF-NEXT: sd ra, 8(sp)
169 ; RV64IF-NEXT: call powf
170 ; RV64IF-NEXT: ld ra, 8(sp)
171 ; RV64IF-NEXT: addi sp, sp, 16
173 %1 = call float @llvm.pow.f32(float %a, float %b)
177 declare float @llvm.exp.f32(float)
179 define float @exp_f32(float %a) nounwind {
180 ; RV32IF-LABEL: exp_f32:
182 ; RV32IF-NEXT: addi sp, sp, -16
183 ; RV32IF-NEXT: sw ra, 12(sp)
184 ; RV32IF-NEXT: call expf
185 ; RV32IF-NEXT: lw ra, 12(sp)
186 ; RV32IF-NEXT: addi sp, sp, 16
189 ; RV64IF-LABEL: exp_f32:
191 ; RV64IF-NEXT: addi sp, sp, -16
192 ; RV64IF-NEXT: sd ra, 8(sp)
193 ; RV64IF-NEXT: call expf
194 ; RV64IF-NEXT: ld ra, 8(sp)
195 ; RV64IF-NEXT: addi sp, sp, 16
197 %1 = call float @llvm.exp.f32(float %a)
201 declare float @llvm.exp2.f32(float)
203 define float @exp2_f32(float %a) nounwind {
204 ; RV32IF-LABEL: exp2_f32:
206 ; RV32IF-NEXT: addi sp, sp, -16
207 ; RV32IF-NEXT: sw ra, 12(sp)
208 ; RV32IF-NEXT: call exp2f
209 ; RV32IF-NEXT: lw ra, 12(sp)
210 ; RV32IF-NEXT: addi sp, sp, 16
213 ; RV64IF-LABEL: exp2_f32:
215 ; RV64IF-NEXT: addi sp, sp, -16
216 ; RV64IF-NEXT: sd ra, 8(sp)
217 ; RV64IF-NEXT: call exp2f
218 ; RV64IF-NEXT: ld ra, 8(sp)
219 ; RV64IF-NEXT: addi sp, sp, 16
221 %1 = call float @llvm.exp2.f32(float %a)
225 declare float @llvm.log.f32(float)
227 define float @log_f32(float %a) nounwind {
228 ; RV32IF-LABEL: log_f32:
230 ; RV32IF-NEXT: addi sp, sp, -16
231 ; RV32IF-NEXT: sw ra, 12(sp)
232 ; RV32IF-NEXT: call logf
233 ; RV32IF-NEXT: lw ra, 12(sp)
234 ; RV32IF-NEXT: addi sp, sp, 16
237 ; RV64IF-LABEL: log_f32:
239 ; RV64IF-NEXT: addi sp, sp, -16
240 ; RV64IF-NEXT: sd ra, 8(sp)
241 ; RV64IF-NEXT: call logf
242 ; RV64IF-NEXT: ld ra, 8(sp)
243 ; RV64IF-NEXT: addi sp, sp, 16
245 %1 = call float @llvm.log.f32(float %a)
249 declare float @llvm.log10.f32(float)
251 define float @log10_f32(float %a) nounwind {
252 ; RV32IF-LABEL: log10_f32:
254 ; RV32IF-NEXT: addi sp, sp, -16
255 ; RV32IF-NEXT: sw ra, 12(sp)
256 ; RV32IF-NEXT: call log10f
257 ; RV32IF-NEXT: lw ra, 12(sp)
258 ; RV32IF-NEXT: addi sp, sp, 16
261 ; RV64IF-LABEL: log10_f32:
263 ; RV64IF-NEXT: addi sp, sp, -16
264 ; RV64IF-NEXT: sd ra, 8(sp)
265 ; RV64IF-NEXT: call log10f
266 ; RV64IF-NEXT: ld ra, 8(sp)
267 ; RV64IF-NEXT: addi sp, sp, 16
269 %1 = call float @llvm.log10.f32(float %a)
273 declare float @llvm.log2.f32(float)
275 define float @log2_f32(float %a) nounwind {
276 ; RV32IF-LABEL: log2_f32:
278 ; RV32IF-NEXT: addi sp, sp, -16
279 ; RV32IF-NEXT: sw ra, 12(sp)
280 ; RV32IF-NEXT: call log2f
281 ; RV32IF-NEXT: lw ra, 12(sp)
282 ; RV32IF-NEXT: addi sp, sp, 16
285 ; RV64IF-LABEL: log2_f32:
287 ; RV64IF-NEXT: addi sp, sp, -16
288 ; RV64IF-NEXT: sd ra, 8(sp)
289 ; RV64IF-NEXT: call log2f
290 ; RV64IF-NEXT: ld ra, 8(sp)
291 ; RV64IF-NEXT: addi sp, sp, 16
293 %1 = call float @llvm.log2.f32(float %a)
297 declare float @llvm.fma.f32(float, float, float)
299 define float @fma_f32(float %a, float %b, float %c) nounwind {
300 ; RV32IF-LABEL: fma_f32:
302 ; RV32IF-NEXT: fmv.w.x ft0, a2
303 ; RV32IF-NEXT: fmv.w.x ft1, a1
304 ; RV32IF-NEXT: fmv.w.x ft2, a0
305 ; RV32IF-NEXT: fmadd.s ft0, ft2, ft1, ft0
306 ; RV32IF-NEXT: fmv.x.w a0, ft0
309 ; RV64IF-LABEL: fma_f32:
311 ; RV64IF-NEXT: fmv.w.x ft0, a2
312 ; RV64IF-NEXT: fmv.w.x ft1, a1
313 ; RV64IF-NEXT: fmv.w.x ft2, a0
314 ; RV64IF-NEXT: fmadd.s ft0, ft2, ft1, ft0
315 ; RV64IF-NEXT: fmv.x.w a0, ft0
317 %1 = call float @llvm.fma.f32(float %a, float %b, float %c)
321 declare float @llvm.fmuladd.f32(float, float, float)
323 define float @fmuladd_f32(float %a, float %b, float %c) nounwind {
324 ; Use of fmadd depends on TargetLowering::isFMAFasterthanFMulAndFAdd
325 ; RV32IF-LABEL: fmuladd_f32:
327 ; RV32IF-NEXT: fmv.w.x ft0, a1
328 ; RV32IF-NEXT: fmv.w.x ft1, a0
329 ; RV32IF-NEXT: fmul.s ft0, ft1, ft0
330 ; RV32IF-NEXT: fmv.w.x ft1, a2
331 ; RV32IF-NEXT: fadd.s ft0, ft0, ft1
332 ; RV32IF-NEXT: fmv.x.w a0, ft0
335 ; RV64IF-LABEL: fmuladd_f32:
337 ; RV64IF-NEXT: fmv.w.x ft0, a1
338 ; RV64IF-NEXT: fmv.w.x ft1, a0
339 ; RV64IF-NEXT: fmul.s ft0, ft1, ft0
340 ; RV64IF-NEXT: fmv.w.x ft1, a2
341 ; RV64IF-NEXT: fadd.s ft0, ft0, ft1
342 ; RV64IF-NEXT: fmv.x.w a0, ft0
344 %1 = call float @llvm.fmuladd.f32(float %a, float %b, float %c)
348 declare float @llvm.fabs.f32(float)
350 define float @fabs_f32(float %a) nounwind {
351 ; RV32IF-LABEL: fabs_f32:
353 ; RV32IF-NEXT: lui a1, 524288
354 ; RV32IF-NEXT: addi a1, a1, -1
355 ; RV32IF-NEXT: and a0, a0, a1
358 ; RV64IF-LABEL: fabs_f32:
360 ; RV64IF-NEXT: lui a1, 524288
361 ; RV64IF-NEXT: addiw a1, a1, -1
362 ; RV64IF-NEXT: and a0, a0, a1
364 %1 = call float @llvm.fabs.f32(float %a)
368 declare float @llvm.minnum.f32(float, float)
370 define float @minnum_f32(float %a, float %b) nounwind {
371 ; RV32IF-LABEL: minnum_f32:
373 ; RV32IF-NEXT: fmv.w.x ft0, a1
374 ; RV32IF-NEXT: fmv.w.x ft1, a0
375 ; RV32IF-NEXT: fmin.s ft0, ft1, ft0
376 ; RV32IF-NEXT: fmv.x.w a0, ft0
379 ; RV64IF-LABEL: minnum_f32:
381 ; RV64IF-NEXT: fmv.w.x ft0, a1
382 ; RV64IF-NEXT: fmv.w.x ft1, a0
383 ; RV64IF-NEXT: fmin.s ft0, ft1, ft0
384 ; RV64IF-NEXT: fmv.x.w a0, ft0
386 %1 = call float @llvm.minnum.f32(float %a, float %b)
390 declare float @llvm.maxnum.f32(float, float)
392 define float @maxnum_f32(float %a, float %b) nounwind {
393 ; RV32IF-LABEL: maxnum_f32:
395 ; RV32IF-NEXT: fmv.w.x ft0, a1
396 ; RV32IF-NEXT: fmv.w.x ft1, a0
397 ; RV32IF-NEXT: fmax.s ft0, ft1, ft0
398 ; RV32IF-NEXT: fmv.x.w a0, ft0
401 ; RV64IF-LABEL: maxnum_f32:
403 ; RV64IF-NEXT: fmv.w.x ft0, a1
404 ; RV64IF-NEXT: fmv.w.x ft1, a0
405 ; RV64IF-NEXT: fmax.s ft0, ft1, ft0
406 ; RV64IF-NEXT: fmv.x.w a0, ft0
408 %1 = call float @llvm.maxnum.f32(float %a, float %b)
412 ; TODO: FMINNAN and FMAXNAN aren't handled in
413 ; SelectionDAGLegalize::ExpandNode.
415 ; declare float @llvm.minimum.f32(float, float)
417 ; define float @fminimum_f32(float %a, float %b) nounwind {
418 ; %1 = call float @llvm.minimum.f32(float %a, float %b)
422 ; declare float @llvm.maximum.f32(float, float)
424 ; define float @fmaximum_f32(float %a, float %b) nounwind {
425 ; %1 = call float @llvm.maximum.f32(float %a, float %b)
429 declare float @llvm.copysign.f32(float, float)
431 define float @copysign_f32(float %a, float %b) nounwind {
432 ; RV32IF-LABEL: copysign_f32:
434 ; RV32IF-NEXT: fmv.w.x ft0, a1
435 ; RV32IF-NEXT: fmv.w.x ft1, a0
436 ; RV32IF-NEXT: fsgnj.s ft0, ft1, ft0
437 ; RV32IF-NEXT: fmv.x.w a0, ft0
440 ; RV64IF-LABEL: copysign_f32:
442 ; RV64IF-NEXT: fmv.w.x ft0, a1
443 ; RV64IF-NEXT: fmv.w.x ft1, a0
444 ; RV64IF-NEXT: fsgnj.s ft0, ft1, ft0
445 ; RV64IF-NEXT: fmv.x.w a0, ft0
447 %1 = call float @llvm.copysign.f32(float %a, float %b)
451 declare float @llvm.floor.f32(float)
453 define float @floor_f32(float %a) nounwind {
454 ; RV32IF-LABEL: floor_f32:
456 ; RV32IF-NEXT: addi sp, sp, -16
457 ; RV32IF-NEXT: sw ra, 12(sp)
458 ; RV32IF-NEXT: call floorf
459 ; RV32IF-NEXT: lw ra, 12(sp)
460 ; RV32IF-NEXT: addi sp, sp, 16
463 ; RV64IF-LABEL: floor_f32:
465 ; RV64IF-NEXT: addi sp, sp, -16
466 ; RV64IF-NEXT: sd ra, 8(sp)
467 ; RV64IF-NEXT: call floorf
468 ; RV64IF-NEXT: ld ra, 8(sp)
469 ; RV64IF-NEXT: addi sp, sp, 16
471 %1 = call float @llvm.floor.f32(float %a)
475 declare float @llvm.ceil.f32(float)
477 define float @ceil_f32(float %a) nounwind {
478 ; RV32IF-LABEL: ceil_f32:
480 ; RV32IF-NEXT: addi sp, sp, -16
481 ; RV32IF-NEXT: sw ra, 12(sp)
482 ; RV32IF-NEXT: call ceilf
483 ; RV32IF-NEXT: lw ra, 12(sp)
484 ; RV32IF-NEXT: addi sp, sp, 16
487 ; RV64IF-LABEL: ceil_f32:
489 ; RV64IF-NEXT: addi sp, sp, -16
490 ; RV64IF-NEXT: sd ra, 8(sp)
491 ; RV64IF-NEXT: call ceilf
492 ; RV64IF-NEXT: ld ra, 8(sp)
493 ; RV64IF-NEXT: addi sp, sp, 16
495 %1 = call float @llvm.ceil.f32(float %a)
499 declare float @llvm.trunc.f32(float)
501 define float @trunc_f32(float %a) nounwind {
502 ; RV32IF-LABEL: trunc_f32:
504 ; RV32IF-NEXT: addi sp, sp, -16
505 ; RV32IF-NEXT: sw ra, 12(sp)
506 ; RV32IF-NEXT: call truncf
507 ; RV32IF-NEXT: lw ra, 12(sp)
508 ; RV32IF-NEXT: addi sp, sp, 16
511 ; RV64IF-LABEL: trunc_f32:
513 ; RV64IF-NEXT: addi sp, sp, -16
514 ; RV64IF-NEXT: sd ra, 8(sp)
515 ; RV64IF-NEXT: call truncf
516 ; RV64IF-NEXT: ld ra, 8(sp)
517 ; RV64IF-NEXT: addi sp, sp, 16
519 %1 = call float @llvm.trunc.f32(float %a)
523 declare float @llvm.rint.f32(float)
525 define float @rint_f32(float %a) nounwind {
526 ; RV32IF-LABEL: rint_f32:
528 ; RV32IF-NEXT: addi sp, sp, -16
529 ; RV32IF-NEXT: sw ra, 12(sp)
530 ; RV32IF-NEXT: call rintf
531 ; RV32IF-NEXT: lw ra, 12(sp)
532 ; RV32IF-NEXT: addi sp, sp, 16
535 ; RV64IF-LABEL: rint_f32:
537 ; RV64IF-NEXT: addi sp, sp, -16
538 ; RV64IF-NEXT: sd ra, 8(sp)
539 ; RV64IF-NEXT: call rintf
540 ; RV64IF-NEXT: ld ra, 8(sp)
541 ; RV64IF-NEXT: addi sp, sp, 16
543 %1 = call float @llvm.rint.f32(float %a)
547 declare float @llvm.nearbyint.f32(float)
549 define float @nearbyint_f32(float %a) nounwind {
550 ; RV32IF-LABEL: nearbyint_f32:
552 ; RV32IF-NEXT: addi sp, sp, -16
553 ; RV32IF-NEXT: sw ra, 12(sp)
554 ; RV32IF-NEXT: call nearbyintf
555 ; RV32IF-NEXT: lw ra, 12(sp)
556 ; RV32IF-NEXT: addi sp, sp, 16
559 ; RV64IF-LABEL: nearbyint_f32:
561 ; RV64IF-NEXT: addi sp, sp, -16
562 ; RV64IF-NEXT: sd ra, 8(sp)
563 ; RV64IF-NEXT: call nearbyintf
564 ; RV64IF-NEXT: ld ra, 8(sp)
565 ; RV64IF-NEXT: addi sp, sp, 16
567 %1 = call float @llvm.nearbyint.f32(float %a)
571 declare float @llvm.round.f32(float)
573 define float @round_f32(float %a) nounwind {
574 ; RV32IF-LABEL: round_f32:
576 ; RV32IF-NEXT: addi sp, sp, -16
577 ; RV32IF-NEXT: sw ra, 12(sp)
578 ; RV32IF-NEXT: call roundf
579 ; RV32IF-NEXT: lw ra, 12(sp)
580 ; RV32IF-NEXT: addi sp, sp, 16
583 ; RV64IF-LABEL: round_f32:
585 ; RV64IF-NEXT: addi sp, sp, -16
586 ; RV64IF-NEXT: sd ra, 8(sp)
587 ; RV64IF-NEXT: call roundf
588 ; RV64IF-NEXT: ld ra, 8(sp)
589 ; RV64IF-NEXT: addi sp, sp, 16
591 %1 = call float @llvm.round.f32(float %a)