1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=i686-unknown-unknown -mattr=cmov | FileCheck %s --check-prefixes=X86,X86-NOSSE
3 ; RUN: llc < %s -mtriple=i686-unknown-unknown -mattr=+sse2 | FileCheck %s --check-prefixes=X86,X86-SSE2
5 ; This tests codegen time inlining/optimization of memcmp
8 @.str = private constant [65 x i8] c"0123456789012345678901234567890123456789012345678901234567890123\00", align 1
10 declare dso_local i32 @memcmp(ptr, ptr, i32)
12 define i32 @length2(ptr %X, ptr %Y) nounwind minsize {
16 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
17 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
18 ; X86-NEXT: calll memcmp
19 ; X86-NEXT: addl $12, %esp
21 %m = tail call i32 @memcmp(ptr %X, ptr %Y, i32 2) nounwind
25 define i1 @length2_eq(ptr %X, ptr %Y) nounwind minsize {
26 ; X86-LABEL: length2_eq:
28 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
29 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
30 ; X86-NEXT: movzwl (%ecx), %ecx
31 ; X86-NEXT: cmpw (%eax), %cx
34 %m = tail call i32 @memcmp(ptr %X, ptr %Y, i32 2) nounwind
35 %c = icmp eq i32 %m, 0
39 define i1 @length2_eq_const(ptr %X) nounwind minsize {
40 ; X86-LABEL: length2_eq_const:
42 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
43 ; X86-NEXT: cmpw $12849, (%eax) # imm = 0x3231
46 %m = tail call i32 @memcmp(ptr %X, ptr getelementptr inbounds ([65 x i8], ptr @.str, i32 0, i32 1), i32 2) nounwind
47 %c = icmp ne i32 %m, 0
51 define i1 @length2_eq_nobuiltin_attr(ptr %X, ptr %Y) nounwind minsize {
52 ; X86-LABEL: length2_eq_nobuiltin_attr:
55 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
56 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
57 ; X86-NEXT: calll memcmp
58 ; X86-NEXT: addl $12, %esp
59 ; X86-NEXT: testl %eax, %eax
62 %m = tail call i32 @memcmp(ptr %X, ptr %Y, i32 2) nounwind nobuiltin
63 %c = icmp eq i32 %m, 0
67 define i32 @length3(ptr %X, ptr %Y) nounwind minsize {
71 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
72 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
73 ; X86-NEXT: calll memcmp
74 ; X86-NEXT: addl $12, %esp
76 %m = tail call i32 @memcmp(ptr %X, ptr %Y, i32 3) nounwind
80 define i1 @length3_eq(ptr %X, ptr %Y) nounwind minsize {
81 ; X86-LABEL: length3_eq:
84 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
85 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
86 ; X86-NEXT: calll memcmp
87 ; X86-NEXT: addl $12, %esp
88 ; X86-NEXT: testl %eax, %eax
91 %m = tail call i32 @memcmp(ptr %X, ptr %Y, i32 3) nounwind
92 %c = icmp ne i32 %m, 0
96 define i32 @length4(ptr %X, ptr %Y) nounwind minsize {
100 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
101 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
102 ; X86-NEXT: calll memcmp
103 ; X86-NEXT: addl $12, %esp
105 %m = tail call i32 @memcmp(ptr %X, ptr %Y, i32 4) nounwind
109 define i1 @length4_eq(ptr %X, ptr %Y) nounwind minsize {
110 ; X86-LABEL: length4_eq:
112 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
113 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
114 ; X86-NEXT: movl (%ecx), %ecx
115 ; X86-NEXT: cmpl (%eax), %ecx
116 ; X86-NEXT: setne %al
118 %m = tail call i32 @memcmp(ptr %X, ptr %Y, i32 4) nounwind
119 %c = icmp ne i32 %m, 0
123 define i1 @length4_eq_const(ptr %X) nounwind minsize {
124 ; X86-LABEL: length4_eq_const:
126 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
127 ; X86-NEXT: cmpl $875770417, (%eax) # imm = 0x34333231
130 %m = tail call i32 @memcmp(ptr %X, ptr getelementptr inbounds ([65 x i8], ptr @.str, i32 0, i32 1), i32 4) nounwind
131 %c = icmp eq i32 %m, 0
135 define i32 @length5(ptr %X, ptr %Y) nounwind minsize {
136 ; X86-LABEL: length5:
139 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
140 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
141 ; X86-NEXT: calll memcmp
142 ; X86-NEXT: addl $12, %esp
144 %m = tail call i32 @memcmp(ptr %X, ptr %Y, i32 5) nounwind
148 define i1 @length5_eq(ptr %X, ptr %Y) nounwind minsize {
149 ; X86-LABEL: length5_eq:
152 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
153 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
154 ; X86-NEXT: calll memcmp
155 ; X86-NEXT: addl $12, %esp
156 ; X86-NEXT: testl %eax, %eax
157 ; X86-NEXT: setne %al
159 %m = tail call i32 @memcmp(ptr %X, ptr %Y, i32 5) nounwind
160 %c = icmp ne i32 %m, 0
164 define i32 @length8(ptr %X, ptr %Y) nounwind minsize {
165 ; X86-LABEL: length8:
168 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
169 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
170 ; X86-NEXT: calll memcmp
171 ; X86-NEXT: addl $12, %esp
173 %m = tail call i32 @memcmp(ptr %X, ptr %Y, i32 8) nounwind
177 define i1 @length8_eq(ptr %X, ptr %Y) nounwind minsize {
178 ; X86-LABEL: length8_eq:
181 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
182 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
183 ; X86-NEXT: calll memcmp
184 ; X86-NEXT: addl $12, %esp
185 ; X86-NEXT: testl %eax, %eax
188 %m = tail call i32 @memcmp(ptr %X, ptr %Y, i32 8) nounwind
189 %c = icmp eq i32 %m, 0
193 define i1 @length8_eq_const(ptr %X) nounwind minsize {
194 ; X86-LABEL: length8_eq_const:
197 ; X86-NEXT: pushl $.L.str
198 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
199 ; X86-NEXT: calll memcmp
200 ; X86-NEXT: addl $12, %esp
201 ; X86-NEXT: testl %eax, %eax
202 ; X86-NEXT: setne %al
204 %m = tail call i32 @memcmp(ptr %X, ptr @.str, i32 8) nounwind
205 %c = icmp ne i32 %m, 0
209 define i1 @length12_eq(ptr %X, ptr %Y) nounwind minsize {
210 ; X86-LABEL: length12_eq:
212 ; X86-NEXT: pushl $12
213 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
214 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
215 ; X86-NEXT: calll memcmp
216 ; X86-NEXT: addl $12, %esp
217 ; X86-NEXT: testl %eax, %eax
218 ; X86-NEXT: setne %al
220 %m = tail call i32 @memcmp(ptr %X, ptr %Y, i32 12) nounwind
221 %c = icmp ne i32 %m, 0
225 define i32 @length12(ptr %X, ptr %Y) nounwind minsize {
226 ; X86-LABEL: length12:
228 ; X86-NEXT: pushl $12
229 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
230 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
231 ; X86-NEXT: calll memcmp
232 ; X86-NEXT: addl $12, %esp
234 %m = tail call i32 @memcmp(ptr %X, ptr %Y, i32 12) nounwind
238 ; PR33329 - https://bugs.llvm.org/show_bug.cgi?id=33329
240 define i32 @length16(ptr %X, ptr %Y) nounwind minsize {
241 ; X86-LABEL: length16:
243 ; X86-NEXT: pushl $16
244 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
245 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
246 ; X86-NEXT: calll memcmp
247 ; X86-NEXT: addl $12, %esp
249 %m = tail call i32 @memcmp(ptr %X, ptr %Y, i32 16) nounwind
253 define i1 @length16_eq(ptr %x, ptr %y) nounwind minsize {
254 ; X86-NOSSE-LABEL: length16_eq:
255 ; X86-NOSSE: # %bb.0:
256 ; X86-NOSSE-NEXT: pushl $16
257 ; X86-NOSSE-NEXT: pushl {{[0-9]+}}(%esp)
258 ; X86-NOSSE-NEXT: pushl {{[0-9]+}}(%esp)
259 ; X86-NOSSE-NEXT: calll memcmp
260 ; X86-NOSSE-NEXT: addl $12, %esp
261 ; X86-NOSSE-NEXT: testl %eax, %eax
262 ; X86-NOSSE-NEXT: setne %al
263 ; X86-NOSSE-NEXT: retl
265 ; X86-SSE2-LABEL: length16_eq:
267 ; X86-SSE2-NEXT: movl {{[0-9]+}}(%esp), %eax
268 ; X86-SSE2-NEXT: movl {{[0-9]+}}(%esp), %ecx
269 ; X86-SSE2-NEXT: movdqu (%ecx), %xmm0
270 ; X86-SSE2-NEXT: movdqu (%eax), %xmm1
271 ; X86-SSE2-NEXT: pcmpeqb %xmm0, %xmm1
272 ; X86-SSE2-NEXT: pmovmskb %xmm1, %eax
273 ; X86-SSE2-NEXT: cmpl $65535, %eax # imm = 0xFFFF
274 ; X86-SSE2-NEXT: setne %al
275 ; X86-SSE2-NEXT: retl
276 %call = tail call i32 @memcmp(ptr %x, ptr %y, i32 16) nounwind
277 %cmp = icmp ne i32 %call, 0
281 define i1 @length16_eq_const(ptr %X) nounwind minsize {
282 ; X86-NOSSE-LABEL: length16_eq_const:
283 ; X86-NOSSE: # %bb.0:
284 ; X86-NOSSE-NEXT: pushl $16
285 ; X86-NOSSE-NEXT: pushl $.L.str
286 ; X86-NOSSE-NEXT: pushl {{[0-9]+}}(%esp)
287 ; X86-NOSSE-NEXT: calll memcmp
288 ; X86-NOSSE-NEXT: addl $12, %esp
289 ; X86-NOSSE-NEXT: testl %eax, %eax
290 ; X86-NOSSE-NEXT: sete %al
291 ; X86-NOSSE-NEXT: retl
293 ; X86-SSE2-LABEL: length16_eq_const:
295 ; X86-SSE2-NEXT: movl {{[0-9]+}}(%esp), %eax
296 ; X86-SSE2-NEXT: movdqu (%eax), %xmm0
297 ; X86-SSE2-NEXT: pcmpeqb {{\.?LCPI[0-9]+_[0-9]+}}, %xmm0
298 ; X86-SSE2-NEXT: pmovmskb %xmm0, %eax
299 ; X86-SSE2-NEXT: cmpl $65535, %eax # imm = 0xFFFF
300 ; X86-SSE2-NEXT: sete %al
301 ; X86-SSE2-NEXT: retl
302 %m = tail call i32 @memcmp(ptr %X, ptr @.str, i32 16) nounwind
303 %c = icmp eq i32 %m, 0
307 ; PR33914 - https://bugs.llvm.org/show_bug.cgi?id=33914
309 define i32 @length24(ptr %X, ptr %Y) nounwind minsize {
310 ; X86-LABEL: length24:
312 ; X86-NEXT: pushl $24
313 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
314 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
315 ; X86-NEXT: calll memcmp
316 ; X86-NEXT: addl $12, %esp
318 %m = tail call i32 @memcmp(ptr %X, ptr %Y, i32 24) nounwind
322 define i1 @length24_eq(ptr %x, ptr %y) nounwind minsize {
323 ; X86-LABEL: length24_eq:
325 ; X86-NEXT: pushl $24
326 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
327 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
328 ; X86-NEXT: calll memcmp
329 ; X86-NEXT: addl $12, %esp
330 ; X86-NEXT: testl %eax, %eax
333 %call = tail call i32 @memcmp(ptr %x, ptr %y, i32 24) nounwind
334 %cmp = icmp eq i32 %call, 0
338 define i1 @length24_eq_const(ptr %X) nounwind minsize {
339 ; X86-LABEL: length24_eq_const:
341 ; X86-NEXT: pushl $24
342 ; X86-NEXT: pushl $.L.str
343 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
344 ; X86-NEXT: calll memcmp
345 ; X86-NEXT: addl $12, %esp
346 ; X86-NEXT: testl %eax, %eax
347 ; X86-NEXT: setne %al
349 %m = tail call i32 @memcmp(ptr %X, ptr @.str, i32 24) nounwind
350 %c = icmp ne i32 %m, 0
354 define i32 @length32(ptr %X, ptr %Y) nounwind minsize {
355 ; X86-LABEL: length32:
357 ; X86-NEXT: pushl $32
358 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
359 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
360 ; X86-NEXT: calll memcmp
361 ; X86-NEXT: addl $12, %esp
363 %m = tail call i32 @memcmp(ptr %X, ptr %Y, i32 32) nounwind
367 ; PR33325 - https://bugs.llvm.org/show_bug.cgi?id=33325
369 define i1 @length32_eq(ptr %x, ptr %y) nounwind minsize {
370 ; X86-LABEL: length32_eq:
372 ; X86-NEXT: pushl $32
373 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
374 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
375 ; X86-NEXT: calll memcmp
376 ; X86-NEXT: addl $12, %esp
377 ; X86-NEXT: testl %eax, %eax
380 %call = tail call i32 @memcmp(ptr %x, ptr %y, i32 32) nounwind
381 %cmp = icmp eq i32 %call, 0
385 define i1 @length32_eq_const(ptr %X) nounwind minsize {
386 ; X86-LABEL: length32_eq_const:
388 ; X86-NEXT: pushl $32
389 ; X86-NEXT: pushl $.L.str
390 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
391 ; X86-NEXT: calll memcmp
392 ; X86-NEXT: addl $12, %esp
393 ; X86-NEXT: testl %eax, %eax
394 ; X86-NEXT: setne %al
396 %m = tail call i32 @memcmp(ptr %X, ptr @.str, i32 32) nounwind
397 %c = icmp ne i32 %m, 0
401 define i32 @length64(ptr %X, ptr %Y) nounwind minsize {
402 ; X86-LABEL: length64:
404 ; X86-NEXT: pushl $64
405 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
406 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
407 ; X86-NEXT: calll memcmp
408 ; X86-NEXT: addl $12, %esp
410 %m = tail call i32 @memcmp(ptr %X, ptr %Y, i32 64) nounwind
414 define i1 @length64_eq(ptr %x, ptr %y) nounwind minsize {
415 ; X86-LABEL: length64_eq:
417 ; X86-NEXT: pushl $64
418 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
419 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
420 ; X86-NEXT: calll memcmp
421 ; X86-NEXT: addl $12, %esp
422 ; X86-NEXT: testl %eax, %eax
423 ; X86-NEXT: setne %al
425 %call = tail call i32 @memcmp(ptr %x, ptr %y, i32 64) nounwind
426 %cmp = icmp ne i32 %call, 0
430 define i1 @length64_eq_const(ptr %X) nounwind minsize {
431 ; X86-LABEL: length64_eq_const:
433 ; X86-NEXT: pushl $64
434 ; X86-NEXT: pushl $.L.str
435 ; X86-NEXT: pushl {{[0-9]+}}(%esp)
436 ; X86-NEXT: calll memcmp
437 ; X86-NEXT: addl $12, %esp
438 ; X86-NEXT: testl %eax, %eax
441 %m = tail call i32 @memcmp(ptr %X, ptr @.str, i32 64) nounwind
442 %c = icmp eq i32 %m, 0