1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc --mtriple=loongarch64 --mattr=+d --target-abi=lp64d < %s \
5 ;; This file contains specific tests for the lp64d ABI.
7 ;; Check pass floating-point arguments whith FPRs.
9 define i64 @callee_float_in_fpr(i64 %a, float %b, double %c) nounwind {
10 ; CHECK-LABEL: callee_float_in_fpr:
12 ; CHECK-NEXT: ftintrz.l.s $fa0, $fa0
13 ; CHECK-NEXT: movfr2gr.d $a1, $fa0
14 ; CHECK-NEXT: ftintrz.l.d $fa0, $fa1
15 ; CHECK-NEXT: movfr2gr.d $a2, $fa0
16 ; CHECK-NEXT: add.d $a0, $a0, $a1
17 ; CHECK-NEXT: add.d $a0, $a0, $a2
19 %b_fptosi = fptosi float %b to i64
20 %c_fptosi = fptosi double %c to i64
21 %1 = add i64 %a, %b_fptosi
22 %2 = add i64 %1, %c_fptosi
26 define i64 @caller_float_in_fpr() nounwind {
27 ; CHECK-LABEL: caller_float_in_fpr:
29 ; CHECK-NEXT: addi.d $sp, $sp, -16
30 ; CHECK-NEXT: st.d $ra, $sp, 8 # 8-byte Folded Spill
31 ; CHECK-NEXT: movgr2fr.w $fa0, $zero
32 ; CHECK-NEXT: movgr2fr.d $fa1, $zero
33 ; CHECK-NEXT: ori $a0, $zero, 1
34 ; CHECK-NEXT: bl %plt(callee_float_in_fpr)
35 ; CHECK-NEXT: ld.d $ra, $sp, 8 # 8-byte Folded Reload
36 ; CHECK-NEXT: addi.d $sp, $sp, 16
38 %1 = call i64 @callee_float_in_fpr(i64 1, float 0.0, double 0.0)
42 ;; Check that the GPR is used once the FPRs are exhausted.
44 ;; Must keep define on a single line due to an update_llc_test_checks.py limitation.
45 define i64 @callee_double_in_gpr_exhausted_fprs(double %a, double %b, double %c, double %d, double %e, double %f, double %g, double %h, double %i) nounwind {
46 ; CHECK-LABEL: callee_double_in_gpr_exhausted_fprs:
48 ; CHECK-NEXT: movgr2fr.d $fa0, $a0
49 ; CHECK-NEXT: ftintrz.l.d $fa1, $fa7
50 ; CHECK-NEXT: movfr2gr.d $a0, $fa1
51 ; CHECK-NEXT: ftintrz.l.d $fa0, $fa0
52 ; CHECK-NEXT: movfr2gr.d $a1, $fa0
53 ; CHECK-NEXT: add.d $a0, $a0, $a1
55 %h_fptosi = fptosi double %h to i64
56 %i_fptosi = fptosi double %i to i64
57 %1 = add i64 %h_fptosi, %i_fptosi
61 define i64 @caller_double_in_gpr_exhausted_fprs() nounwind {
62 ; CHECK-LABEL: caller_double_in_gpr_exhausted_fprs:
64 ; CHECK-NEXT: addi.d $sp, $sp, -16
65 ; CHECK-NEXT: st.d $ra, $sp, 8 # 8-byte Folded Spill
66 ; CHECK-NEXT: pcalau12i $a0, %pc_hi20(.LCPI3_0)
67 ; CHECK-NEXT: addi.d $a0, $a0, %pc_lo12(.LCPI3_0)
68 ; CHECK-NEXT: fld.d $fa1, $a0, 0
69 ; CHECK-NEXT: pcalau12i $a0, %pc_hi20(.LCPI3_1)
70 ; CHECK-NEXT: addi.d $a0, $a0, %pc_lo12(.LCPI3_1)
71 ; CHECK-NEXT: fld.d $fa2, $a0, 0
72 ; CHECK-NEXT: pcalau12i $a0, %pc_hi20(.LCPI3_2)
73 ; CHECK-NEXT: addi.d $a0, $a0, %pc_lo12(.LCPI3_2)
74 ; CHECK-NEXT: fld.d $fa3, $a0, 0
75 ; CHECK-NEXT: pcalau12i $a0, %pc_hi20(.LCPI3_3)
76 ; CHECK-NEXT: addi.d $a0, $a0, %pc_lo12(.LCPI3_3)
77 ; CHECK-NEXT: fld.d $fa4, $a0, 0
78 ; CHECK-NEXT: pcalau12i $a0, %pc_hi20(.LCPI3_4)
79 ; CHECK-NEXT: addi.d $a0, $a0, %pc_lo12(.LCPI3_4)
80 ; CHECK-NEXT: fld.d $fa5, $a0, 0
81 ; CHECK-NEXT: pcalau12i $a0, %pc_hi20(.LCPI3_5)
82 ; CHECK-NEXT: addi.d $a0, $a0, %pc_lo12(.LCPI3_5)
83 ; CHECK-NEXT: fld.d $fa6, $a0, 0
84 ; CHECK-NEXT: pcalau12i $a0, %pc_hi20(.LCPI3_6)
85 ; CHECK-NEXT: addi.d $a0, $a0, %pc_lo12(.LCPI3_6)
86 ; CHECK-NEXT: fld.d $fa7, $a0, 0
87 ; CHECK-NEXT: addi.d $a0, $zero, 1
88 ; CHECK-NEXT: movgr2fr.d $fa0, $a0
89 ; CHECK-NEXT: ffint.d.l $fa0, $fa0
90 ; CHECK-NEXT: ori $a0, $zero, 0
91 ; CHECK-NEXT: lu32i.d $a0, 131072
92 ; CHECK-NEXT: lu52i.d $a0, $a0, 1026
93 ; CHECK-NEXT: bl %plt(callee_double_in_gpr_exhausted_fprs)
94 ; CHECK-NEXT: ld.d $ra, $sp, 8 # 8-byte Folded Reload
95 ; CHECK-NEXT: addi.d $sp, $sp, 16
97 %1 = call i64 @callee_double_in_gpr_exhausted_fprs(
98 double 1.0, double 2.0, double 3.0, double 4.0, double 5.0, double 6.0,
99 double 7.0, double 8.0, double 9.0)
103 ;; Check returning doubles.
105 define double @callee_double_ret() nounwind {
106 ; CHECK-LABEL: callee_double_ret:
108 ; CHECK-NEXT: addi.d $a0, $zero, 1
109 ; CHECK-NEXT: movgr2fr.d $fa0, $a0
110 ; CHECK-NEXT: ffint.d.l $fa0, $fa0
115 define i64 @caller_double_ret() nounwind {
116 ; CHECK-LABEL: caller_double_ret:
118 ; CHECK-NEXT: addi.d $sp, $sp, -16
119 ; CHECK-NEXT: st.d $ra, $sp, 8 # 8-byte Folded Spill
120 ; CHECK-NEXT: bl %plt(callee_double_ret)
121 ; CHECK-NEXT: movfr2gr.d $a0, $fa0
122 ; CHECK-NEXT: ld.d $ra, $sp, 8 # 8-byte Folded Reload
123 ; CHECK-NEXT: addi.d $sp, $sp, 16
125 %1 = call double @callee_double_ret()
126 %2 = bitcast double %1 to i64