1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv32 -global-isel -mattr=+d -verify-machineinstrs < %s \
3 ; RUN: -target-abi=ilp32d | FileCheck -check-prefixes=CHECKIFD,RV32IFD %s
4 ; RUN: llc -mtriple=riscv64 -global-isel -mattr=+d -verify-machineinstrs < %s \
5 ; RUN: -target-abi=lp64d | FileCheck -check-prefixes=CHECKIFD,RV64IFD %s
7 define float @fcvt_s_d(double %a) nounwind {
8 ; CHECKIFD-LABEL: fcvt_s_d:
10 ; CHECKIFD-NEXT: fcvt.s.d fa0, fa0
12 %1 = fptrunc double %a to float
16 define double @fcvt_d_s(float %a) nounwind {
17 ; CHECKIFD-LABEL: fcvt_d_s:
19 ; CHECKIFD-NEXT: fcvt.d.s fa0, fa0
21 %1 = fpext float %a to double
25 define i32 @fcvt_w_d(double %a) nounwind {
26 ; CHECKIFD-LABEL: fcvt_w_d:
28 ; CHECKIFD-NEXT: fcvt.w.d a0, fa0, rtz
30 %1 = fptosi double %a to i32
34 define i32 @fcvt_wu_d(double %a) nounwind {
35 ; CHECKIFD-LABEL: fcvt_wu_d:
37 ; CHECKIFD-NEXT: fcvt.wu.d a0, fa0, rtz
39 %1 = fptoui double %a to i32
43 define i32 @fcvt_wu_d_multiple_use(double %x, ptr %y) nounwind {
44 ; RV32IFD-LABEL: fcvt_wu_d_multiple_use:
46 ; RV32IFD-NEXT: fcvt.wu.d a1, fa0, rtz
47 ; RV32IFD-NEXT: li a0, 1
48 ; RV32IFD-NEXT: beqz a1, .LBB4_2
49 ; RV32IFD-NEXT: # %bb.1:
50 ; RV32IFD-NEXT: mv a0, a1
51 ; RV32IFD-NEXT: .LBB4_2:
54 ; RV64IFD-LABEL: fcvt_wu_d_multiple_use:
56 ; RV64IFD-NEXT: fcvt.wu.d a1, fa0, rtz
57 ; RV64IFD-NEXT: slli a0, a1, 32
58 ; RV64IFD-NEXT: srli a2, a0, 32
59 ; RV64IFD-NEXT: li a0, 1
60 ; RV64IFD-NEXT: beqz a2, .LBB4_2
61 ; RV64IFD-NEXT: # %bb.1:
62 ; RV64IFD-NEXT: mv a0, a1
63 ; RV64IFD-NEXT: .LBB4_2:
65 %a = fptoui double %x to i32
66 %b = icmp eq i32 %a, 0
67 %c = select i1 %b, i32 1, i32 %a
71 define double @fcvt_d_w(i32 %a) nounwind {
72 ; CHECKIFD-LABEL: fcvt_d_w:
74 ; CHECKIFD-NEXT: fcvt.d.w fa0, a0
76 %1 = sitofp i32 %a to double
80 define double @fcvt_d_w_load(ptr %p) nounwind {
81 ; CHECKIFD-LABEL: fcvt_d_w_load:
83 ; CHECKIFD-NEXT: lw a0, 0(a0)
84 ; CHECKIFD-NEXT: fcvt.d.w fa0, a0
87 %1 = sitofp i32 %a to double
91 define double @fcvt_d_wu(i32 %a) nounwind {
92 ; CHECKIFD-LABEL: fcvt_d_wu:
94 ; CHECKIFD-NEXT: fcvt.d.wu fa0, a0
96 %1 = uitofp i32 %a to double
100 define double @fcvt_d_wu_load(ptr %p) nounwind {
101 ; RV32IFD-LABEL: fcvt_d_wu_load:
103 ; RV32IFD-NEXT: lw a0, 0(a0)
104 ; RV32IFD-NEXT: fcvt.d.wu fa0, a0
107 ; RV64IFD-LABEL: fcvt_d_wu_load:
109 ; RV64IFD-NEXT: lwu a0, 0(a0)
110 ; RV64IFD-NEXT: fcvt.d.wu fa0, a0
112 %a = load i32, ptr %p
113 %1 = uitofp i32 %a to double
117 define i64 @fcvt_l_d(double %a) nounwind {
118 ; RV32IFD-LABEL: fcvt_l_d:
120 ; RV32IFD-NEXT: addi sp, sp, -16
121 ; RV32IFD-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
122 ; RV32IFD-NEXT: call __fixdfdi
123 ; RV32IFD-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
124 ; RV32IFD-NEXT: addi sp, sp, 16
127 ; RV64IFD-LABEL: fcvt_l_d:
129 ; RV64IFD-NEXT: fcvt.l.d a0, fa0, rtz
131 %1 = fptosi double %a to i64
135 define i64 @fcvt_lu_d(double %a) nounwind {
136 ; RV32IFD-LABEL: fcvt_lu_d:
138 ; RV32IFD-NEXT: addi sp, sp, -16
139 ; RV32IFD-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
140 ; RV32IFD-NEXT: call __fixunsdfdi
141 ; RV32IFD-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
142 ; RV32IFD-NEXT: addi sp, sp, 16
145 ; RV64IFD-LABEL: fcvt_lu_d:
147 ; RV64IFD-NEXT: fcvt.lu.d a0, fa0, rtz
149 %1 = fptoui double %a to i64
153 define i64 @fmv_x_d(double %a, double %b) nounwind {
154 ; RV32IFD-LABEL: fmv_x_d:
156 ; RV32IFD-NEXT: addi sp, sp, -16
157 ; RV32IFD-NEXT: fadd.d fa5, fa0, fa1
158 ; RV32IFD-NEXT: fsd fa5, 8(sp)
159 ; RV32IFD-NEXT: lw a0, 8(sp)
160 ; RV32IFD-NEXT: lw a1, 12(sp)
161 ; RV32IFD-NEXT: addi sp, sp, 16
164 ; RV64IFD-LABEL: fmv_x_d:
166 ; RV64IFD-NEXT: fadd.d fa5, fa0, fa1
167 ; RV64IFD-NEXT: fmv.x.d a0, fa5
169 %1 = fadd double %a, %b
170 %2 = bitcast double %1 to i64
174 define double @fcvt_d_l(i64 %a) nounwind {
175 ; RV32IFD-LABEL: fcvt_d_l:
177 ; RV32IFD-NEXT: addi sp, sp, -16
178 ; RV32IFD-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
179 ; RV32IFD-NEXT: call __floatdidf
180 ; RV32IFD-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
181 ; RV32IFD-NEXT: addi sp, sp, 16
184 ; RV64IFD-LABEL: fcvt_d_l:
186 ; RV64IFD-NEXT: fcvt.d.l fa0, a0
188 %1 = sitofp i64 %a to double
192 define double @fcvt_d_lu(i64 %a) nounwind {
193 ; RV32IFD-LABEL: fcvt_d_lu:
195 ; RV32IFD-NEXT: addi sp, sp, -16
196 ; RV32IFD-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
197 ; RV32IFD-NEXT: call __floatundidf
198 ; RV32IFD-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
199 ; RV32IFD-NEXT: addi sp, sp, 16
202 ; RV64IFD-LABEL: fcvt_d_lu:
204 ; RV64IFD-NEXT: fcvt.d.lu fa0, a0
206 %1 = uitofp i64 %a to double
210 define double @fmv_d_x(i64 %a, i64 %b) nounwind {
211 ; RV32IFD-LABEL: fmv_d_x:
213 ; RV32IFD-NEXT: addi sp, sp, -16
214 ; RV32IFD-NEXT: sw a0, 8(sp)
215 ; RV32IFD-NEXT: sw a1, 12(sp)
216 ; RV32IFD-NEXT: fld fa5, 8(sp)
217 ; RV32IFD-NEXT: sw a2, 8(sp)
218 ; RV32IFD-NEXT: sw a3, 12(sp)
219 ; RV32IFD-NEXT: fld fa4, 8(sp)
220 ; RV32IFD-NEXT: fadd.d fa0, fa5, fa4
221 ; RV32IFD-NEXT: addi sp, sp, 16
224 ; RV64IFD-LABEL: fmv_d_x:
226 ; RV64IFD-NEXT: fmv.d.x fa5, a0
227 ; RV64IFD-NEXT: fmv.d.x fa4, a1
228 ; RV64IFD-NEXT: fadd.d fa0, fa5, fa4
230 %1 = bitcast i64 %a to double
231 %2 = bitcast i64 %b to double
232 %3 = fadd double %1, %2
236 define double @fcvt_d_w_i8(i8 signext %a) nounwind {
237 ; CHECKIFD-LABEL: fcvt_d_w_i8:
239 ; CHECKIFD-NEXT: fcvt.d.w fa0, a0
241 %1 = sitofp i8 %a to double
245 define double @fcvt_d_wu_i8(i8 zeroext %a) nounwind {
246 ; CHECKIFD-LABEL: fcvt_d_wu_i8:
248 ; CHECKIFD-NEXT: fcvt.d.wu fa0, a0
250 %1 = uitofp i8 %a to double
254 define double @fcvt_d_w_i16(i16 signext %a) nounwind {
255 ; CHECKIFD-LABEL: fcvt_d_w_i16:
257 ; CHECKIFD-NEXT: fcvt.d.w fa0, a0
259 %1 = sitofp i16 %a to double
263 define double @fcvt_d_wu_i16(i16 zeroext %a) nounwind {
264 ; CHECKIFD-LABEL: fcvt_d_wu_i16:
266 ; CHECKIFD-NEXT: fcvt.d.wu fa0, a0
268 %1 = uitofp i16 %a to double
272 define signext i32 @fcvt_d_w_demanded_bits(i32 signext %0, ptr %1) nounwind {
273 ; RV32IFD-LABEL: fcvt_d_w_demanded_bits:
275 ; RV32IFD-NEXT: addi a0, a0, 1
276 ; RV32IFD-NEXT: fcvt.d.w fa5, a0
277 ; RV32IFD-NEXT: fsd fa5, 0(a1)
280 ; RV64IFD-LABEL: fcvt_d_w_demanded_bits:
282 ; RV64IFD-NEXT: addiw a0, a0, 1
283 ; RV64IFD-NEXT: fcvt.d.w fa5, a0
284 ; RV64IFD-NEXT: fsd fa5, 0(a1)
287 %4 = sitofp i32 %3 to double
288 store double %4, ptr %1, align 8
292 define signext i32 @fcvt_d_wu_demanded_bits(i32 signext %0, ptr %1) nounwind {
293 ; RV32IFD-LABEL: fcvt_d_wu_demanded_bits:
295 ; RV32IFD-NEXT: addi a0, a0, 1
296 ; RV32IFD-NEXT: fcvt.d.wu fa5, a0
297 ; RV32IFD-NEXT: fsd fa5, 0(a1)
300 ; RV64IFD-LABEL: fcvt_d_wu_demanded_bits:
302 ; RV64IFD-NEXT: addiw a0, a0, 1
303 ; RV64IFD-NEXT: fcvt.d.wu fa5, a0
304 ; RV64IFD-NEXT: fsd fa5, 0(a1)
307 %4 = uitofp i32 %3 to double
308 store double %4, ptr %1, align 8
312 define signext i16 @fcvt_w_s_i16(double %a) nounwind {
313 ; RV32IFD-LABEL: fcvt_w_s_i16:
315 ; RV32IFD-NEXT: fcvt.w.d a0, fa0, rtz
316 ; RV32IFD-NEXT: slli a0, a0, 16
317 ; RV32IFD-NEXT: srai a0, a0, 16
320 ; RV64IFD-LABEL: fcvt_w_s_i16:
322 ; RV64IFD-NEXT: fcvt.w.d a0, fa0, rtz
323 ; RV64IFD-NEXT: slli a0, a0, 48
324 ; RV64IFD-NEXT: srai a0, a0, 48
326 %1 = fptosi double %a to i16
330 define zeroext i16 @fcvt_wu_s_i16(double %a) nounwind {
331 ; RV32IFD-LABEL: fcvt_wu_s_i16:
333 ; RV32IFD-NEXT: fcvt.wu.d a0, fa0, rtz
334 ; RV32IFD-NEXT: lui a1, 16
335 ; RV32IFD-NEXT: addi a1, a1, -1
336 ; RV32IFD-NEXT: and a0, a0, a1
339 ; RV64IFD-LABEL: fcvt_wu_s_i16:
341 ; RV64IFD-NEXT: fcvt.wu.d a0, fa0, rtz
342 ; RV64IFD-NEXT: lui a1, 16
343 ; RV64IFD-NEXT: addiw a1, a1, -1
344 ; RV64IFD-NEXT: and a0, a0, a1
346 %1 = fptoui double %a to i16
350 define signext i8 @fcvt_w_s_i8(double %a) nounwind {
351 ; RV32IFD-LABEL: fcvt_w_s_i8:
353 ; RV32IFD-NEXT: fcvt.w.d a0, fa0, rtz
354 ; RV32IFD-NEXT: slli a0, a0, 24
355 ; RV32IFD-NEXT: srai a0, a0, 24
358 ; RV64IFD-LABEL: fcvt_w_s_i8:
360 ; RV64IFD-NEXT: fcvt.w.d a0, fa0, rtz
361 ; RV64IFD-NEXT: slli a0, a0, 56
362 ; RV64IFD-NEXT: srai a0, a0, 56
364 %1 = fptosi double %a to i8
368 define zeroext i8 @fcvt_wu_s_i8(double %a) nounwind {
369 ; CHECKIFD-LABEL: fcvt_wu_s_i8:
371 ; CHECKIFD-NEXT: fcvt.wu.d a0, fa0, rtz
372 ; CHECKIFD-NEXT: andi a0, a0, 255
374 %1 = fptoui double %a to i8