1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv32 -mattr=+d -verify-machineinstrs < %s \
3 ; RUN: | FileCheck -check-prefix=RV32IFD %s
4 ; RUN: llc -mtriple=riscv64 -mattr=+d -verify-machineinstrs < %s \
5 ; RUN: | FileCheck -check-prefix=RV64IFD %s
7 define dso_local double @fld(double *%a) nounwind {
10 ; RV32IFD-NEXT: addi sp, sp, -16
11 ; RV32IFD-NEXT: fld ft0, 0(a0)
12 ; RV32IFD-NEXT: fld ft1, 24(a0)
13 ; RV32IFD-NEXT: fadd.d ft0, ft0, ft1
14 ; RV32IFD-NEXT: fsd ft0, 8(sp)
15 ; RV32IFD-NEXT: lw a0, 8(sp)
16 ; RV32IFD-NEXT: lw a1, 12(sp)
17 ; RV32IFD-NEXT: addi sp, sp, 16
22 ; RV64IFD-NEXT: fld ft0, 0(a0)
23 ; RV64IFD-NEXT: fld ft1, 24(a0)
24 ; RV64IFD-NEXT: fadd.d ft0, ft0, ft1
25 ; RV64IFD-NEXT: fmv.x.d a0, ft0
27 %1 = load double, double* %a
28 %2 = getelementptr double, double* %a, i32 3
29 %3 = load double, double* %2
30 ; Use both loaded values in an FP op to ensure an fld is used, even for the
32 %4 = fadd double %1, %3
36 define dso_local void @fsd(double *%a, double %b, double %c) nounwind {
39 ; RV32IFD-NEXT: addi sp, sp, -16
40 ; RV32IFD-NEXT: sw a3, 8(sp)
41 ; RV32IFD-NEXT: sw a4, 12(sp)
42 ; RV32IFD-NEXT: fld ft0, 8(sp)
43 ; RV32IFD-NEXT: sw a1, 8(sp)
44 ; RV32IFD-NEXT: sw a2, 12(sp)
45 ; RV32IFD-NEXT: fld ft1, 8(sp)
46 ; RV32IFD-NEXT: fadd.d ft0, ft1, ft0
47 ; RV32IFD-NEXT: fsd ft0, 0(a0)
48 ; RV32IFD-NEXT: fsd ft0, 64(a0)
49 ; RV32IFD-NEXT: addi sp, sp, 16
54 ; RV64IFD-NEXT: fmv.d.x ft0, a2
55 ; RV64IFD-NEXT: fmv.d.x ft1, a1
56 ; RV64IFD-NEXT: fadd.d ft0, ft1, ft0
57 ; RV64IFD-NEXT: fsd ft0, 0(a0)
58 ; RV64IFD-NEXT: fsd ft0, 64(a0)
60 ; Use %b and %c in an FP op to ensure floating point registers are used, even
61 ; for the soft float ABI
62 %1 = fadd double %b, %c
63 store double %1, double* %a
64 %2 = getelementptr double, double* %a, i32 8
65 store double %1, double* %2
69 ; Check load and store to a global
70 @G = dso_local global double 0.0
72 define dso_local double @fld_fsd_global(double %a, double %b) nounwind {
73 ; RV32IFD-LABEL: fld_fsd_global:
75 ; RV32IFD-NEXT: addi sp, sp, -16
76 ; RV32IFD-NEXT: sw a2, 8(sp)
77 ; RV32IFD-NEXT: sw a3, 12(sp)
78 ; RV32IFD-NEXT: fld ft0, 8(sp)
79 ; RV32IFD-NEXT: sw a0, 8(sp)
80 ; RV32IFD-NEXT: sw a1, 12(sp)
81 ; RV32IFD-NEXT: fld ft1, 8(sp)
82 ; RV32IFD-NEXT: fadd.d ft0, ft1, ft0
83 ; RV32IFD-NEXT: lui a0, %hi(G)
84 ; RV32IFD-NEXT: fld ft1, %lo(G)(a0)
85 ; RV32IFD-NEXT: fsd ft0, %lo(G)(a0)
86 ; RV32IFD-NEXT: addi a0, a0, %lo(G)
87 ; RV32IFD-NEXT: fld ft1, 72(a0)
88 ; RV32IFD-NEXT: fsd ft0, 72(a0)
89 ; RV32IFD-NEXT: fsd ft0, 8(sp)
90 ; RV32IFD-NEXT: lw a0, 8(sp)
91 ; RV32IFD-NEXT: lw a1, 12(sp)
92 ; RV32IFD-NEXT: addi sp, sp, 16
95 ; RV64IFD-LABEL: fld_fsd_global:
97 ; RV64IFD-NEXT: fmv.d.x ft0, a1
98 ; RV64IFD-NEXT: fmv.d.x ft1, a0
99 ; RV64IFD-NEXT: fadd.d ft0, ft1, ft0
100 ; RV64IFD-NEXT: lui a0, %hi(G)
101 ; RV64IFD-NEXT: fld ft1, %lo(G)(a0)
102 ; RV64IFD-NEXT: fsd ft0, %lo(G)(a0)
103 ; RV64IFD-NEXT: addi a1, a0, %lo(G)
104 ; RV64IFD-NEXT: fld ft1, 72(a1)
105 ; RV64IFD-NEXT: fmv.x.d a0, ft0
106 ; RV64IFD-NEXT: fsd ft0, 72(a1)
108 ; Use %a and %b in an FP op to ensure floating point registers are used, even
109 ; for the soft float ABI
110 %1 = fadd double %a, %b
111 %2 = load volatile double, double* @G
112 store double %1, double* @G
113 %3 = getelementptr double, double* @G, i32 9
114 %4 = load volatile double, double* %3
115 store double %1, double* %3
119 ; Ensure that 1 is added to the high 20 bits if bit 11 of the low part is 1
120 define dso_local double @fld_fsd_constant(double %a) nounwind {
121 ; RV32IFD-LABEL: fld_fsd_constant:
123 ; RV32IFD-NEXT: addi sp, sp, -16
124 ; RV32IFD-NEXT: sw a0, 8(sp)
125 ; RV32IFD-NEXT: sw a1, 12(sp)
126 ; RV32IFD-NEXT: fld ft0, 8(sp)
127 ; RV32IFD-NEXT: lui a0, 912092
128 ; RV32IFD-NEXT: fld ft1, -273(a0)
129 ; RV32IFD-NEXT: fadd.d ft0, ft0, ft1
130 ; RV32IFD-NEXT: fsd ft0, -273(a0)
131 ; RV32IFD-NEXT: fsd ft0, 8(sp)
132 ; RV32IFD-NEXT: lw a0, 8(sp)
133 ; RV32IFD-NEXT: lw a1, 12(sp)
134 ; RV32IFD-NEXT: addi sp, sp, 16
137 ; RV64IFD-LABEL: fld_fsd_constant:
139 ; RV64IFD-NEXT: lui a1, 228023
140 ; RV64IFD-NEXT: slli a1, a1, 2
141 ; RV64IFD-NEXT: fld ft0, -273(a1)
142 ; RV64IFD-NEXT: fmv.d.x ft1, a0
143 ; RV64IFD-NEXT: fadd.d ft0, ft1, ft0
144 ; RV64IFD-NEXT: fmv.x.d a0, ft0
145 ; RV64IFD-NEXT: fsd ft0, -273(a1)
147 %1 = inttoptr i32 3735928559 to double*
148 %2 = load volatile double, double* %1
149 %3 = fadd double %a, %2
150 store double %3, double* %1
154 declare void @notdead(i8*)
156 define dso_local double @fld_stack(double %a) nounwind {
157 ; RV32IFD-LABEL: fld_stack:
159 ; RV32IFD-NEXT: addi sp, sp, -32
160 ; RV32IFD-NEXT: sw ra, 28(sp) # 4-byte Folded Spill
161 ; RV32IFD-NEXT: sw a0, 8(sp)
162 ; RV32IFD-NEXT: sw a1, 12(sp)
163 ; RV32IFD-NEXT: fld ft0, 8(sp)
164 ; RV32IFD-NEXT: fsd ft0, 0(sp) # 8-byte Folded Spill
165 ; RV32IFD-NEXT: addi a0, sp, 16
166 ; RV32IFD-NEXT: call notdead@plt
167 ; RV32IFD-NEXT: fld ft0, 16(sp)
168 ; RV32IFD-NEXT: fld ft1, 0(sp) # 8-byte Folded Reload
169 ; RV32IFD-NEXT: fadd.d ft0, ft0, ft1
170 ; RV32IFD-NEXT: fsd ft0, 8(sp)
171 ; RV32IFD-NEXT: lw a0, 8(sp)
172 ; RV32IFD-NEXT: lw a1, 12(sp)
173 ; RV32IFD-NEXT: lw ra, 28(sp) # 4-byte Folded Reload
174 ; RV32IFD-NEXT: addi sp, sp, 32
177 ; RV64IFD-LABEL: fld_stack:
179 ; RV64IFD-NEXT: addi sp, sp, -32
180 ; RV64IFD-NEXT: sd ra, 24(sp) # 8-byte Folded Spill
181 ; RV64IFD-NEXT: fmv.d.x ft0, a0
182 ; RV64IFD-NEXT: fsd ft0, 8(sp) # 8-byte Folded Spill
183 ; RV64IFD-NEXT: addi a0, sp, 16
184 ; RV64IFD-NEXT: call notdead@plt
185 ; RV64IFD-NEXT: fld ft0, 16(sp)
186 ; RV64IFD-NEXT: fld ft1, 8(sp) # 8-byte Folded Reload
187 ; RV64IFD-NEXT: fadd.d ft0, ft0, ft1
188 ; RV64IFD-NEXT: fmv.x.d a0, ft0
189 ; RV64IFD-NEXT: ld ra, 24(sp) # 8-byte Folded Reload
190 ; RV64IFD-NEXT: addi sp, sp, 32
192 %1 = alloca double, align 8
193 %2 = bitcast double* %1 to i8*
194 call void @notdead(i8* %2)
195 %3 = load double, double* %1
196 %4 = fadd double %3, %a ; force load in to FPR64
200 define dso_local void @fsd_stack(double %a, double %b) nounwind {
201 ; RV32IFD-LABEL: fsd_stack:
203 ; RV32IFD-NEXT: addi sp, sp, -32
204 ; RV32IFD-NEXT: sw ra, 28(sp) # 4-byte Folded Spill
205 ; RV32IFD-NEXT: sw a2, 8(sp)
206 ; RV32IFD-NEXT: sw a3, 12(sp)
207 ; RV32IFD-NEXT: fld ft0, 8(sp)
208 ; RV32IFD-NEXT: sw a0, 8(sp)
209 ; RV32IFD-NEXT: sw a1, 12(sp)
210 ; RV32IFD-NEXT: fld ft1, 8(sp)
211 ; RV32IFD-NEXT: fadd.d ft0, ft1, ft0
212 ; RV32IFD-NEXT: fsd ft0, 16(sp)
213 ; RV32IFD-NEXT: addi a0, sp, 16
214 ; RV32IFD-NEXT: call notdead@plt
215 ; RV32IFD-NEXT: lw ra, 28(sp) # 4-byte Folded Reload
216 ; RV32IFD-NEXT: addi sp, sp, 32
219 ; RV64IFD-LABEL: fsd_stack:
221 ; RV64IFD-NEXT: addi sp, sp, -16
222 ; RV64IFD-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
223 ; RV64IFD-NEXT: fmv.d.x ft0, a1
224 ; RV64IFD-NEXT: fmv.d.x ft1, a0
225 ; RV64IFD-NEXT: fadd.d ft0, ft1, ft0
226 ; RV64IFD-NEXT: fsd ft0, 0(sp)
227 ; RV64IFD-NEXT: mv a0, sp
228 ; RV64IFD-NEXT: call notdead@plt
229 ; RV64IFD-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
230 ; RV64IFD-NEXT: addi sp, sp, 16
232 %1 = fadd double %a, %b ; force store from FPR64
233 %2 = alloca double, align 8
234 store double %1, double* %2
235 %3 = bitcast double* %2 to i8*
236 call void @notdead(i8* %3)
240 ; Test selection of store<ST4[%a], trunc to f32>, ..
241 define dso_local void @fsd_trunc(float* %a, double %b) nounwind noinline optnone {
242 ; RV32IFD-LABEL: fsd_trunc:
244 ; RV32IFD-NEXT: addi sp, sp, -16
245 ; RV32IFD-NEXT: sw a1, 8(sp)
246 ; RV32IFD-NEXT: sw a2, 12(sp)
247 ; RV32IFD-NEXT: fld ft0, 8(sp)
248 ; RV32IFD-NEXT: fcvt.s.d ft0, ft0
249 ; RV32IFD-NEXT: fsw ft0, 0(a0)
250 ; RV32IFD-NEXT: addi sp, sp, 16
253 ; RV64IFD-LABEL: fsd_trunc:
255 ; RV64IFD-NEXT: fmv.d.x ft0, a1
256 ; RV64IFD-NEXT: fcvt.s.d ft0, ft0
257 ; RV64IFD-NEXT: fsw ft0, 0(a0)
259 %1 = fptrunc double %b to float
260 store float %1, float* %a, align 4