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 double @fld(double *%a) nounwind {
10 ; RV32IFD-NEXT: addi sp, sp, -16
11 ; RV32IFD-NEXT: fld ft0, 24(a0)
12 ; RV32IFD-NEXT: fld ft1, 0(a0)
13 ; RV32IFD-NEXT: fadd.d ft0, ft1, ft0
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, 24(a0)
23 ; RV64IFD-NEXT: fld ft1, 0(a0)
24 ; RV64IFD-NEXT: fadd.d ft0, ft1, ft0
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 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, 64(a0)
48 ; RV32IFD-NEXT: fsd ft0, 0(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, 64(a0)
58 ; RV64IFD-NEXT: fsd ft0, 0(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 = global double 0.0
72 define 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 a0, a0, %lo(G)
104 ; RV64IFD-NEXT: fld ft1, 72(a0)
105 ; RV64IFD-NEXT: fsd ft0, 72(a0)
106 ; RV64IFD-NEXT: fmv.x.d a0, ft0
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 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: fmv.d.x ft0, a0
140 ; RV64IFD-NEXT: lui a0, 56
141 ; RV64IFD-NEXT: addiw a0, a0, -1353
142 ; RV64IFD-NEXT: slli a0, a0, 14
143 ; RV64IFD-NEXT: fld ft1, -273(a0)
144 ; RV64IFD-NEXT: fadd.d ft0, ft0, ft1
145 ; RV64IFD-NEXT: fsd ft0, -273(a0)
146 ; RV64IFD-NEXT: fmv.x.d a0, ft0
148 %1 = inttoptr i32 3735928559 to double*
149 %2 = load volatile double, double* %1
150 %3 = fadd double %a, %2
151 store double %3, double* %1
155 declare void @notdead(i8*)
157 define double @fld_stack(double %a) nounwind {
158 ; RV32IFD-LABEL: fld_stack:
160 ; RV32IFD-NEXT: addi sp, sp, -32
161 ; RV32IFD-NEXT: sw ra, 28(sp)
162 ; RV32IFD-NEXT: sw s0, 24(sp)
163 ; RV32IFD-NEXT: sw s1, 20(sp)
164 ; RV32IFD-NEXT: mv s0, a1
165 ; RV32IFD-NEXT: mv s1, a0
166 ; RV32IFD-NEXT: addi a0, sp, 8
167 ; RV32IFD-NEXT: call notdead
168 ; RV32IFD-NEXT: sw s1, 0(sp)
169 ; RV32IFD-NEXT: sw s0, 4(sp)
170 ; RV32IFD-NEXT: fld ft0, 0(sp)
171 ; RV32IFD-NEXT: fld ft1, 8(sp)
172 ; RV32IFD-NEXT: fadd.d ft0, ft1, ft0
173 ; RV32IFD-NEXT: fsd ft0, 0(sp)
174 ; RV32IFD-NEXT: lw a0, 0(sp)
175 ; RV32IFD-NEXT: lw a1, 4(sp)
176 ; RV32IFD-NEXT: lw s1, 20(sp)
177 ; RV32IFD-NEXT: lw s0, 24(sp)
178 ; RV32IFD-NEXT: lw ra, 28(sp)
179 ; RV32IFD-NEXT: addi sp, sp, 32
182 ; RV64IFD-LABEL: fld_stack:
184 ; RV64IFD-NEXT: addi sp, sp, -32
185 ; RV64IFD-NEXT: sd ra, 24(sp)
186 ; RV64IFD-NEXT: sd s0, 16(sp)
187 ; RV64IFD-NEXT: mv s0, a0
188 ; RV64IFD-NEXT: addi a0, sp, 8
189 ; RV64IFD-NEXT: call notdead
190 ; RV64IFD-NEXT: fmv.d.x ft0, s0
191 ; RV64IFD-NEXT: fld ft1, 8(sp)
192 ; RV64IFD-NEXT: fadd.d ft0, ft1, ft0
193 ; RV64IFD-NEXT: fmv.x.d a0, ft0
194 ; RV64IFD-NEXT: ld s0, 16(sp)
195 ; RV64IFD-NEXT: ld ra, 24(sp)
196 ; RV64IFD-NEXT: addi sp, sp, 32
198 %1 = alloca double, align 8
199 %2 = bitcast double* %1 to i8*
200 call void @notdead(i8* %2)
201 %3 = load double, double* %1
202 %4 = fadd double %3, %a ; force load in to FPR64
206 define void @fsd_stack(double %a, double %b) nounwind {
207 ; RV32IFD-LABEL: fsd_stack:
209 ; RV32IFD-NEXT: addi sp, sp, -32
210 ; RV32IFD-NEXT: sw ra, 28(sp)
211 ; RV32IFD-NEXT: sw a2, 8(sp)
212 ; RV32IFD-NEXT: sw a3, 12(sp)
213 ; RV32IFD-NEXT: fld ft0, 8(sp)
214 ; RV32IFD-NEXT: sw a0, 8(sp)
215 ; RV32IFD-NEXT: sw a1, 12(sp)
216 ; RV32IFD-NEXT: fld ft1, 8(sp)
217 ; RV32IFD-NEXT: fadd.d ft0, ft1, ft0
218 ; RV32IFD-NEXT: fsd ft0, 16(sp)
219 ; RV32IFD-NEXT: addi a0, sp, 16
220 ; RV32IFD-NEXT: call notdead
221 ; RV32IFD-NEXT: lw ra, 28(sp)
222 ; RV32IFD-NEXT: addi sp, sp, 32
225 ; RV64IFD-LABEL: fsd_stack:
227 ; RV64IFD-NEXT: addi sp, sp, -16
228 ; RV64IFD-NEXT: sd ra, 8(sp)
229 ; RV64IFD-NEXT: fmv.d.x ft0, a1
230 ; RV64IFD-NEXT: fmv.d.x ft1, a0
231 ; RV64IFD-NEXT: fadd.d ft0, ft1, ft0
232 ; RV64IFD-NEXT: fsd ft0, 0(sp)
233 ; RV64IFD-NEXT: mv a0, sp
234 ; RV64IFD-NEXT: call notdead
235 ; RV64IFD-NEXT: ld ra, 8(sp)
236 ; RV64IFD-NEXT: addi sp, sp, 16
238 %1 = fadd double %a, %b ; force store from FPR64
239 %2 = alloca double, align 8
240 store double %1, double* %2
241 %3 = bitcast double* %2 to i8*
242 call void @notdead(i8* %3)
246 ; Test selection of store<ST4[%a], trunc to f32>, ..
247 define void @fsd_trunc(float* %a, double %b) nounwind noinline optnone {
248 ; RV32IFD-LABEL: fsd_trunc:
250 ; RV32IFD-NEXT: addi sp, sp, -16
251 ; RV32IFD-NEXT: sw a1, 8(sp)
252 ; RV32IFD-NEXT: sw a2, 12(sp)
253 ; RV32IFD-NEXT: fld ft0, 8(sp)
254 ; RV32IFD-NEXT: fcvt.s.d ft0, ft0
255 ; RV32IFD-NEXT: fsw ft0, 0(a0)
256 ; RV32IFD-NEXT: addi sp, sp, 16
259 ; RV64IFD-LABEL: fsd_trunc:
261 ; RV64IFD-NEXT: fmv.d.x ft0, a1
262 ; RV64IFD-NEXT: fcvt.s.d ft0, ft0
263 ; RV64IFD-NEXT: fsw ft0, 0(a0)
265 %1 = fptrunc double %b to float
266 store float %1, float* %a, align 4