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: mv s0, a0
112 ; RV32IF-NEXT: call sinf
113 ; RV32IF-NEXT: fmv.w.x ft0, a0
114 ; RV32IF-NEXT: fsw ft0, 4(sp)
115 ; RV32IF-NEXT: mv a0, s0
116 ; RV32IF-NEXT: call cosf
117 ; RV32IF-NEXT: fmv.w.x ft0, a0
118 ; RV32IF-NEXT: flw ft1, 4(sp)
119 ; RV32IF-NEXT: fadd.s ft0, ft1, ft0
120 ; RV32IF-NEXT: fmv.x.w a0, ft0
121 ; RV32IF-NEXT: lw s0, 8(sp)
122 ; RV32IF-NEXT: lw ra, 12(sp)
123 ; RV32IF-NEXT: addi sp, sp, 16
126 ; RV64IF-LABEL: sincos_f32:
128 ; RV64IF-NEXT: addi sp, sp, -32
129 ; RV64IF-NEXT: sd ra, 24(sp)
130 ; RV64IF-NEXT: sd s0, 16(sp)
131 ; RV64IF-NEXT: mv s0, a0
132 ; RV64IF-NEXT: call sinf
133 ; RV64IF-NEXT: fmv.w.x ft0, a0
134 ; RV64IF-NEXT: fsw ft0, 12(sp)
135 ; RV64IF-NEXT: mv a0, s0
136 ; RV64IF-NEXT: call cosf
137 ; RV64IF-NEXT: fmv.w.x ft0, a0
138 ; RV64IF-NEXT: flw ft1, 12(sp)
139 ; RV64IF-NEXT: fadd.s ft0, ft1, ft0
140 ; RV64IF-NEXT: fmv.x.w a0, ft0
141 ; RV64IF-NEXT: ld s0, 16(sp)
142 ; RV64IF-NEXT: ld ra, 24(sp)
143 ; RV64IF-NEXT: addi sp, sp, 32
145 %1 = call float @llvm.sin.f32(float %a)
146 %2 = call float @llvm.cos.f32(float %a)
147 %3 = fadd float %1, %2
151 declare float @llvm.pow.f32(float, float)
153 define float @pow_f32(float %a, float %b) nounwind {
154 ; RV32IF-LABEL: pow_f32:
156 ; RV32IF-NEXT: addi sp, sp, -16
157 ; RV32IF-NEXT: sw ra, 12(sp)
158 ; RV32IF-NEXT: call powf
159 ; RV32IF-NEXT: lw ra, 12(sp)
160 ; RV32IF-NEXT: addi sp, sp, 16
163 ; RV64IF-LABEL: pow_f32:
165 ; RV64IF-NEXT: addi sp, sp, -16
166 ; RV64IF-NEXT: sd ra, 8(sp)
167 ; RV64IF-NEXT: call powf
168 ; RV64IF-NEXT: ld ra, 8(sp)
169 ; RV64IF-NEXT: addi sp, sp, 16
171 %1 = call float @llvm.pow.f32(float %a, float %b)
175 declare float @llvm.exp.f32(float)
177 define float @exp_f32(float %a) nounwind {
178 ; RV32IF-LABEL: exp_f32:
180 ; RV32IF-NEXT: addi sp, sp, -16
181 ; RV32IF-NEXT: sw ra, 12(sp)
182 ; RV32IF-NEXT: call expf
183 ; RV32IF-NEXT: lw ra, 12(sp)
184 ; RV32IF-NEXT: addi sp, sp, 16
187 ; RV64IF-LABEL: exp_f32:
189 ; RV64IF-NEXT: addi sp, sp, -16
190 ; RV64IF-NEXT: sd ra, 8(sp)
191 ; RV64IF-NEXT: call expf
192 ; RV64IF-NEXT: ld ra, 8(sp)
193 ; RV64IF-NEXT: addi sp, sp, 16
195 %1 = call float @llvm.exp.f32(float %a)
199 declare float @llvm.exp2.f32(float)
201 define float @exp2_f32(float %a) nounwind {
202 ; RV32IF-LABEL: exp2_f32:
204 ; RV32IF-NEXT: addi sp, sp, -16
205 ; RV32IF-NEXT: sw ra, 12(sp)
206 ; RV32IF-NEXT: call exp2f
207 ; RV32IF-NEXT: lw ra, 12(sp)
208 ; RV32IF-NEXT: addi sp, sp, 16
211 ; RV64IF-LABEL: exp2_f32:
213 ; RV64IF-NEXT: addi sp, sp, -16
214 ; RV64IF-NEXT: sd ra, 8(sp)
215 ; RV64IF-NEXT: call exp2f
216 ; RV64IF-NEXT: ld ra, 8(sp)
217 ; RV64IF-NEXT: addi sp, sp, 16
219 %1 = call float @llvm.exp2.f32(float %a)
223 declare float @llvm.log.f32(float)
225 define float @log_f32(float %a) nounwind {
226 ; RV32IF-LABEL: log_f32:
228 ; RV32IF-NEXT: addi sp, sp, -16
229 ; RV32IF-NEXT: sw ra, 12(sp)
230 ; RV32IF-NEXT: call logf
231 ; RV32IF-NEXT: lw ra, 12(sp)
232 ; RV32IF-NEXT: addi sp, sp, 16
235 ; RV64IF-LABEL: log_f32:
237 ; RV64IF-NEXT: addi sp, sp, -16
238 ; RV64IF-NEXT: sd ra, 8(sp)
239 ; RV64IF-NEXT: call logf
240 ; RV64IF-NEXT: ld ra, 8(sp)
241 ; RV64IF-NEXT: addi sp, sp, 16
243 %1 = call float @llvm.log.f32(float %a)
247 declare float @llvm.log10.f32(float)
249 define float @log10_f32(float %a) nounwind {
250 ; RV32IF-LABEL: log10_f32:
252 ; RV32IF-NEXT: addi sp, sp, -16
253 ; RV32IF-NEXT: sw ra, 12(sp)
254 ; RV32IF-NEXT: call log10f
255 ; RV32IF-NEXT: lw ra, 12(sp)
256 ; RV32IF-NEXT: addi sp, sp, 16
259 ; RV64IF-LABEL: log10_f32:
261 ; RV64IF-NEXT: addi sp, sp, -16
262 ; RV64IF-NEXT: sd ra, 8(sp)
263 ; RV64IF-NEXT: call log10f
264 ; RV64IF-NEXT: ld ra, 8(sp)
265 ; RV64IF-NEXT: addi sp, sp, 16
267 %1 = call float @llvm.log10.f32(float %a)
271 declare float @llvm.log2.f32(float)
273 define float @log2_f32(float %a) nounwind {
274 ; RV32IF-LABEL: log2_f32:
276 ; RV32IF-NEXT: addi sp, sp, -16
277 ; RV32IF-NEXT: sw ra, 12(sp)
278 ; RV32IF-NEXT: call log2f
279 ; RV32IF-NEXT: lw ra, 12(sp)
280 ; RV32IF-NEXT: addi sp, sp, 16
283 ; RV64IF-LABEL: log2_f32:
285 ; RV64IF-NEXT: addi sp, sp, -16
286 ; RV64IF-NEXT: sd ra, 8(sp)
287 ; RV64IF-NEXT: call log2f
288 ; RV64IF-NEXT: ld ra, 8(sp)
289 ; RV64IF-NEXT: addi sp, sp, 16
291 %1 = call float @llvm.log2.f32(float %a)
295 declare float @llvm.fma.f32(float, float, float)
297 define float @fma_f32(float %a, float %b, float %c) nounwind {
298 ; RV32IF-LABEL: fma_f32:
300 ; RV32IF-NEXT: fmv.w.x ft0, a2
301 ; RV32IF-NEXT: fmv.w.x ft1, a1
302 ; RV32IF-NEXT: fmv.w.x ft2, a0
303 ; RV32IF-NEXT: fmadd.s ft0, ft2, ft1, ft0
304 ; RV32IF-NEXT: fmv.x.w a0, ft0
307 ; RV64IF-LABEL: fma_f32:
309 ; RV64IF-NEXT: fmv.w.x ft0, a2
310 ; RV64IF-NEXT: fmv.w.x ft1, a1
311 ; RV64IF-NEXT: fmv.w.x ft2, a0
312 ; RV64IF-NEXT: fmadd.s ft0, ft2, ft1, ft0
313 ; RV64IF-NEXT: fmv.x.w a0, ft0
315 %1 = call float @llvm.fma.f32(float %a, float %b, float %c)
319 declare float @llvm.fmuladd.f32(float, float, float)
321 define float @fmuladd_f32(float %a, float %b, float %c) nounwind {
322 ; Use of fmadd depends on TargetLowering::isFMAFasterthanFMulAndFAdd
323 ; RV32IF-LABEL: fmuladd_f32:
325 ; RV32IF-NEXT: fmv.w.x ft0, a2
326 ; RV32IF-NEXT: fmv.w.x ft1, a1
327 ; RV32IF-NEXT: fmv.w.x ft2, a0
328 ; RV32IF-NEXT: fmul.s ft1, ft2, ft1
329 ; RV32IF-NEXT: fadd.s ft0, ft1, ft0
330 ; RV32IF-NEXT: fmv.x.w a0, ft0
333 ; RV64IF-LABEL: fmuladd_f32:
335 ; RV64IF-NEXT: fmv.w.x ft0, a2
336 ; RV64IF-NEXT: fmv.w.x ft1, a1
337 ; RV64IF-NEXT: fmv.w.x ft2, a0
338 ; RV64IF-NEXT: fmul.s ft1, ft2, ft1
339 ; RV64IF-NEXT: fadd.s ft0, ft1, ft0
340 ; RV64IF-NEXT: fmv.x.w a0, ft0
342 %1 = call float @llvm.fmuladd.f32(float %a, float %b, float %c)
346 declare float @llvm.fabs.f32(float)
348 define float @fabs_f32(float %a) nounwind {
349 ; RV32IF-LABEL: fabs_f32:
351 ; RV32IF-NEXT: lui a1, 524288
352 ; RV32IF-NEXT: addi a1, a1, -1
353 ; RV32IF-NEXT: and a0, a0, a1
356 ; RV64IF-LABEL: fabs_f32:
358 ; RV64IF-NEXT: lui a1, 524288
359 ; RV64IF-NEXT: addiw a1, a1, -1
360 ; RV64IF-NEXT: and a0, a0, a1
362 %1 = call float @llvm.fabs.f32(float %a)
366 declare float @llvm.minnum.f32(float, float)
368 define float @minnum_f32(float %a, float %b) nounwind {
369 ; RV32IF-LABEL: minnum_f32:
371 ; RV32IF-NEXT: fmv.w.x ft0, a1
372 ; RV32IF-NEXT: fmv.w.x ft1, a0
373 ; RV32IF-NEXT: fmin.s ft0, ft1, ft0
374 ; RV32IF-NEXT: fmv.x.w a0, ft0
377 ; RV64IF-LABEL: minnum_f32:
379 ; RV64IF-NEXT: fmv.w.x ft0, a1
380 ; RV64IF-NEXT: fmv.w.x ft1, a0
381 ; RV64IF-NEXT: fmin.s ft0, ft1, ft0
382 ; RV64IF-NEXT: fmv.x.w a0, ft0
384 %1 = call float @llvm.minnum.f32(float %a, float %b)
388 declare float @llvm.maxnum.f32(float, float)
390 define float @maxnum_f32(float %a, float %b) nounwind {
391 ; RV32IF-LABEL: maxnum_f32:
393 ; RV32IF-NEXT: fmv.w.x ft0, a1
394 ; RV32IF-NEXT: fmv.w.x ft1, a0
395 ; RV32IF-NEXT: fmax.s ft0, ft1, ft0
396 ; RV32IF-NEXT: fmv.x.w a0, ft0
399 ; RV64IF-LABEL: maxnum_f32:
401 ; RV64IF-NEXT: fmv.w.x ft0, a1
402 ; RV64IF-NEXT: fmv.w.x ft1, a0
403 ; RV64IF-NEXT: fmax.s ft0, ft1, ft0
404 ; RV64IF-NEXT: fmv.x.w a0, ft0
406 %1 = call float @llvm.maxnum.f32(float %a, float %b)
410 ; TODO: FMINNAN and FMAXNAN aren't handled in
411 ; SelectionDAGLegalize::ExpandNode.
413 ; declare float @llvm.minimum.f32(float, float)
415 ; define float @fminimum_f32(float %a, float %b) nounwind {
416 ; %1 = call float @llvm.minimum.f32(float %a, float %b)
420 ; declare float @llvm.maximum.f32(float, float)
422 ; define float @fmaximum_f32(float %a, float %b) nounwind {
423 ; %1 = call float @llvm.maximum.f32(float %a, float %b)
427 declare float @llvm.copysign.f32(float, float)
429 define float @copysign_f32(float %a, float %b) nounwind {
430 ; RV32IF-LABEL: copysign_f32:
432 ; RV32IF-NEXT: fmv.w.x ft0, a1
433 ; RV32IF-NEXT: fmv.w.x ft1, a0
434 ; RV32IF-NEXT: fsgnj.s ft0, ft1, ft0
435 ; RV32IF-NEXT: fmv.x.w a0, ft0
438 ; RV64IF-LABEL: copysign_f32:
440 ; RV64IF-NEXT: fmv.w.x ft0, a1
441 ; RV64IF-NEXT: fmv.w.x ft1, a0
442 ; RV64IF-NEXT: fsgnj.s ft0, ft1, ft0
443 ; RV64IF-NEXT: fmv.x.w a0, ft0
445 %1 = call float @llvm.copysign.f32(float %a, float %b)
449 declare float @llvm.floor.f32(float)
451 define float @floor_f32(float %a) nounwind {
452 ; RV32IF-LABEL: floor_f32:
454 ; RV32IF-NEXT: addi sp, sp, -16
455 ; RV32IF-NEXT: sw ra, 12(sp)
456 ; RV32IF-NEXT: call floorf
457 ; RV32IF-NEXT: lw ra, 12(sp)
458 ; RV32IF-NEXT: addi sp, sp, 16
461 ; RV64IF-LABEL: floor_f32:
463 ; RV64IF-NEXT: addi sp, sp, -16
464 ; RV64IF-NEXT: sd ra, 8(sp)
465 ; RV64IF-NEXT: call floorf
466 ; RV64IF-NEXT: ld ra, 8(sp)
467 ; RV64IF-NEXT: addi sp, sp, 16
469 %1 = call float @llvm.floor.f32(float %a)
473 declare float @llvm.ceil.f32(float)
475 define float @ceil_f32(float %a) nounwind {
476 ; RV32IF-LABEL: ceil_f32:
478 ; RV32IF-NEXT: addi sp, sp, -16
479 ; RV32IF-NEXT: sw ra, 12(sp)
480 ; RV32IF-NEXT: call ceilf
481 ; RV32IF-NEXT: lw ra, 12(sp)
482 ; RV32IF-NEXT: addi sp, sp, 16
485 ; RV64IF-LABEL: ceil_f32:
487 ; RV64IF-NEXT: addi sp, sp, -16
488 ; RV64IF-NEXT: sd ra, 8(sp)
489 ; RV64IF-NEXT: call ceilf
490 ; RV64IF-NEXT: ld ra, 8(sp)
491 ; RV64IF-NEXT: addi sp, sp, 16
493 %1 = call float @llvm.ceil.f32(float %a)
497 declare float @llvm.trunc.f32(float)
499 define float @trunc_f32(float %a) nounwind {
500 ; RV32IF-LABEL: trunc_f32:
502 ; RV32IF-NEXT: addi sp, sp, -16
503 ; RV32IF-NEXT: sw ra, 12(sp)
504 ; RV32IF-NEXT: call truncf
505 ; RV32IF-NEXT: lw ra, 12(sp)
506 ; RV32IF-NEXT: addi sp, sp, 16
509 ; RV64IF-LABEL: trunc_f32:
511 ; RV64IF-NEXT: addi sp, sp, -16
512 ; RV64IF-NEXT: sd ra, 8(sp)
513 ; RV64IF-NEXT: call truncf
514 ; RV64IF-NEXT: ld ra, 8(sp)
515 ; RV64IF-NEXT: addi sp, sp, 16
517 %1 = call float @llvm.trunc.f32(float %a)
521 declare float @llvm.rint.f32(float)
523 define float @rint_f32(float %a) nounwind {
524 ; RV32IF-LABEL: rint_f32:
526 ; RV32IF-NEXT: addi sp, sp, -16
527 ; RV32IF-NEXT: sw ra, 12(sp)
528 ; RV32IF-NEXT: call rintf
529 ; RV32IF-NEXT: lw ra, 12(sp)
530 ; RV32IF-NEXT: addi sp, sp, 16
533 ; RV64IF-LABEL: rint_f32:
535 ; RV64IF-NEXT: addi sp, sp, -16
536 ; RV64IF-NEXT: sd ra, 8(sp)
537 ; RV64IF-NEXT: call rintf
538 ; RV64IF-NEXT: ld ra, 8(sp)
539 ; RV64IF-NEXT: addi sp, sp, 16
541 %1 = call float @llvm.rint.f32(float %a)
545 declare float @llvm.nearbyint.f32(float)
547 define float @nearbyint_f32(float %a) nounwind {
548 ; RV32IF-LABEL: nearbyint_f32:
550 ; RV32IF-NEXT: addi sp, sp, -16
551 ; RV32IF-NEXT: sw ra, 12(sp)
552 ; RV32IF-NEXT: call nearbyintf
553 ; RV32IF-NEXT: lw ra, 12(sp)
554 ; RV32IF-NEXT: addi sp, sp, 16
557 ; RV64IF-LABEL: nearbyint_f32:
559 ; RV64IF-NEXT: addi sp, sp, -16
560 ; RV64IF-NEXT: sd ra, 8(sp)
561 ; RV64IF-NEXT: call nearbyintf
562 ; RV64IF-NEXT: ld ra, 8(sp)
563 ; RV64IF-NEXT: addi sp, sp, 16
565 %1 = call float @llvm.nearbyint.f32(float %a)
569 declare float @llvm.round.f32(float)
571 define float @round_f32(float %a) nounwind {
572 ; RV32IF-LABEL: round_f32:
574 ; RV32IF-NEXT: addi sp, sp, -16
575 ; RV32IF-NEXT: sw ra, 12(sp)
576 ; RV32IF-NEXT: call roundf
577 ; RV32IF-NEXT: lw ra, 12(sp)
578 ; RV32IF-NEXT: addi sp, sp, 16
581 ; RV64IF-LABEL: round_f32:
583 ; RV64IF-NEXT: addi sp, sp, -16
584 ; RV64IF-NEXT: sd ra, 8(sp)
585 ; RV64IF-NEXT: call roundf
586 ; RV64IF-NEXT: ld ra, 8(sp)
587 ; RV64IF-NEXT: addi sp, sp, 16
589 %1 = call float @llvm.round.f32(float %a)