blob: 30674b8605928dd34c09ff9d7766d4d52809b0c9 [file] [log] [blame]
Simon Pilgrimc2cbb522017-07-18 14:26:07 +00001; 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-prefix=X86 --check-prefix=X86-NOSSE
3; RUN: llc < %s -mtriple=i686-unknown-unknown -mattr=+sse2 | FileCheck %s --check-prefix=X86 --check-prefix=X86-SSE2
4; RUN: llc < %s -mtriple=x86_64-unknown-unknown | FileCheck %s --check-prefix=X64 --check-prefix=X64-SSE2
5; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=avx2 | FileCheck %s --check-prefix=X64 --check-prefix=X64-AVX2
6
7; This tests codegen time inlining/optimization of memcmp
8; rdar://6480398
9
10@.str = private constant [65 x i8] c"0123456789012345678901234567890123456789012345678901234567890123\00", align 1
11
12declare i32 @memcmp(i8*, i8*, i64)
13
14define i32 @length2(i8* %X, i8* %Y) nounwind optsize {
15; X86-LABEL: length2:
16; X86: # BB#0:
17; X86-NEXT: pushl %edi
18; X86-NEXT: pushl %esi
19; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
20; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
21; X86-NEXT: movzwl (%ecx), %ecx
22; X86-NEXT: movzwl (%eax), %edx
23; X86-NEXT: rolw $8, %cx
24; X86-NEXT: rolw $8, %dx
25; X86-NEXT: xorl %esi, %esi
26; X86-NEXT: xorl %edi, %edi
27; X86-NEXT: incl %edi
28; X86-NEXT: xorl %eax, %eax
29; X86-NEXT: decl %eax
30; X86-NEXT: cmpw %dx, %cx
31; X86-NEXT: cmovael %edi, %eax
32; X86-NEXT: cmovel %esi, %eax
33; X86-NEXT: popl %esi
34; X86-NEXT: popl %edi
35; X86-NEXT: retl
36;
37; X64-LABEL: length2:
38; X64: # BB#0:
39; X64-NEXT: movzwl (%rdi), %eax
40; X64-NEXT: movzwl (%rsi), %ecx
41; X64-NEXT: rolw $8, %ax
42; X64-NEXT: rolw $8, %cx
43; X64-NEXT: xorl %edx, %edx
44; X64-NEXT: cmpw %cx, %ax
45; X64-NEXT: movl $-1, %ecx
46; X64-NEXT: movl $1, %eax
47; X64-NEXT: cmovbl %ecx, %eax
48; X64-NEXT: cmovel %edx, %eax
49; X64-NEXT: retq
50 %m = tail call i32 @memcmp(i8* %X, i8* %Y, i64 2) nounwind
51 ret i32 %m
52}
53
54define i1 @length2_eq(i8* %X, i8* %Y) nounwind optsize {
55; X86-LABEL: length2_eq:
56; X86: # BB#0:
57; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
58; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
59; X86-NEXT: movzwl (%ecx), %ecx
60; X86-NEXT: cmpw (%eax), %cx
61; X86-NEXT: sete %al
62; X86-NEXT: retl
63;
64; X64-LABEL: length2_eq:
65; X64: # BB#0:
66; X64-NEXT: movzwl (%rdi), %eax
67; X64-NEXT: cmpw (%rsi), %ax
68; X64-NEXT: sete %al
69; X64-NEXT: retq
70 %m = tail call i32 @memcmp(i8* %X, i8* %Y, i64 2) nounwind
71 %c = icmp eq i32 %m, 0
72 ret i1 %c
73}
74
75define i1 @length2_eq_const(i8* %X) nounwind optsize {
76; X86-LABEL: length2_eq_const:
77; X86: # BB#0:
78; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
79; X86-NEXT: movzwl (%eax), %eax
80; X86-NEXT: cmpl $12849, %eax # imm = 0x3231
81; X86-NEXT: setne %al
82; X86-NEXT: retl
83;
84; X64-LABEL: length2_eq_const:
85; X64: # BB#0:
86; X64-NEXT: movzwl (%rdi), %eax
87; X64-NEXT: cmpl $12849, %eax # imm = 0x3231
88; X64-NEXT: setne %al
89; X64-NEXT: retq
90 %m = tail call i32 @memcmp(i8* %X, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i32 0, i32 1), i64 2) nounwind
91 %c = icmp ne i32 %m, 0
92 ret i1 %c
93}
94
95define i1 @length2_eq_nobuiltin_attr(i8* %X, i8* %Y) nounwind optsize {
96; X86-LABEL: length2_eq_nobuiltin_attr:
97; X86: # BB#0:
98; X86-NEXT: pushl $0
99; X86-NEXT: pushl $2
100; X86-NEXT: pushl {{[0-9]+}}(%esp)
101; X86-NEXT: pushl {{[0-9]+}}(%esp)
102; X86-NEXT: calll memcmp
103; X86-NEXT: addl $16, %esp
104; X86-NEXT: testl %eax, %eax
105; X86-NEXT: sete %al
106; X86-NEXT: retl
107;
108; X64-LABEL: length2_eq_nobuiltin_attr:
109; X64: # BB#0:
110; X64-NEXT: pushq %rax
111; X64-NEXT: movl $2, %edx
112; X64-NEXT: callq memcmp
113; X64-NEXT: testl %eax, %eax
114; X64-NEXT: sete %al
115; X64-NEXT: popq %rcx
116; X64-NEXT: retq
117 %m = tail call i32 @memcmp(i8* %X, i8* %Y, i64 2) nounwind nobuiltin
118 %c = icmp eq i32 %m, 0
119 ret i1 %c
120}
121
122define i32 @length3(i8* %X, i8* %Y) nounwind optsize {
123; X86-LABEL: length3:
124; X86: # BB#0:
125; X86-NEXT: pushl $0
126; X86-NEXT: pushl $3
127; X86-NEXT: pushl {{[0-9]+}}(%esp)
128; X86-NEXT: pushl {{[0-9]+}}(%esp)
129; X86-NEXT: calll memcmp
130; X86-NEXT: addl $16, %esp
131; X86-NEXT: retl
132;
133; X64-LABEL: length3:
134; X64: # BB#0:
135; X64-NEXT: movl $3, %edx
136; X64-NEXT: jmp memcmp # TAILCALL
137 %m = tail call i32 @memcmp(i8* %X, i8* %Y, i64 3) nounwind
138 ret i32 %m
139}
140
141define i1 @length3_eq(i8* %X, i8* %Y) nounwind optsize {
142; X86-LABEL: length3_eq:
143; X86: # BB#0:
144; X86-NEXT: pushl $0
145; X86-NEXT: pushl $3
146; X86-NEXT: pushl {{[0-9]+}}(%esp)
147; X86-NEXT: pushl {{[0-9]+}}(%esp)
148; X86-NEXT: calll memcmp
149; X86-NEXT: addl $16, %esp
150; X86-NEXT: testl %eax, %eax
151; X86-NEXT: setne %al
152; X86-NEXT: retl
153;
154; X64-LABEL: length3_eq:
155; X64: # BB#0:
156; X64-NEXT: pushq %rax
157; X64-NEXT: movl $3, %edx
158; X64-NEXT: callq memcmp
159; X64-NEXT: testl %eax, %eax
160; X64-NEXT: setne %al
161; X64-NEXT: popq %rcx
162; X64-NEXT: retq
163 %m = tail call i32 @memcmp(i8* %X, i8* %Y, i64 3) nounwind
164 %c = icmp ne i32 %m, 0
165 ret i1 %c
166}
167
168define i32 @length4(i8* %X, i8* %Y) nounwind optsize {
169; X86-LABEL: length4:
170; X86: # BB#0:
171; X86-NEXT: pushl %edi
172; X86-NEXT: pushl %esi
173; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
174; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
175; X86-NEXT: movl (%ecx), %ecx
176; X86-NEXT: movl (%eax), %edx
177; X86-NEXT: bswapl %ecx
178; X86-NEXT: bswapl %edx
179; X86-NEXT: xorl %esi, %esi
180; X86-NEXT: xorl %edi, %edi
181; X86-NEXT: incl %edi
182; X86-NEXT: xorl %eax, %eax
183; X86-NEXT: decl %eax
184; X86-NEXT: cmpl %edx, %ecx
185; X86-NEXT: cmovael %edi, %eax
186; X86-NEXT: cmovel %esi, %eax
187; X86-NEXT: popl %esi
188; X86-NEXT: popl %edi
189; X86-NEXT: retl
190;
191; X64-LABEL: length4:
192; X64: # BB#0:
193; X64-NEXT: movl (%rdi), %eax
194; X64-NEXT: movl (%rsi), %ecx
195; X64-NEXT: bswapl %eax
196; X64-NEXT: bswapl %ecx
197; X64-NEXT: xorl %edx, %edx
198; X64-NEXT: cmpl %ecx, %eax
199; X64-NEXT: movl $-1, %ecx
200; X64-NEXT: movl $1, %eax
201; X64-NEXT: cmovbl %ecx, %eax
202; X64-NEXT: cmovel %edx, %eax
203; X64-NEXT: retq
204 %m = tail call i32 @memcmp(i8* %X, i8* %Y, i64 4) nounwind
205 ret i32 %m
206}
207
208define i1 @length4_eq(i8* %X, i8* %Y) nounwind optsize {
209; X86-LABEL: length4_eq:
210; X86: # BB#0:
211; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
212; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
213; X86-NEXT: movl (%ecx), %ecx
214; X86-NEXT: cmpl (%eax), %ecx
215; X86-NEXT: setne %al
216; X86-NEXT: retl
217;
218; X64-LABEL: length4_eq:
219; X64: # BB#0:
220; X64-NEXT: movl (%rdi), %eax
221; X64-NEXT: cmpl (%rsi), %eax
222; X64-NEXT: setne %al
223; X64-NEXT: retq
224 %m = tail call i32 @memcmp(i8* %X, i8* %Y, i64 4) nounwind
225 %c = icmp ne i32 %m, 0
226 ret i1 %c
227}
228
229define i1 @length4_eq_const(i8* %X) nounwind optsize {
230; X86-LABEL: length4_eq_const:
231; X86: # BB#0:
232; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
233; X86-NEXT: cmpl $875770417, (%eax) # imm = 0x34333231
234; X86-NEXT: sete %al
235; X86-NEXT: retl
236;
237; X64-LABEL: length4_eq_const:
238; X64: # BB#0:
239; X64-NEXT: cmpl $875770417, (%rdi) # imm = 0x34333231
240; X64-NEXT: sete %al
241; X64-NEXT: retq
242 %m = tail call i32 @memcmp(i8* %X, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i32 0, i32 1), i64 4) nounwind
243 %c = icmp eq i32 %m, 0
244 ret i1 %c
245}
246
247define i32 @length5(i8* %X, i8* %Y) nounwind optsize {
248; X86-LABEL: length5:
249; X86: # BB#0:
250; X86-NEXT: pushl $0
251; X86-NEXT: pushl $5
252; X86-NEXT: pushl {{[0-9]+}}(%esp)
253; X86-NEXT: pushl {{[0-9]+}}(%esp)
254; X86-NEXT: calll memcmp
255; X86-NEXT: addl $16, %esp
256; X86-NEXT: retl
257;
258; X64-LABEL: length5:
259; X64: # BB#0:
260; X64-NEXT: movl $5, %edx
261; X64-NEXT: jmp memcmp # TAILCALL
262 %m = tail call i32 @memcmp(i8* %X, i8* %Y, i64 5) nounwind
263 ret i32 %m
264}
265
266define i1 @length5_eq(i8* %X, i8* %Y) nounwind optsize {
267; X86-LABEL: length5_eq:
268; X86: # BB#0:
269; X86-NEXT: pushl $0
270; X86-NEXT: pushl $5
271; X86-NEXT: pushl {{[0-9]+}}(%esp)
272; X86-NEXT: pushl {{[0-9]+}}(%esp)
273; X86-NEXT: calll memcmp
274; X86-NEXT: addl $16, %esp
275; X86-NEXT: testl %eax, %eax
276; X86-NEXT: setne %al
277; X86-NEXT: retl
278;
279; X64-LABEL: length5_eq:
280; X64: # BB#0:
281; X64-NEXT: pushq %rax
282; X64-NEXT: movl $5, %edx
283; X64-NEXT: callq memcmp
284; X64-NEXT: testl %eax, %eax
285; X64-NEXT: setne %al
286; X64-NEXT: popq %rcx
287; X64-NEXT: retq
288 %m = tail call i32 @memcmp(i8* %X, i8* %Y, i64 5) nounwind
289 %c = icmp ne i32 %m, 0
290 ret i1 %c
291}
292
293define i32 @length8(i8* %X, i8* %Y) nounwind optsize {
294; X86-LABEL: length8:
295; X86: # BB#0:
296; X86-NEXT: pushl $0
297; X86-NEXT: pushl $8
298; X86-NEXT: pushl {{[0-9]+}}(%esp)
299; X86-NEXT: pushl {{[0-9]+}}(%esp)
300; X86-NEXT: calll memcmp
301; X86-NEXT: addl $16, %esp
302; X86-NEXT: retl
303;
304; X64-LABEL: length8:
305; X64: # BB#0:
306; X64-NEXT: movq (%rdi), %rax
307; X64-NEXT: movq (%rsi), %rcx
308; X64-NEXT: bswapq %rax
309; X64-NEXT: bswapq %rcx
310; X64-NEXT: xorl %edx, %edx
311; X64-NEXT: cmpq %rcx, %rax
312; X64-NEXT: movl $-1, %ecx
313; X64-NEXT: movl $1, %eax
314; X64-NEXT: cmovbl %ecx, %eax
315; X64-NEXT: cmovel %edx, %eax
316; X64-NEXT: retq
317 %m = tail call i32 @memcmp(i8* %X, i8* %Y, i64 8) nounwind
318 ret i32 %m
319}
320
321define i1 @length8_eq(i8* %X, i8* %Y) nounwind optsize {
322; X86-LABEL: length8_eq:
323; X86: # BB#0:
324; X86-NEXT: pushl $0
325; X86-NEXT: pushl $8
326; X86-NEXT: pushl {{[0-9]+}}(%esp)
327; X86-NEXT: pushl {{[0-9]+}}(%esp)
328; X86-NEXT: calll memcmp
329; X86-NEXT: addl $16, %esp
330; X86-NEXT: testl %eax, %eax
331; X86-NEXT: sete %al
332; X86-NEXT: retl
333;
334; X64-LABEL: length8_eq:
335; X64: # BB#0:
336; X64-NEXT: movq (%rdi), %rax
337; X64-NEXT: cmpq (%rsi), %rax
338; X64-NEXT: sete %al
339; X64-NEXT: retq
340 %m = tail call i32 @memcmp(i8* %X, i8* %Y, i64 8) nounwind
341 %c = icmp eq i32 %m, 0
342 ret i1 %c
343}
344
345define i1 @length8_eq_const(i8* %X) nounwind optsize {
346; X86-LABEL: length8_eq_const:
347; X86: # BB#0:
348; X86-NEXT: pushl $0
349; X86-NEXT: pushl $8
350; X86-NEXT: pushl $.L.str
351; X86-NEXT: pushl {{[0-9]+}}(%esp)
352; X86-NEXT: calll memcmp
353; X86-NEXT: addl $16, %esp
354; X86-NEXT: testl %eax, %eax
355; X86-NEXT: setne %al
356; X86-NEXT: retl
357;
358; X64-LABEL: length8_eq_const:
359; X64: # BB#0:
360; X64-NEXT: movabsq $3978425819141910832, %rax # imm = 0x3736353433323130
361; X64-NEXT: cmpq %rax, (%rdi)
362; X64-NEXT: setne %al
363; X64-NEXT: retq
364 %m = tail call i32 @memcmp(i8* %X, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i32 0, i32 0), i64 8) nounwind
365 %c = icmp ne i32 %m, 0
366 ret i1 %c
367}
368
369define i1 @length12_eq(i8* %X, i8* %Y) nounwind optsize {
370; X86-LABEL: length12_eq:
371; X86: # BB#0:
372; X86-NEXT: pushl $0
373; X86-NEXT: pushl $12
374; X86-NEXT: pushl {{[0-9]+}}(%esp)
375; X86-NEXT: pushl {{[0-9]+}}(%esp)
376; X86-NEXT: calll memcmp
377; X86-NEXT: addl $16, %esp
378; X86-NEXT: testl %eax, %eax
379; X86-NEXT: setne %al
380; X86-NEXT: retl
381;
382; X64-LABEL: length12_eq:
383; X64: # BB#0:
384; X64-NEXT: pushq %rax
385; X64-NEXT: movl $12, %edx
386; X64-NEXT: callq memcmp
387; X64-NEXT: testl %eax, %eax
388; X64-NEXT: setne %al
389; X64-NEXT: popq %rcx
390; X64-NEXT: retq
391 %m = tail call i32 @memcmp(i8* %X, i8* %Y, i64 12) nounwind
392 %c = icmp ne i32 %m, 0
393 ret i1 %c
394}
395
396define i32 @length12(i8* %X, i8* %Y) nounwind optsize {
397; X86-LABEL: length12:
398; X86: # BB#0:
399; X86-NEXT: pushl $0
400; X86-NEXT: pushl $12
401; X86-NEXT: pushl {{[0-9]+}}(%esp)
402; X86-NEXT: pushl {{[0-9]+}}(%esp)
403; X86-NEXT: calll memcmp
404; X86-NEXT: addl $16, %esp
405; X86-NEXT: retl
406;
407; X64-LABEL: length12:
408; X64: # BB#0:
409; X64-NEXT: movl $12, %edx
410; X64-NEXT: jmp memcmp # TAILCALL
411 %m = tail call i32 @memcmp(i8* %X, i8* %Y, i64 12) nounwind
412 ret i32 %m
413}
414
415; PR33329 - https://bugs.llvm.org/show_bug.cgi?id=33329
416
417define i32 @length16(i8* %X, i8* %Y) nounwind optsize {
418; X86-LABEL: length16:
419; X86: # BB#0:
420; X86-NEXT: pushl $0
421; X86-NEXT: pushl $16
422; X86-NEXT: pushl {{[0-9]+}}(%esp)
423; X86-NEXT: pushl {{[0-9]+}}(%esp)
424; X86-NEXT: calll memcmp
425; X86-NEXT: addl $16, %esp
426; X86-NEXT: retl
427;
428; X64-LABEL: length16:
429; X64: # BB#0:
430; X64-NEXT: movl $16, %edx
431; X64-NEXT: jmp memcmp # TAILCALL
432 %m = tail call i32 @memcmp(i8* %X, i8* %Y, i64 16) nounwind
433 ret i32 %m
434}
435
436define i1 @length16_eq(i8* %x, i8* %y) nounwind optsize {
437; X86-NOSSE-LABEL: length16_eq:
438; X86-NOSSE: # BB#0:
439; X86-NOSSE-NEXT: pushl $0
440; X86-NOSSE-NEXT: pushl $16
441; X86-NOSSE-NEXT: pushl {{[0-9]+}}(%esp)
442; X86-NOSSE-NEXT: pushl {{[0-9]+}}(%esp)
443; X86-NOSSE-NEXT: calll memcmp
444; X86-NOSSE-NEXT: addl $16, %esp
445; X86-NOSSE-NEXT: testl %eax, %eax
446; X86-NOSSE-NEXT: setne %al
447; X86-NOSSE-NEXT: retl
448;
449; X86-SSE2-LABEL: length16_eq:
450; X86-SSE2: # BB#0:
451; X86-SSE2-NEXT: movl {{[0-9]+}}(%esp), %eax
452; X86-SSE2-NEXT: movl {{[0-9]+}}(%esp), %ecx
453; X86-SSE2-NEXT: movdqu (%ecx), %xmm0
454; X86-SSE2-NEXT: movdqu (%eax), %xmm1
455; X86-SSE2-NEXT: pcmpeqb %xmm0, %xmm1
456; X86-SSE2-NEXT: pmovmskb %xmm1, %eax
457; X86-SSE2-NEXT: cmpl $65535, %eax # imm = 0xFFFF
458; X86-SSE2-NEXT: setne %al
459; X86-SSE2-NEXT: retl
460;
461; X64-SSE2-LABEL: length16_eq:
462; X64-SSE2: # BB#0:
463; X64-SSE2-NEXT: movdqu (%rsi), %xmm0
464; X64-SSE2-NEXT: movdqu (%rdi), %xmm1
465; X64-SSE2-NEXT: pcmpeqb %xmm0, %xmm1
466; X64-SSE2-NEXT: pmovmskb %xmm1, %eax
467; X64-SSE2-NEXT: cmpl $65535, %eax # imm = 0xFFFF
468; X64-SSE2-NEXT: setne %al
469; X64-SSE2-NEXT: retq
470;
471; X64-AVX2-LABEL: length16_eq:
472; X64-AVX2: # BB#0:
473; X64-AVX2-NEXT: vmovdqu (%rdi), %xmm0
474; X64-AVX2-NEXT: vpcmpeqb (%rsi), %xmm0, %xmm0
475; X64-AVX2-NEXT: vpmovmskb %xmm0, %eax
476; X64-AVX2-NEXT: cmpl $65535, %eax # imm = 0xFFFF
477; X64-AVX2-NEXT: setne %al
478; X64-AVX2-NEXT: retq
479 %call = tail call i32 @memcmp(i8* %x, i8* %y, i64 16) nounwind
480 %cmp = icmp ne i32 %call, 0
481 ret i1 %cmp
482}
483
484define i1 @length16_eq_const(i8* %X) nounwind optsize {
485; X86-NOSSE-LABEL: length16_eq_const:
486; X86-NOSSE: # BB#0:
487; X86-NOSSE-NEXT: pushl $0
488; X86-NOSSE-NEXT: pushl $16
489; X86-NOSSE-NEXT: pushl $.L.str
490; X86-NOSSE-NEXT: pushl {{[0-9]+}}(%esp)
491; X86-NOSSE-NEXT: calll memcmp
492; X86-NOSSE-NEXT: addl $16, %esp
493; X86-NOSSE-NEXT: testl %eax, %eax
494; X86-NOSSE-NEXT: sete %al
495; X86-NOSSE-NEXT: retl
496;
497; X86-SSE2-LABEL: length16_eq_const:
498; X86-SSE2: # BB#0:
499; X86-SSE2-NEXT: movl {{[0-9]+}}(%esp), %eax
500; X86-SSE2-NEXT: movdqu (%eax), %xmm0
501; X86-SSE2-NEXT: pcmpeqb {{\.LCPI.*}}, %xmm0
502; X86-SSE2-NEXT: pmovmskb %xmm0, %eax
503; X86-SSE2-NEXT: cmpl $65535, %eax # imm = 0xFFFF
504; X86-SSE2-NEXT: sete %al
505; X86-SSE2-NEXT: retl
506;
507; X64-SSE2-LABEL: length16_eq_const:
508; X64-SSE2: # BB#0:
509; X64-SSE2-NEXT: movdqu (%rdi), %xmm0
510; X64-SSE2-NEXT: pcmpeqb {{.*}}(%rip), %xmm0
511; X64-SSE2-NEXT: pmovmskb %xmm0, %eax
512; X64-SSE2-NEXT: cmpl $65535, %eax # imm = 0xFFFF
513; X64-SSE2-NEXT: sete %al
514; X64-SSE2-NEXT: retq
515;
516; X64-AVX2-LABEL: length16_eq_const:
517; X64-AVX2: # BB#0:
518; X64-AVX2-NEXT: vmovdqu (%rdi), %xmm0
519; X64-AVX2-NEXT: vpcmpeqb {{.*}}(%rip), %xmm0, %xmm0
520; X64-AVX2-NEXT: vpmovmskb %xmm0, %eax
521; X64-AVX2-NEXT: cmpl $65535, %eax # imm = 0xFFFF
522; X64-AVX2-NEXT: sete %al
523; X64-AVX2-NEXT: retq
524 %m = tail call i32 @memcmp(i8* %X, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i32 0, i32 0), i64 16) nounwind
525 %c = icmp eq i32 %m, 0
526 ret i1 %c
527}
528
529define i32 @length32(i8* %X, i8* %Y) nounwind optsize {
530; X86-LABEL: length32:
531; X86: # BB#0:
532; X86-NEXT: pushl $0
533; X86-NEXT: pushl $32
534; X86-NEXT: pushl {{[0-9]+}}(%esp)
535; X86-NEXT: pushl {{[0-9]+}}(%esp)
536; X86-NEXT: calll memcmp
537; X86-NEXT: addl $16, %esp
538; X86-NEXT: retl
539;
540; X64-LABEL: length32:
541; X64: # BB#0:
542; X64-NEXT: movl $32, %edx
543; X64-NEXT: jmp memcmp # TAILCALL
544 %m = tail call i32 @memcmp(i8* %X, i8* %Y, i64 32) nounwind
545 ret i32 %m
546}
547
548; PR33325 - https://bugs.llvm.org/show_bug.cgi?id=33325
549
550define i1 @length32_eq(i8* %x, i8* %y) nounwind optsize {
551; X86-LABEL: length32_eq:
552; X86: # BB#0:
553; X86-NEXT: pushl $0
554; X86-NEXT: pushl $32
555; X86-NEXT: pushl {{[0-9]+}}(%esp)
556; X86-NEXT: pushl {{[0-9]+}}(%esp)
557; X86-NEXT: calll memcmp
558; X86-NEXT: addl $16, %esp
559; X86-NEXT: testl %eax, %eax
560; X86-NEXT: sete %al
561; X86-NEXT: retl
562;
563; X64-SSE2-LABEL: length32_eq:
564; X64-SSE2: # BB#0:
565; X64-SSE2-NEXT: pushq %rax
566; X64-SSE2-NEXT: movl $32, %edx
567; X64-SSE2-NEXT: callq memcmp
568; X64-SSE2-NEXT: testl %eax, %eax
569; X64-SSE2-NEXT: sete %al
570; X64-SSE2-NEXT: popq %rcx
571; X64-SSE2-NEXT: retq
572;
573; X64-AVX2-LABEL: length32_eq:
574; X64-AVX2: # BB#0:
575; X64-AVX2-NEXT: vmovdqu (%rdi), %ymm0
576; X64-AVX2-NEXT: vpcmpeqb (%rsi), %ymm0, %ymm0
577; X64-AVX2-NEXT: vpmovmskb %ymm0, %eax
578; X64-AVX2-NEXT: cmpl $-1, %eax
579; X64-AVX2-NEXT: sete %al
580; X64-AVX2-NEXT: vzeroupper
581; X64-AVX2-NEXT: retq
582 %call = tail call i32 @memcmp(i8* %x, i8* %y, i64 32) nounwind
583 %cmp = icmp eq i32 %call, 0
584 ret i1 %cmp
585}
586
587define i1 @length32_eq_const(i8* %X) nounwind optsize {
588; X86-LABEL: length32_eq_const:
589; X86: # BB#0:
590; X86-NEXT: pushl $0
591; X86-NEXT: pushl $32
592; X86-NEXT: pushl $.L.str
593; X86-NEXT: pushl {{[0-9]+}}(%esp)
594; X86-NEXT: calll memcmp
595; X86-NEXT: addl $16, %esp
596; X86-NEXT: testl %eax, %eax
597; X86-NEXT: setne %al
598; X86-NEXT: retl
599;
600; X64-SSE2-LABEL: length32_eq_const:
601; X64-SSE2: # BB#0:
602; X64-SSE2-NEXT: pushq %rax
603; X64-SSE2-NEXT: movl $.L.str, %esi
604; X64-SSE2-NEXT: movl $32, %edx
605; X64-SSE2-NEXT: callq memcmp
606; X64-SSE2-NEXT: testl %eax, %eax
607; X64-SSE2-NEXT: setne %al
608; X64-SSE2-NEXT: popq %rcx
609; X64-SSE2-NEXT: retq
610;
611; X64-AVX2-LABEL: length32_eq_const:
612; X64-AVX2: # BB#0:
613; X64-AVX2-NEXT: vmovdqu (%rdi), %ymm0
614; X64-AVX2-NEXT: vpcmpeqb {{.*}}(%rip), %ymm0, %ymm0
615; X64-AVX2-NEXT: vpmovmskb %ymm0, %eax
616; X64-AVX2-NEXT: cmpl $-1, %eax
617; X64-AVX2-NEXT: setne %al
618; X64-AVX2-NEXT: vzeroupper
619; X64-AVX2-NEXT: retq
620 %m = tail call i32 @memcmp(i8* %X, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i32 0, i32 0), i64 32) nounwind
621 %c = icmp ne i32 %m, 0
622 ret i1 %c
623}
624
625define i32 @length64(i8* %X, i8* %Y) nounwind optsize {
626; X86-LABEL: length64:
627; X86: # BB#0:
628; X86-NEXT: pushl $0
629; X86-NEXT: pushl $64
630; X86-NEXT: pushl {{[0-9]+}}(%esp)
631; X86-NEXT: pushl {{[0-9]+}}(%esp)
632; X86-NEXT: calll memcmp
633; X86-NEXT: addl $16, %esp
634; X86-NEXT: retl
635;
636; X64-LABEL: length64:
637; X64: # BB#0:
638; X64-NEXT: movl $64, %edx
639; X64-NEXT: jmp memcmp # TAILCALL
640 %m = tail call i32 @memcmp(i8* %X, i8* %Y, i64 64) nounwind
641 ret i32 %m
642}
643
644define i1 @length64_eq(i8* %x, i8* %y) nounwind optsize {
645; X86-LABEL: length64_eq:
646; X86: # BB#0:
647; X86-NEXT: pushl $0
648; X86-NEXT: pushl $64
649; X86-NEXT: pushl {{[0-9]+}}(%esp)
650; X86-NEXT: pushl {{[0-9]+}}(%esp)
651; X86-NEXT: calll memcmp
652; X86-NEXT: addl $16, %esp
653; X86-NEXT: testl %eax, %eax
654; X86-NEXT: setne %al
655; X86-NEXT: retl
656;
657; X64-LABEL: length64_eq:
658; X64: # BB#0:
659; X64-NEXT: pushq %rax
660; X64-NEXT: movl $64, %edx
661; X64-NEXT: callq memcmp
662; X64-NEXT: testl %eax, %eax
663; X64-NEXT: setne %al
664; X64-NEXT: popq %rcx
665; X64-NEXT: retq
666 %call = tail call i32 @memcmp(i8* %x, i8* %y, i64 64) nounwind
667 %cmp = icmp ne i32 %call, 0
668 ret i1 %cmp
669}
670
671define i1 @length64_eq_const(i8* %X) nounwind optsize {
672; X86-LABEL: length64_eq_const:
673; X86: # BB#0:
674; X86-NEXT: pushl $0
675; X86-NEXT: pushl $64
676; X86-NEXT: pushl $.L.str
677; X86-NEXT: pushl {{[0-9]+}}(%esp)
678; X86-NEXT: calll memcmp
679; X86-NEXT: addl $16, %esp
680; X86-NEXT: testl %eax, %eax
681; X86-NEXT: sete %al
682; X86-NEXT: retl
683;
684; X64-LABEL: length64_eq_const:
685; X64: # BB#0:
686; X64-NEXT: pushq %rax
687; X64-NEXT: movl $.L.str, %esi
688; X64-NEXT: movl $64, %edx
689; X64-NEXT: callq memcmp
690; X64-NEXT: testl %eax, %eax
691; X64-NEXT: sete %al
692; X64-NEXT: popq %rcx
693; X64-NEXT: retq
694 %m = tail call i32 @memcmp(i8* %X, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i32 0, i32 0), i64 64) nounwind
695 %c = icmp eq i32 %m, 0
696 ret i1 %c
697}
698