Re-implement the main strength-reduction portion of LoopStrengthReduction.
[oota-llvm.git] / test / CodeGen / X86 / memcmp.ll
1 ; RUN: llc %s -o - -march=x86-64 | FileCheck %s
2
3 ; This tests codegen time inlining/optimization of memcmp
4 ; rdar://6480398
5
6 @.str = private constant [23 x i8] c"fooooooooooooooooooooo\00", align 1 ; <[23 x i8]*> [#uses=1]
7
8 declare i32 @memcmp(...)
9
10 define void @memcmp2(i8* %X, i8* %Y, i32* nocapture %P) nounwind {
11 entry:
12   %0 = tail call i32 (...)* @memcmp(i8* %X, i8* %Y, i32 2) nounwind ; <i32> [#uses=1]
13   %1 = icmp eq i32 %0, 0                          ; <i1> [#uses=1]
14   br i1 %1, label %return, label %bb
15
16 bb:                                               ; preds = %entry
17   store i32 4, i32* %P, align 4
18   ret void
19
20 return:                                           ; preds = %entry
21   ret void
22 ; CHECK: memcmp2:
23 ; CHECK: movw    (%rsi), %ax
24 ; CHECK: cmpw    %ax, (%rdi)
25 }
26
27 define void @memcmp2a(i8* %X, i32* nocapture %P) nounwind {
28 entry:
29   %0 = tail call i32 (...)* @memcmp(i8* %X, i8* getelementptr inbounds ([23 x i8]* @.str, i32 0, i32 1), i32 2) nounwind ; <i32> [#uses=1]
30   %1 = icmp eq i32 %0, 0                          ; <i1> [#uses=1]
31   br i1 %1, label %return, label %bb
32
33 bb:                                               ; preds = %entry
34   store i32 4, i32* %P, align 4
35   ret void
36
37 return:                                           ; preds = %entry
38   ret void
39 ; CHECK: memcmp2a:
40 ; CHECK: cmpw    $28527, (%rdi)
41 }
42
43
44 define void @memcmp4(i8* %X, i8* %Y, i32* nocapture %P) nounwind {
45 entry:
46   %0 = tail call i32 (...)* @memcmp(i8* %X, i8* %Y, i32 4) nounwind ; <i32> [#uses=1]
47   %1 = icmp eq i32 %0, 0                          ; <i1> [#uses=1]
48   br i1 %1, label %return, label %bb
49
50 bb:                                               ; preds = %entry
51   store i32 4, i32* %P, align 4
52   ret void
53
54 return:                                           ; preds = %entry
55   ret void
56 ; CHECK: memcmp4:
57 ; CHECK: movl    (%rsi), %eax
58 ; CHECK: cmpl    %eax, (%rdi)
59 }
60
61 define void @memcmp4a(i8* %X, i32* nocapture %P) nounwind {
62 entry:
63   %0 = tail call i32 (...)* @memcmp(i8* %X, i8* getelementptr inbounds ([23 x i8]* @.str, i32 0, i32 1), i32 4) nounwind ; <i32> [#uses=1]
64   %1 = icmp eq i32 %0, 0                          ; <i1> [#uses=1]
65   br i1 %1, label %return, label %bb
66
67 bb:                                               ; preds = %entry
68   store i32 4, i32* %P, align 4
69   ret void
70
71 return:                                           ; preds = %entry
72   ret void
73 ; CHECK: memcmp4a:
74 ; CHECK: cmpl $1869573999, (%rdi)
75 }
76
77 define void @memcmp8(i8* %X, i8* %Y, i32* nocapture %P) nounwind {
78 entry:
79   %0 = tail call i32 (...)* @memcmp(i8* %X, i8* %Y, i32 8) nounwind ; <i32> [#uses=1]
80   %1 = icmp eq i32 %0, 0                          ; <i1> [#uses=1]
81   br i1 %1, label %return, label %bb
82
83 bb:                                               ; preds = %entry
84   store i32 4, i32* %P, align 4
85   ret void
86
87 return:                                           ; preds = %entry
88   ret void
89 ; CHECK: memcmp8:
90 ; CHECK: movq    (%rsi), %rax
91 ; CHECK: cmpq    %rax, (%rdi)
92 }
93
94 define void @memcmp8a(i8* %X, i32* nocapture %P) nounwind {
95 entry:
96   %0 = tail call i32 (...)* @memcmp(i8* %X, i8* getelementptr inbounds ([23 x i8]* @.str, i32 0, i32 0), i32 8) nounwind ; <i32> [#uses=1]
97   %1 = icmp eq i32 %0, 0                          ; <i1> [#uses=1]
98   br i1 %1, label %return, label %bb
99
100 bb:                                               ; preds = %entry
101   store i32 4, i32* %P, align 4
102   ret void
103
104 return:                                           ; preds = %entry
105   ret void
106 ; CHECK: memcmp8a:
107 ; CHECK: movabsq $8029759185026510694, %rax
108 ; CHECK: cmpq   %rax, (%rdi)
109 }
110