1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv32 -mattr=+f -target-abi=ilp32 -verify-machineinstrs < %s \
3 ; RUN: | FileCheck -check-prefix=RV32F %s
4 ; RUN: llc -mtriple=riscv32 -mattr=+f,+d -target-abi=ilp32 -verify-machineinstrs < %s \
5 ; RUN: | FileCheck -check-prefix=RV32FD %s
6 ; RUN: llc -mtriple=riscv64 -mattr=+f -target-abi=lp64 -verify-machineinstrs < %s \
7 ; RUN: | FileCheck -check-prefix=RV64F %s
8 ; RUN: llc -mtriple=riscv64 -mattr=+f,+d -target-abi=lp64 -verify-machineinstrs < %s \
9 ; RUN: | FileCheck -check-prefix=RV64FD %s
11 ; These functions perform extra work to ensure that `%a3` starts in a
12 ; floating-point register, if the machine has them, and the result of
13 ; the bitwise operation is then needed in a floating-point register.
14 ; This should mean the optimisations will fire even if you're using the
15 ; soft-float ABI on a machine with hardware floating-point support.
17 define float @bitcast_and(float %a1, float %a2) nounwind {
18 ; RV32F-LABEL: bitcast_and:
20 ; RV32F-NEXT: fmv.w.x ft0, a1
21 ; RV32F-NEXT: fmv.w.x ft1, a0
22 ; RV32F-NEXT: fadd.s ft0, ft1, ft0
23 ; RV32F-NEXT: fabs.s ft0, ft0
24 ; RV32F-NEXT: fadd.s ft0, ft1, ft0
25 ; RV32F-NEXT: fmv.x.w a0, ft0
28 ; RV32FD-LABEL: bitcast_and:
30 ; RV32FD-NEXT: fmv.w.x ft0, a1
31 ; RV32FD-NEXT: fmv.w.x ft1, a0
32 ; RV32FD-NEXT: fadd.s ft0, ft1, ft0
33 ; RV32FD-NEXT: fabs.s ft0, ft0
34 ; RV32FD-NEXT: fadd.s ft0, ft1, ft0
35 ; RV32FD-NEXT: fmv.x.w a0, ft0
38 ; RV64F-LABEL: bitcast_and:
40 ; RV64F-NEXT: fmv.w.x ft0, a1
41 ; RV64F-NEXT: fmv.w.x ft1, a0
42 ; RV64F-NEXT: fadd.s ft0, ft1, ft0
43 ; RV64F-NEXT: fabs.s ft0, ft0
44 ; RV64F-NEXT: fadd.s ft0, ft1, ft0
45 ; RV64F-NEXT: fmv.x.w a0, ft0
48 ; RV64FD-LABEL: bitcast_and:
50 ; RV64FD-NEXT: fmv.w.x ft0, a1
51 ; RV64FD-NEXT: fmv.w.x ft1, a0
52 ; RV64FD-NEXT: fadd.s ft0, ft1, ft0
53 ; RV64FD-NEXT: fabs.s ft0, ft0
54 ; RV64FD-NEXT: fadd.s ft0, ft1, ft0
55 ; RV64FD-NEXT: fmv.x.w a0, ft0
57 %a3 = fadd float %a1, %a2
58 %bc1 = bitcast float %a3 to i32
59 %and = and i32 %bc1, 2147483647
60 %bc2 = bitcast i32 %and to float
61 %a4 = fadd float %a1, %bc2
65 define double @bitcast_double_and(double %a1, double %a2) nounwind {
66 ; RV32F-LABEL: bitcast_double_and:
68 ; RV32F-NEXT: addi sp, sp, -16
69 ; RV32F-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
70 ; RV32F-NEXT: sw s0, 8(sp) # 4-byte Folded Spill
71 ; RV32F-NEXT: sw s1, 4(sp) # 4-byte Folded Spill
72 ; RV32F-NEXT: mv s0, a1
73 ; RV32F-NEXT: mv s1, a0
74 ; RV32F-NEXT: call __adddf3@plt
75 ; RV32F-NEXT: mv a2, a0
76 ; RV32F-NEXT: slli a0, a1, 1
77 ; RV32F-NEXT: srli a3, a0, 1
78 ; RV32F-NEXT: mv a0, s1
79 ; RV32F-NEXT: mv a1, s0
80 ; RV32F-NEXT: call __adddf3@plt
81 ; RV32F-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
82 ; RV32F-NEXT: lw s0, 8(sp) # 4-byte Folded Reload
83 ; RV32F-NEXT: lw s1, 4(sp) # 4-byte Folded Reload
84 ; RV32F-NEXT: addi sp, sp, 16
87 ; RV32FD-LABEL: bitcast_double_and:
89 ; RV32FD-NEXT: addi sp, sp, -16
90 ; RV32FD-NEXT: sw a2, 8(sp)
91 ; RV32FD-NEXT: sw a3, 12(sp)
92 ; RV32FD-NEXT: fld ft0, 8(sp)
93 ; RV32FD-NEXT: sw a0, 8(sp)
94 ; RV32FD-NEXT: sw a1, 12(sp)
95 ; RV32FD-NEXT: fld ft1, 8(sp)
96 ; RV32FD-NEXT: fadd.d ft0, ft1, ft0
97 ; RV32FD-NEXT: fabs.d ft0, ft0
98 ; RV32FD-NEXT: fadd.d ft0, ft1, ft0
99 ; RV32FD-NEXT: fsd ft0, 8(sp)
100 ; RV32FD-NEXT: lw a0, 8(sp)
101 ; RV32FD-NEXT: lw a1, 12(sp)
102 ; RV32FD-NEXT: addi sp, sp, 16
105 ; RV64F-LABEL: bitcast_double_and:
107 ; RV64F-NEXT: addi sp, sp, -16
108 ; RV64F-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
109 ; RV64F-NEXT: sd s0, 0(sp) # 8-byte Folded Spill
110 ; RV64F-NEXT: mv s0, a0
111 ; RV64F-NEXT: call __adddf3@plt
112 ; RV64F-NEXT: slli a0, a0, 1
113 ; RV64F-NEXT: srli a1, a0, 1
114 ; RV64F-NEXT: mv a0, s0
115 ; RV64F-NEXT: call __adddf3@plt
116 ; RV64F-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
117 ; RV64F-NEXT: ld s0, 0(sp) # 8-byte Folded Reload
118 ; RV64F-NEXT: addi sp, sp, 16
121 ; RV64FD-LABEL: bitcast_double_and:
123 ; RV64FD-NEXT: fmv.d.x ft0, a1
124 ; RV64FD-NEXT: fmv.d.x ft1, a0
125 ; RV64FD-NEXT: fadd.d ft0, ft1, ft0
126 ; RV64FD-NEXT: fabs.d ft0, ft0
127 ; RV64FD-NEXT: fadd.d ft0, ft1, ft0
128 ; RV64FD-NEXT: fmv.x.d a0, ft0
130 %a3 = fadd double %a1, %a2
131 %bc1 = bitcast double %a3 to i64
132 %and = and i64 %bc1, 9223372036854775807
133 %bc2 = bitcast i64 %and to double
134 %a4 = fadd double %a1, %bc2
139 define float @bitcast_xor(float %a1, float %a2) nounwind {
140 ; RV32F-LABEL: bitcast_xor:
142 ; RV32F-NEXT: fmv.w.x ft0, a1
143 ; RV32F-NEXT: fmv.w.x ft1, a0
144 ; RV32F-NEXT: fmul.s ft0, ft1, ft0
145 ; RV32F-NEXT: fneg.s ft0, ft0
146 ; RV32F-NEXT: fmul.s ft0, ft1, ft0
147 ; RV32F-NEXT: fmv.x.w a0, ft0
150 ; RV32FD-LABEL: bitcast_xor:
152 ; RV32FD-NEXT: fmv.w.x ft0, a1
153 ; RV32FD-NEXT: fmv.w.x ft1, a0
154 ; RV32FD-NEXT: fmul.s ft0, ft1, ft0
155 ; RV32FD-NEXT: fneg.s ft0, ft0
156 ; RV32FD-NEXT: fmul.s ft0, ft1, ft0
157 ; RV32FD-NEXT: fmv.x.w a0, ft0
160 ; RV64F-LABEL: bitcast_xor:
162 ; RV64F-NEXT: fmv.w.x ft0, a1
163 ; RV64F-NEXT: fmv.w.x ft1, a0
164 ; RV64F-NEXT: fmul.s ft0, ft1, ft0
165 ; RV64F-NEXT: fneg.s ft0, ft0
166 ; RV64F-NEXT: fmul.s ft0, ft1, ft0
167 ; RV64F-NEXT: fmv.x.w a0, ft0
170 ; RV64FD-LABEL: bitcast_xor:
172 ; RV64FD-NEXT: fmv.w.x ft0, a1
173 ; RV64FD-NEXT: fmv.w.x ft1, a0
174 ; RV64FD-NEXT: fmul.s ft0, ft1, ft0
175 ; RV64FD-NEXT: fneg.s ft0, ft0
176 ; RV64FD-NEXT: fmul.s ft0, ft1, ft0
177 ; RV64FD-NEXT: fmv.x.w a0, ft0
179 %a3 = fmul float %a1, %a2
180 %bc1 = bitcast float %a3 to i32
181 %and = xor i32 %bc1, 2147483648
182 %bc2 = bitcast i32 %and to float
183 %a4 = fmul float %a1, %bc2
187 define double @bitcast_double_xor(double %a1, double %a2) nounwind {
188 ; RV32F-LABEL: bitcast_double_xor:
190 ; RV32F-NEXT: addi sp, sp, -16
191 ; RV32F-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
192 ; RV32F-NEXT: sw s0, 8(sp) # 4-byte Folded Spill
193 ; RV32F-NEXT: sw s1, 4(sp) # 4-byte Folded Spill
194 ; RV32F-NEXT: mv s0, a1
195 ; RV32F-NEXT: mv s1, a0
196 ; RV32F-NEXT: call __muldf3@plt
197 ; RV32F-NEXT: mv a2, a0
198 ; RV32F-NEXT: lui a0, 524288
199 ; RV32F-NEXT: xor a3, a1, a0
200 ; RV32F-NEXT: mv a0, s1
201 ; RV32F-NEXT: mv a1, s0
202 ; RV32F-NEXT: call __muldf3@plt
203 ; RV32F-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
204 ; RV32F-NEXT: lw s0, 8(sp) # 4-byte Folded Reload
205 ; RV32F-NEXT: lw s1, 4(sp) # 4-byte Folded Reload
206 ; RV32F-NEXT: addi sp, sp, 16
209 ; RV32FD-LABEL: bitcast_double_xor:
211 ; RV32FD-NEXT: addi sp, sp, -16
212 ; RV32FD-NEXT: sw a2, 8(sp)
213 ; RV32FD-NEXT: sw a3, 12(sp)
214 ; RV32FD-NEXT: fld ft0, 8(sp)
215 ; RV32FD-NEXT: sw a0, 8(sp)
216 ; RV32FD-NEXT: sw a1, 12(sp)
217 ; RV32FD-NEXT: fld ft1, 8(sp)
218 ; RV32FD-NEXT: fmul.d ft0, ft1, ft0
219 ; RV32FD-NEXT: fneg.d ft0, ft0
220 ; RV32FD-NEXT: fmul.d ft0, ft1, ft0
221 ; RV32FD-NEXT: fsd ft0, 8(sp)
222 ; RV32FD-NEXT: lw a0, 8(sp)
223 ; RV32FD-NEXT: lw a1, 12(sp)
224 ; RV32FD-NEXT: addi sp, sp, 16
227 ; RV64F-LABEL: bitcast_double_xor:
229 ; RV64F-NEXT: addi sp, sp, -16
230 ; RV64F-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
231 ; RV64F-NEXT: sd s0, 0(sp) # 8-byte Folded Spill
232 ; RV64F-NEXT: mv s0, a0
233 ; RV64F-NEXT: call __muldf3@plt
234 ; RV64F-NEXT: li a1, -1
235 ; RV64F-NEXT: slli a1, a1, 63
236 ; RV64F-NEXT: xor a1, a0, a1
237 ; RV64F-NEXT: mv a0, s0
238 ; RV64F-NEXT: call __muldf3@plt
239 ; RV64F-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
240 ; RV64F-NEXT: ld s0, 0(sp) # 8-byte Folded Reload
241 ; RV64F-NEXT: addi sp, sp, 16
244 ; RV64FD-LABEL: bitcast_double_xor:
246 ; RV64FD-NEXT: fmv.d.x ft0, a1
247 ; RV64FD-NEXT: fmv.d.x ft1, a0
248 ; RV64FD-NEXT: fmul.d ft0, ft1, ft0
249 ; RV64FD-NEXT: fneg.d ft0, ft0
250 ; RV64FD-NEXT: fmul.d ft0, ft1, ft0
251 ; RV64FD-NEXT: fmv.x.d a0, ft0
253 %a3 = fmul double %a1, %a2
254 %bc1 = bitcast double %a3 to i64
255 %and = xor i64 %bc1, 9223372036854775808
256 %bc2 = bitcast i64 %and to double
257 %a4 = fmul double %a1, %bc2
261 define float @bitcast_or(float %a1, float %a2) nounwind {
262 ; RV32F-LABEL: bitcast_or:
264 ; RV32F-NEXT: fmv.w.x ft0, a1
265 ; RV32F-NEXT: fmv.w.x ft1, a0
266 ; RV32F-NEXT: fmul.s ft0, ft1, ft0
267 ; RV32F-NEXT: fabs.s ft0, ft0
268 ; RV32F-NEXT: fneg.s ft0, ft0
269 ; RV32F-NEXT: fmul.s ft0, ft1, ft0
270 ; RV32F-NEXT: fmv.x.w a0, ft0
273 ; RV32FD-LABEL: bitcast_or:
275 ; RV32FD-NEXT: fmv.w.x ft0, a1
276 ; RV32FD-NEXT: fmv.w.x ft1, a0
277 ; RV32FD-NEXT: fmul.s ft0, ft1, ft0
278 ; RV32FD-NEXT: fabs.s ft0, ft0
279 ; RV32FD-NEXT: fneg.s ft0, ft0
280 ; RV32FD-NEXT: fmul.s ft0, ft1, ft0
281 ; RV32FD-NEXT: fmv.x.w a0, ft0
284 ; RV64F-LABEL: bitcast_or:
286 ; RV64F-NEXT: fmv.w.x ft0, a1
287 ; RV64F-NEXT: fmv.w.x ft1, a0
288 ; RV64F-NEXT: fmul.s ft0, ft1, ft0
289 ; RV64F-NEXT: fabs.s ft0, ft0
290 ; RV64F-NEXT: fneg.s ft0, ft0
291 ; RV64F-NEXT: fmul.s ft0, ft1, ft0
292 ; RV64F-NEXT: fmv.x.w a0, ft0
295 ; RV64FD-LABEL: bitcast_or:
297 ; RV64FD-NEXT: fmv.w.x ft0, a1
298 ; RV64FD-NEXT: fmv.w.x ft1, a0
299 ; RV64FD-NEXT: fmul.s ft0, ft1, ft0
300 ; RV64FD-NEXT: fabs.s ft0, ft0
301 ; RV64FD-NEXT: fneg.s ft0, ft0
302 ; RV64FD-NEXT: fmul.s ft0, ft1, ft0
303 ; RV64FD-NEXT: fmv.x.w a0, ft0
305 %a3 = fmul float %a1, %a2
306 %bc1 = bitcast float %a3 to i32
307 %and = or i32 %bc1, 2147483648
308 %bc2 = bitcast i32 %and to float
309 %a4 = fmul float %a1, %bc2
313 define double @bitcast_double_or(double %a1, double %a2) nounwind {
314 ; RV32F-LABEL: bitcast_double_or:
316 ; RV32F-NEXT: addi sp, sp, -16
317 ; RV32F-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
318 ; RV32F-NEXT: sw s0, 8(sp) # 4-byte Folded Spill
319 ; RV32F-NEXT: sw s1, 4(sp) # 4-byte Folded Spill
320 ; RV32F-NEXT: mv s0, a1
321 ; RV32F-NEXT: mv s1, a0
322 ; RV32F-NEXT: call __muldf3@plt
323 ; RV32F-NEXT: mv a2, a0
324 ; RV32F-NEXT: lui a0, 524288
325 ; RV32F-NEXT: or a3, a1, a0
326 ; RV32F-NEXT: mv a0, s1
327 ; RV32F-NEXT: mv a1, s0
328 ; RV32F-NEXT: call __muldf3@plt
329 ; RV32F-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
330 ; RV32F-NEXT: lw s0, 8(sp) # 4-byte Folded Reload
331 ; RV32F-NEXT: lw s1, 4(sp) # 4-byte Folded Reload
332 ; RV32F-NEXT: addi sp, sp, 16
335 ; RV32FD-LABEL: bitcast_double_or:
337 ; RV32FD-NEXT: addi sp, sp, -16
338 ; RV32FD-NEXT: sw a2, 8(sp)
339 ; RV32FD-NEXT: sw a3, 12(sp)
340 ; RV32FD-NEXT: fld ft0, 8(sp)
341 ; RV32FD-NEXT: sw a0, 8(sp)
342 ; RV32FD-NEXT: sw a1, 12(sp)
343 ; RV32FD-NEXT: fld ft1, 8(sp)
344 ; RV32FD-NEXT: fmul.d ft0, ft1, ft0
345 ; RV32FD-NEXT: fabs.d ft0, ft0
346 ; RV32FD-NEXT: fneg.d ft0, ft0
347 ; RV32FD-NEXT: fmul.d ft0, ft1, ft0
348 ; RV32FD-NEXT: fsd ft0, 8(sp)
349 ; RV32FD-NEXT: lw a0, 8(sp)
350 ; RV32FD-NEXT: lw a1, 12(sp)
351 ; RV32FD-NEXT: addi sp, sp, 16
354 ; RV64F-LABEL: bitcast_double_or:
356 ; RV64F-NEXT: addi sp, sp, -16
357 ; RV64F-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
358 ; RV64F-NEXT: sd s0, 0(sp) # 8-byte Folded Spill
359 ; RV64F-NEXT: mv s0, a0
360 ; RV64F-NEXT: call __muldf3@plt
361 ; RV64F-NEXT: li a1, -1
362 ; RV64F-NEXT: slli a1, a1, 63
363 ; RV64F-NEXT: or a1, a0, a1
364 ; RV64F-NEXT: mv a0, s0
365 ; RV64F-NEXT: call __muldf3@plt
366 ; RV64F-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
367 ; RV64F-NEXT: ld s0, 0(sp) # 8-byte Folded Reload
368 ; RV64F-NEXT: addi sp, sp, 16
371 ; RV64FD-LABEL: bitcast_double_or:
373 ; RV64FD-NEXT: fmv.d.x ft0, a1
374 ; RV64FD-NEXT: fmv.d.x ft1, a0
375 ; RV64FD-NEXT: fmul.d ft0, ft1, ft0
376 ; RV64FD-NEXT: fabs.d ft0, ft0
377 ; RV64FD-NEXT: fneg.d ft0, ft0
378 ; RV64FD-NEXT: fmul.d ft0, ft1, ft0
379 ; RV64FD-NEXT: fmv.x.d a0, ft0
381 %a3 = fmul double %a1, %a2
382 %bc1 = bitcast double %a3 to i64
383 %and = or i64 %bc1, 9223372036854775808
384 %bc2 = bitcast i64 %and to double
385 %a4 = fmul double %a1, %bc2