Skip to content

Commit ebd1379

Browse files
committed
[DAGCombiner] Add tests for simplifying {si|ui}tofp; NFC
1 parent b60cf84 commit ebd1379

File tree

1 file changed

+382
-0
lines changed

1 file changed

+382
-0
lines changed
Lines changed: 382 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,382 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
2+
; RUN: llc < %s -mtriple=i686-unknown-unknown | FileCheck %s --check-prefix=X86
3+
; RUN: llc < %s -mtriple=x86_64-unknown-unknown | FileCheck %s --check-prefix=X64
4+
5+
declare void @use.i1(i1)
6+
declare void @use.i32(i32)
7+
define i32 @sitofp_signbit_only(i32 %i_in) nounwind {
8+
; X86-LABEL: sitofp_signbit_only:
9+
; X86: # %bb.0:
10+
; X86-NEXT: subl $8, %esp
11+
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
12+
; X86-NEXT: movl %eax, (%esp)
13+
; X86-NEXT: fildl (%esp)
14+
; X86-NEXT: fstps {{[0-9]+}}(%esp)
15+
; X86-NEXT: movl $-2147483648, %eax # imm = 0x80000000
16+
; X86-NEXT: andl {{[0-9]+}}(%esp), %eax
17+
; X86-NEXT: addl $8, %esp
18+
; X86-NEXT: retl
19+
;
20+
; X64-LABEL: sitofp_signbit_only:
21+
; X64: # %bb.0:
22+
; X64-NEXT: cvtsi2ss %edi, %xmm0
23+
; X64-NEXT: movmskps %xmm0, %eax
24+
; X64-NEXT: shll $31, %eax
25+
; X64-NEXT: retq
26+
%f = sitofp i32 %i_in to float
27+
%i = bitcast float %f to i32
28+
%r = and i32 %i, 2147483648
29+
ret i32 %r
30+
}
31+
32+
define i32 @sitofp_signbit_only_okay_width(i16 %i_in) nounwind {
33+
; X86-LABEL: sitofp_signbit_only_okay_width:
34+
; X86: # %bb.0:
35+
; X86-NEXT: subl $8, %esp
36+
; X86-NEXT: movzwl {{[0-9]+}}(%esp), %eax
37+
; X86-NEXT: movw %ax, {{[0-9]+}}(%esp)
38+
; X86-NEXT: filds {{[0-9]+}}(%esp)
39+
; X86-NEXT: fstps {{[0-9]+}}(%esp)
40+
; X86-NEXT: movl $-2147483648, %eax # imm = 0x80000000
41+
; X86-NEXT: andl {{[0-9]+}}(%esp), %eax
42+
; X86-NEXT: addl $8, %esp
43+
; X86-NEXT: retl
44+
;
45+
; X64-LABEL: sitofp_signbit_only_okay_width:
46+
; X64: # %bb.0:
47+
; X64-NEXT: movswl %di, %eax
48+
; X64-NEXT: cvtsi2ss %eax, %xmm0
49+
; X64-NEXT: movmskps %xmm0, %eax
50+
; X64-NEXT: shll $31, %eax
51+
; X64-NEXT: retq
52+
%f = sitofp i16 %i_in to float
53+
%i = bitcast float %f to i32
54+
%r = and i32 %i, 2147483648
55+
ret i32 %r
56+
}
57+
58+
define i32 @sitofp_signbit_only_fail_bad_width1(i64 %i_in) nounwind {
59+
; X86-LABEL: sitofp_signbit_only_fail_bad_width1:
60+
; X86: # %bb.0:
61+
; X86-NEXT: pushl %eax
62+
; X86-NEXT: fildll {{[0-9]+}}(%esp)
63+
; X86-NEXT: fstps (%esp)
64+
; X86-NEXT: movl $-2147483648, %eax # imm = 0x80000000
65+
; X86-NEXT: andl (%esp), %eax
66+
; X86-NEXT: popl %ecx
67+
; X86-NEXT: retl
68+
;
69+
; X64-LABEL: sitofp_signbit_only_fail_bad_width1:
70+
; X64: # %bb.0:
71+
; X64-NEXT: cvtsi2ss %rdi, %xmm0
72+
; X64-NEXT: movmskps %xmm0, %eax
73+
; X64-NEXT: shll $31, %eax
74+
; X64-NEXT: retq
75+
%f = sitofp i64 %i_in to float
76+
%i = bitcast float %f to i32
77+
%r = and i32 %i, 2147483648
78+
ret i32 %r
79+
}
80+
81+
define <2 x i16> @sitofp_signbit_only_fail_bad_width2(i32 %i_in) nounwind {
82+
; X86-LABEL: sitofp_signbit_only_fail_bad_width2:
83+
; X86: # %bb.0:
84+
; X86-NEXT: subl $8, %esp
85+
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
86+
; X86-NEXT: movl %eax, (%esp)
87+
; X86-NEXT: fildl (%esp)
88+
; X86-NEXT: fstps {{[0-9]+}}(%esp)
89+
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
90+
; X86-NEXT: movl %eax, %edx
91+
; X86-NEXT: shrl $16, %edx
92+
; X86-NEXT: andl $32768, %eax # imm = 0x8000
93+
; X86-NEXT: andl $32768, %edx # imm = 0x8000
94+
; X86-NEXT: # kill: def $ax killed $ax killed $eax
95+
; X86-NEXT: # kill: def $dx killed $dx killed $edx
96+
; X86-NEXT: addl $8, %esp
97+
; X86-NEXT: retl
98+
;
99+
; X64-LABEL: sitofp_signbit_only_fail_bad_width2:
100+
; X64: # %bb.0:
101+
; X64-NEXT: cvtsi2ss %edi, %xmm0
102+
; X64-NEXT: andps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
103+
; X64-NEXT: retq
104+
%f = sitofp i32 %i_in to float
105+
%i2xi16 = bitcast float %f to <2 x i16>
106+
%r = and <2 x i16> %i2xi16, <i16 32768, i16 32768>
107+
ret <2 x i16> %r
108+
}
109+
110+
define i32 @sitofp_many_bits_fail(i32 %i_in) nounwind {
111+
; X86-LABEL: sitofp_many_bits_fail:
112+
; X86: # %bb.0:
113+
; X86-NEXT: subl $8, %esp
114+
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
115+
; X86-NEXT: movl %eax, (%esp)
116+
; X86-NEXT: fildl (%esp)
117+
; X86-NEXT: fstps {{[0-9]+}}(%esp)
118+
; X86-NEXT: movl $-2147483647, %eax # imm = 0x80000001
119+
; X86-NEXT: andl {{[0-9]+}}(%esp), %eax
120+
; X86-NEXT: addl $8, %esp
121+
; X86-NEXT: retl
122+
;
123+
; X64-LABEL: sitofp_many_bits_fail:
124+
; X64: # %bb.0:
125+
; X64-NEXT: cvtsi2ss %edi, %xmm0
126+
; X64-NEXT: movd %xmm0, %eax
127+
; X64-NEXT: andl $-2147483647, %eax # imm = 0x80000001
128+
; X64-NEXT: retq
129+
%f = sitofp i32 %i_in to float
130+
%i = bitcast float %f to i32
131+
%r = and i32 %i, 2147483649
132+
ret i32 %r
133+
}
134+
135+
define i32 @sitofp_multiuse_fail(i32 %i_in) nounwind {
136+
; X86-LABEL: sitofp_multiuse_fail:
137+
; X86: # %bb.0:
138+
; X86-NEXT: subl $12, %esp
139+
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
140+
; X86-NEXT: movl %eax, {{[0-9]+}}(%esp)
141+
; X86-NEXT: fildl {{[0-9]+}}(%esp)
142+
; X86-NEXT: fsts {{[0-9]+}}(%esp)
143+
; X86-NEXT: fstps (%esp)
144+
; X86-NEXT: calll use.i32@PLT
145+
; X86-NEXT: movl $-2147483648, %eax # imm = 0x80000000
146+
; X86-NEXT: andl {{[0-9]+}}(%esp), %eax
147+
; X86-NEXT: addl $12, %esp
148+
; X86-NEXT: retl
149+
;
150+
; X64-LABEL: sitofp_multiuse_fail:
151+
; X64: # %bb.0:
152+
; X64-NEXT: pushq %rbx
153+
; X64-NEXT: cvtsi2ss %edi, %xmm0
154+
; X64-NEXT: movd %xmm0, %ebx
155+
; X64-NEXT: movl %ebx, %edi
156+
; X64-NEXT: callq use.i32@PLT
157+
; X64-NEXT: andl $-2147483648, %ebx # imm = 0x80000000
158+
; X64-NEXT: movl %ebx, %eax
159+
; X64-NEXT: popq %rbx
160+
; X64-NEXT: retq
161+
%f = sitofp i32 %i_in to float
162+
%i = bitcast float %f to i32
163+
call void @use.i32(i32 %i)
164+
%r = and i32 %i, 2147483648
165+
ret i32 %r
166+
}
167+
168+
define i32 @sitofp_multiuse_okay(i32 %i_in) nounwind {
169+
; X86-LABEL: sitofp_multiuse_okay:
170+
; X86: # %bb.0:
171+
; X86-NEXT: subl $12, %esp
172+
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
173+
; X86-NEXT: movl %eax, {{[0-9]+}}(%esp)
174+
; X86-NEXT: fildl {{[0-9]+}}(%esp)
175+
; X86-NEXT: fsts {{[0-9]+}}(%esp)
176+
; X86-NEXT: fstps (%esp)
177+
; X86-NEXT: calll use.i1@PLT
178+
; X86-NEXT: movl $-2147483648, %eax # imm = 0x80000000
179+
; X86-NEXT: andl {{[0-9]+}}(%esp), %eax
180+
; X86-NEXT: addl $12, %esp
181+
; X86-NEXT: retl
182+
;
183+
; X64-LABEL: sitofp_multiuse_okay:
184+
; X64: # %bb.0:
185+
; X64-NEXT: pushq %rbx
186+
; X64-NEXT: cvtsi2ss %edi, %xmm0
187+
; X64-NEXT: movd %xmm0, %ebx
188+
; X64-NEXT: movl %ebx, %edi
189+
; X64-NEXT: callq use.i1@PLT
190+
; X64-NEXT: andl $-2147483648, %ebx # imm = 0x80000000
191+
; X64-NEXT: movl %ebx, %eax
192+
; X64-NEXT: popq %rbx
193+
; X64-NEXT: retq
194+
%f = sitofp i32 %i_in to float
195+
%i = bitcast float %f to i32
196+
%cmp = icmp slt i32 %i, 0
197+
call void @use.i1(i32 %i)
198+
%r = and i32 %i, 2147483648
199+
ret i32 %r
200+
}
201+
202+
define i32 @uitofp_signbit_only(i32 %i_in) nounwind {
203+
; X86-LABEL: uitofp_signbit_only:
204+
; X86: # %bb.0:
205+
; X86-NEXT: xorl %eax, %eax
206+
; X86-NEXT: retl
207+
;
208+
; X64-LABEL: uitofp_signbit_only:
209+
; X64: # %bb.0:
210+
; X64-NEXT: xorl %eax, %eax
211+
; X64-NEXT: retq
212+
%f = uitofp i32 %i_in to float
213+
%i = bitcast float %f to i32
214+
%r = and i32 %i, 2147483648
215+
ret i32 %r
216+
}
217+
218+
define i32 @uitofp_signbit_only_okay_width(i16 %i_in) nounwind {
219+
; X86-LABEL: uitofp_signbit_only_okay_width:
220+
; X86: # %bb.0:
221+
; X86-NEXT: xorl %eax, %eax
222+
; X86-NEXT: retl
223+
;
224+
; X64-LABEL: uitofp_signbit_only_okay_width:
225+
; X64: # %bb.0:
226+
; X64-NEXT: xorl %eax, %eax
227+
; X64-NEXT: retq
228+
%f = uitofp i16 %i_in to float
229+
%i = bitcast float %f to i32
230+
%r = and i32 %i, 2147483648
231+
ret i32 %r
232+
}
233+
234+
define i32 @uitofp_signbit_only_okay_width1(i64 %i_in) nounwind {
235+
; X86-LABEL: uitofp_signbit_only_okay_width1:
236+
; X86: # %bb.0:
237+
; X86-NEXT: xorl %eax, %eax
238+
; X86-NEXT: retl
239+
;
240+
; X64-LABEL: uitofp_signbit_only_okay_width1:
241+
; X64: # %bb.0:
242+
; X64-NEXT: xorl %eax, %eax
243+
; X64-NEXT: retq
244+
%f = uitofp i64 %i_in to float
245+
%i = bitcast float %f to i32
246+
%r = and i32 %i, 2147483648
247+
ret i32 %r
248+
}
249+
250+
define <2 x i16> @uitofp_signbit_only_fail_bad_width2(i32 %i_in) nounwind {
251+
; X86-LABEL: uitofp_signbit_only_fail_bad_width2:
252+
; X86: # %bb.0:
253+
; X86-NEXT: pushl %ebp
254+
; X86-NEXT: movl %esp, %ebp
255+
; X86-NEXT: andl $-8, %esp
256+
; X86-NEXT: subl $16, %esp
257+
; X86-NEXT: movl 8(%ebp), %eax
258+
; X86-NEXT: movl %eax, {{[0-9]+}}(%esp)
259+
; X86-NEXT: movl $0, {{[0-9]+}}(%esp)
260+
; X86-NEXT: fildll {{[0-9]+}}(%esp)
261+
; X86-NEXT: fstps {{[0-9]+}}(%esp)
262+
; X86-NEXT: movl $32768, %eax # imm = 0x8000
263+
; X86-NEXT: andl {{[0-9]+}}(%esp), %eax
264+
; X86-NEXT: # kill: def $ax killed $ax killed $eax
265+
; X86-NEXT: xorl %edx, %edx
266+
; X86-NEXT: movl %ebp, %esp
267+
; X86-NEXT: popl %ebp
268+
; X86-NEXT: retl
269+
;
270+
; X64-LABEL: uitofp_signbit_only_fail_bad_width2:
271+
; X64: # %bb.0:
272+
; X64-NEXT: movl %edi, %eax
273+
; X64-NEXT: cvtsi2ss %rax, %xmm0
274+
; X64-NEXT: andps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
275+
; X64-NEXT: retq
276+
%f = uitofp i32 %i_in to float
277+
%i2xi16 = bitcast float %f to <2 x i16>
278+
%r = and <2 x i16> %i2xi16, <i16 32768, i16 32768>
279+
ret <2 x i16> %r
280+
}
281+
282+
define i32 @uitofp_many_bits_fail(i32 %i_in) nounwind {
283+
; X86-LABEL: uitofp_many_bits_fail:
284+
; X86: # %bb.0:
285+
; X86-NEXT: pushl %ebp
286+
; X86-NEXT: movl %esp, %ebp
287+
; X86-NEXT: andl $-8, %esp
288+
; X86-NEXT: subl $16, %esp
289+
; X86-NEXT: movl 8(%ebp), %eax
290+
; X86-NEXT: movl %eax, {{[0-9]+}}(%esp)
291+
; X86-NEXT: movl $0, {{[0-9]+}}(%esp)
292+
; X86-NEXT: fildll {{[0-9]+}}(%esp)
293+
; X86-NEXT: fstps {{[0-9]+}}(%esp)
294+
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
295+
; X86-NEXT: andl $1, %eax
296+
; X86-NEXT: movl %ebp, %esp
297+
; X86-NEXT: popl %ebp
298+
; X86-NEXT: retl
299+
;
300+
; X64-LABEL: uitofp_many_bits_fail:
301+
; X64: # %bb.0:
302+
; X64-NEXT: movl %edi, %eax
303+
; X64-NEXT: cvtsi2ss %rax, %xmm0
304+
; X64-NEXT: movd %xmm0, %eax
305+
; X64-NEXT: andl $1, %eax
306+
; X64-NEXT: retq
307+
%f = uitofp i32 %i_in to float
308+
%i = bitcast float %f to i32
309+
%r = and i32 %i, 2147483649
310+
ret i32 %r
311+
}
312+
313+
define i32 @uitofp_multiuse_fail(i32 %i_in) nounwind {
314+
; X86-LABEL: uitofp_multiuse_fail:
315+
; X86: # %bb.0:
316+
; X86-NEXT: pushl %ebp
317+
; X86-NEXT: movl %esp, %ebp
318+
; X86-NEXT: andl $-8, %esp
319+
; X86-NEXT: subl $16, %esp
320+
; X86-NEXT: movl 8(%ebp), %eax
321+
; X86-NEXT: movl %eax, {{[0-9]+}}(%esp)
322+
; X86-NEXT: movl $0, {{[0-9]+}}(%esp)
323+
; X86-NEXT: fildll {{[0-9]+}}(%esp)
324+
; X86-NEXT: fstps (%esp)
325+
; X86-NEXT: calll use.i32@PLT
326+
; X86-NEXT: xorl %eax, %eax
327+
; X86-NEXT: movl %ebp, %esp
328+
; X86-NEXT: popl %ebp
329+
; X86-NEXT: retl
330+
;
331+
; X64-LABEL: uitofp_multiuse_fail:
332+
; X64: # %bb.0:
333+
; X64-NEXT: pushq %rax
334+
; X64-NEXT: movl %edi, %eax
335+
; X64-NEXT: cvtsi2ss %rax, %xmm0
336+
; X64-NEXT: movd %xmm0, %edi
337+
; X64-NEXT: callq use.i32@PLT
338+
; X64-NEXT: xorl %eax, %eax
339+
; X64-NEXT: popq %rcx
340+
; X64-NEXT: retq
341+
%f = uitofp i32 %i_in to float
342+
%i = bitcast float %f to i32
343+
call void @use.i32(i32 %i)
344+
%r = and i32 %i, 2147483648
345+
ret i32 %r
346+
}
347+
348+
define i32 @uitofp_multiuse_okay(i32 %i_in) nounwind {
349+
; X86-LABEL: uitofp_multiuse_okay:
350+
; X86: # %bb.0:
351+
; X86-NEXT: pushl %ebp
352+
; X86-NEXT: movl %esp, %ebp
353+
; X86-NEXT: andl $-8, %esp
354+
; X86-NEXT: subl $16, %esp
355+
; X86-NEXT: movl 8(%ebp), %eax
356+
; X86-NEXT: movl %eax, {{[0-9]+}}(%esp)
357+
; X86-NEXT: movl $0, {{[0-9]+}}(%esp)
358+
; X86-NEXT: fildll {{[0-9]+}}(%esp)
359+
; X86-NEXT: fstps (%esp)
360+
; X86-NEXT: calll use.i1@PLT
361+
; X86-NEXT: xorl %eax, %eax
362+
; X86-NEXT: movl %ebp, %esp
363+
; X86-NEXT: popl %ebp
364+
; X86-NEXT: retl
365+
;
366+
; X64-LABEL: uitofp_multiuse_okay:
367+
; X64: # %bb.0:
368+
; X64-NEXT: pushq %rax
369+
; X64-NEXT: movl %edi, %eax
370+
; X64-NEXT: cvtsi2ss %rax, %xmm0
371+
; X64-NEXT: movd %xmm0, %edi
372+
; X64-NEXT: callq use.i1@PLT
373+
; X64-NEXT: xorl %eax, %eax
374+
; X64-NEXT: popq %rcx
375+
; X64-NEXT: retq
376+
%f = uitofp i32 %i_in to float
377+
%i = bitcast float %f to i32
378+
%cmp = icmp slt i32 %i, 0
379+
call void @use.i1(i32 %i)
380+
%r = and i32 %i, 2147483648
381+
ret i32 %r
382+
}

0 commit comments

Comments
 (0)