1; RUN: opt -mtriple=i386-pc-linux-gnu -inferattrs -basic-aa -aa-eval -print-all-alias-modref-info -disable-output 2>&1 %s | FileCheck %s
2
3; CHECK-LABEL: Function: test_memcmp_const_size
4; CHECK:      Just Ref:  Ptr: i8* %a	<->  %res = tail call i32 @memcmp(i8* %a, i8* %b, i64 4)
5; CHECK-NEXT: Just Ref:  Ptr: i8* %b	<->  %res = tail call i32 @memcmp(i8* %a, i8* %b, i64 4)
6; CHECK-NEXT: Just Ref:  Ptr: i8* %a.gep.1	<->  %res = tail call i32 @memcmp(i8* %a, i8* %b, i64 4)
7; CHECK-NEXT: NoModRef:  Ptr: i8* %a.gep.5	<->  %res = tail call i32 @memcmp(i8* %a, i8* %b, i64 4)
8; CHECK-NEXT: Just Ref:  Ptr: i8* %b.gep.1	<->  %res = tail call i32 @memcmp(i8* %a, i8* %b, i64 4)
9; CHECK-NEXT: NoModRef:  Ptr: i8* %b.gep.5	<->  %res = tail call i32 @memcmp(i8* %a, i8* %b, i64 4)
10define i32 @test_memcmp_const_size(i8* noalias %a, i8* noalias %b) {
11entry:
12  %res = tail call i32 @memcmp(i8* %a, i8* %b, i64 4)
13  %a.gep.1 = getelementptr i8, i8* %a, i32 1
14  store i8 0, i8* %a.gep.1
15  %a.gep.5 = getelementptr i8, i8* %a, i32 5
16  store i8 1, i8* %a.gep.5
17  %b.gep.1 = getelementptr i8, i8* %b, i32 1
18  store i8 2, i8* %b.gep.1
19  %b.gep.5 = getelementptr i8, i8* %b, i32 5
20  store i8 3, i8* %b.gep.5
21  ret i32 %res
22}
23
24; CHECK-LABEL: Function: test_memcmp_variable_size
25; CHECK:      Just Ref:  Ptr: i8* %a	<->  %res = tail call i32 @memcmp(i8* %a, i8* %b, i64 %n)
26; CHECK-NEXT: Just Ref:  Ptr: i8* %b	<->  %res = tail call i32 @memcmp(i8* %a, i8* %b, i64 %n)
27; CHECK-NEXT: Just Ref:  Ptr: i8* %a.gep.1	<->  %res = tail call i32 @memcmp(i8* %a, i8* %b, i64 %n)
28; CHECK-NEXT: Just Ref:  Ptr: i8* %a.gep.5	<->  %res = tail call i32 @memcmp(i8* %a, i8* %b, i64 %n)
29; CHECK-NEXT: Just Ref:  Ptr: i8* %b.gep.1	<->  %res = tail call i32 @memcmp(i8* %a, i8* %b, i64 %n)
30; CHECK-NEXT: Just Ref:  Ptr: i8* %b.gep.5	<->  %res = tail call i32 @memcmp(i8* %a, i8* %b, i64 %n)
31define i32 @test_memcmp_variable_size(i8* noalias %a, i8* noalias %b, i64 %n) {
32entry:
33  %res = tail call i32 @memcmp(i8* %a, i8* %b, i64 %n)
34  %a.gep.1 = getelementptr i8, i8* %a, i32 1
35  store i8 0, i8* %a.gep.1
36  %a.gep.5 = getelementptr i8, i8* %a, i32 5
37  store i8 1, i8* %a.gep.5
38  %b.gep.1 = getelementptr i8, i8* %b, i32 1
39  store i8 2, i8* %b.gep.1
40  %b.gep.5 = getelementptr i8, i8* %b, i32 5
41  store i8 3, i8* %b.gep.5
42  ret i32 %res
43}
44
45declare i32 @memcmp(i8*, i8*, i64)
46declare i32 @bcmp(i8*, i8*, i64)
47
48; CHECK-LABEL: Function: test_bcmp_const_size
49; CHECK:      Just Ref:  Ptr: i8* %a	<->  %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 4)
50; CHECK-NEXT: Just Ref:  Ptr: i8* %b	<->  %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 4)
51; CHECK-NEXT: Just Ref:  Ptr: i8* %a.gep.1	<->  %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 4)
52; CHECK-NEXT: NoModRef:  Ptr: i8* %a.gep.5	<->  %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 4)
53; CHECK-NEXT: Just Ref:  Ptr: i8* %b.gep.1	<->  %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 4)
54; CHECK-NEXT: NoModRef:  Ptr: i8* %b.gep.5	<->  %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 4)
55define i32 @test_bcmp_const_size(i8* noalias %a, i8* noalias %b) {
56entry:
57  %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 4)
58  %a.gep.1 = getelementptr i8, i8* %a, i32 1
59  store i8 0, i8* %a.gep.1
60  %a.gep.5 = getelementptr i8, i8* %a, i32 5
61  store i8 1, i8* %a.gep.5
62  %b.gep.1 = getelementptr i8, i8* %b, i32 1
63  store i8 2, i8* %b.gep.1
64  %b.gep.5 = getelementptr i8, i8* %b, i32 5
65  store i8 3, i8* %b.gep.5
66  ret i32 %res
67}
68
69; CHECK-LABEL: Function: test_bcmp_variable_size
70; CHECK:      Just Ref:  Ptr: i8* %a	<->  %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 %n)
71; CHECK-NEXT: Just Ref:  Ptr: i8* %b	<->  %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 %n)
72; CHECK-NEXT: Just Ref:  Ptr: i8* %a.gep.1	<->  %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 %n)
73; CHECK-NEXT: Just Ref:  Ptr: i8* %a.gep.5	<->  %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 %n)
74; CHECK-NEXT: Just Ref:  Ptr: i8* %b.gep.1	<->  %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 %n)
75; CHECK-NEXT: Just Ref:  Ptr: i8* %b.gep.5	<->  %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 %n)
76define i32 @test_bcmp_variable_size(i8* noalias %a, i8* noalias %b, i64 %n) {
77entry:
78  %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 %n)
79  %a.gep.1 = getelementptr i8, i8* %a, i32 1
80  store i8 0, i8* %a.gep.1
81  %a.gep.5 = getelementptr i8, i8* %a, i32 5
82  store i8 1, i8* %a.gep.5
83  %b.gep.1 = getelementptr i8, i8* %b, i32 1
84  store i8 2, i8* %b.gep.1
85  %b.gep.5 = getelementptr i8, i8* %b, i32 5
86  store i8 3, i8* %b.gep.5
87  ret i32 %res
88}
89
90declare i8* @memchr(i8*, i32, i64)
91
92; CHECK-LABEL: Function: test_memchr_const_size
93; CHECK: Just Ref:  Ptr: i8* %res      <->  %res = call i8* @memchr(i8* %a, i32 42, i64 4)
94; CHECK-NEXT: Just Ref:  Ptr: i8* %a.gep.1  <->  %res = call i8* @memchr(i8* %a, i32 42, i64 4)
95; CHECK-NEXT: NoModRef:  Ptr: i8* %a.gep.5  <->  %res = call i8* @memchr(i8* %a, i32 42, i64 4)
96define i8* @test_memchr_const_size(i8* noalias %a) {
97entry:
98  %res = call i8* @memchr(i8* %a, i32 42, i64 4)
99  %a.gep.1 = getelementptr i8, i8* %a, i32 1
100  store i8 0, i8* %a.gep.1
101  %a.gep.5 = getelementptr i8, i8* %a, i32 5
102  store i8 1, i8* %a.gep.5
103  ret i8* %res
104}
105
106declare i8* @memccpy(i8*, i8*, i32, i64)
107
108; CHECK-LABEL: Function: test_memccpy_const_size
109; CHECK:      Just Mod:  Ptr: i8* %a        <->  %res = call i8* @memccpy(i8* %a, i8* %b, i32 42, i64 4)
110; CHECK-NEXT: Just Ref:  Ptr: i8* %b        <->  %res = call i8* @memccpy(i8* %a, i8* %b, i32 42, i64 4)
111; CHECK-NEXT: Just Mod:  Ptr: i8* %res      <->  %res = call i8* @memccpy(i8* %a, i8* %b, i32 42, i64 4)
112; CHECK-NEXT: Just Mod:  Ptr: i8* %a.gep.1  <->  %res = call i8* @memccpy(i8* %a, i8* %b, i32 42, i64 4)
113; CHECK-NEXT: NoModRef:  Ptr: i8* %a.gep.5  <->  %res = call i8* @memccpy(i8* %a, i8* %b, i32 42, i64 4)
114; CHECK-NEXT: Just Ref:  Ptr: i8* %b.gep.1  <->  %res = call i8* @memccpy(i8* %a, i8* %b, i32 42, i64 4)
115; CHECK-NEXT: NoModRef:  Ptr: i8* %b.gep.5  <->  %res = call i8* @memccpy(i8* %a, i8* %b, i32 42, i64 4)
116
117define i8* @test_memccpy_const_size(i8* noalias %a, i8* noalias %b) {
118entry:
119  %res = call i8* @memccpy(i8* %a, i8* %b, i32 42, i64 4)
120  %a.gep.1 = getelementptr i8, i8* %a, i32 1
121  store i8 0, i8* %a.gep.1
122  %a.gep.5 = getelementptr i8, i8* %a, i32 5
123  store i8 1, i8* %a.gep.5
124  %b.gep.1 = getelementptr i8, i8* %b, i32 1
125  store i8 2, i8* %b.gep.1
126  %b.gep.5 = getelementptr i8, i8* %b, i32 5
127  store i8 3, i8* %b.gep.5
128  ret i8* %res
129}
130
131declare i8* @strncpy(i8*, i8*, i64)
132
133define i8* @test_strncpy_const_size(i8* noalias %a, i8* noalias %b) {
134; CHECK-LABEL: Function: test_strncpy_const_size
135; CHECK:       Just Mod:  Ptr: i8* %a	<->  %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 4)
136; CHECK-NEXT:  Just Ref:  Ptr: i8* %b	<->  %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 4)
137; CHECK-NEXT:  Just Mod:  Ptr: i8* %res	<->  %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 4)
138; CHECK-NEXT:  Just Mod:  Ptr: i8* %a.gep.1	<->  %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 4)
139; CHECK-NEXT:  Just Mod:  Ptr: i8* %a.gep.5	<->  %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 4)
140; CHECK-NEXT:  Just Ref:  Ptr: i8* %b.gep.1	<->  %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 4)
141; CHECK-NEXT:  Just Ref:  Ptr: i8* %b.gep.5	<->  %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 4)
142;
143entry:
144  %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 4)
145  %a.gep.1 = getelementptr i8, i8* %a, i32 1
146  store i8 0, i8* %a.gep.1
147  %a.gep.5 = getelementptr i8, i8* %a, i32 5
148  store i8 1, i8* %a.gep.5
149  %b.gep.1 = getelementptr i8, i8* %b, i32 1
150  store i8 2, i8* %b.gep.1
151  %b.gep.5 = getelementptr i8, i8* %b, i32 5
152  store i8 3, i8* %b.gep.5
153  ret i8* %res
154}
155
156define i8* @test_strncpy_variable_size(i8* noalias %a, i8* noalias %b, i64 %n) {
157; CHECK-LABEL: Function: test_strncpy_variable_size
158; CHECK:       Just Mod:  Ptr: i8* %a	<->  %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 %n)
159; CHECK-NEXT:  Just Ref:  Ptr: i8* %b	<->  %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 %n)
160; CHECK-NEXT:  Just Mod:  Ptr: i8* %res	<->  %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 %n)
161; CHECK-NEXT:  Just Mod:  Ptr: i8* %a.gep.1	<->  %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 %n)
162; CHECK-NEXT:  Just Mod:  Ptr: i8* %a.gep.5	<->  %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 %n)
163; CHECK-NEXT:  Just Ref:  Ptr: i8* %b.gep.1	<->  %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 %n)
164; CHECK-NEXT:  Just Ref:  Ptr: i8* %b.gep.5	<->  %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 %n)
165;
166entry:
167  %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 %n)
168  %a.gep.1 = getelementptr i8, i8* %a, i32 1
169  store i8 0, i8* %a.gep.1
170  %a.gep.5 = getelementptr i8, i8* %a, i32 5
171  store i8 1, i8* %a.gep.5
172  %b.gep.1 = getelementptr i8, i8* %b, i32 1
173  store i8 2, i8* %b.gep.1
174  %b.gep.5 = getelementptr i8, i8* %b, i32 5
175  store i8 3, i8* %b.gep.5
176  ret i8* %res
177}
178
179declare i8* @__memset_chk(i8* writeonly, i32, i64, i64)
180
181; CHECK-LABEL: Function: test_memset_chk_const_size
182define i8* @test_memset_chk_const_size(i8* noalias %a, i64 %n) {
183; CHECK:       Just Mod (MustAlias):  Ptr: i8* %a	<->  %res = tail call i8* @__memset_chk(i8* %a, i32 0, i64 4, i64 %n)
184; CHECK-NEXT:  Just Mod:  Ptr: i8* %res	<->  %res = tail call i8* @__memset_chk(i8* %a, i32 0, i64 4, i64 %n)
185; CHECK-NEXT:  Just Mod:  Ptr: i8* %a.gep.1	<->  %res = tail call i8* @__memset_chk(i8* %a, i32 0, i64 4, i64 %n)
186; CHECK-NEXT:  Just Mod:  Ptr: i8* %a.gep.5	<->  %res = tail call i8* @__memset_chk(i8* %a, i32 0, i64 4, i64 %n)
187;
188entry:
189  %res = tail call i8* @__memset_chk(i8* %a, i32 0, i64 4, i64 %n)
190  %a.gep.1 = getelementptr i8, i8* %a, i32 1
191  store i8 0, i8* %a.gep.1
192  %a.gep.5 = getelementptr i8, i8* %a, i32 5
193  store i8 1, i8* %a.gep.5
194  ret i8* %res
195}
196
197define i8* @test_memset_chk_variable_size(i8* noalias %a, i64 %n.1, i64 %n.2) {
198; CHECK-LABEL: Function: test_memset_chk_variable_size
199; CHECK:       Just Mod (MustAlias):  Ptr: i8* %a	<->  %res = tail call i8* @__memset_chk(i8* %a, i32 0, i64 %n.1, i64 %n.2)
200; CHECK-NEXT:  Just Mod:  Ptr: i8* %res	<->  %res = tail call i8* @__memset_chk(i8* %a, i32 0, i64 %n.1, i64 %n.2)
201; CHECK-NEXT:  Just Mod:  Ptr: i8* %a.gep.1	<->  %res = tail call i8* @__memset_chk(i8* %a, i32 0, i64 %n.1, i64 %n.2)
202; CHECK-NEXT:  Just Mod:  Ptr: i8* %a.gep.5	<->  %res = tail call i8* @__memset_chk(i8* %a, i32 0, i64 %n.1, i64 %n.2)
203;
204entry:
205  %res = tail call i8* @__memset_chk(i8* %a, i32 0, i64 %n.1, i64 %n.2)
206  %a.gep.1 = getelementptr i8, i8* %a, i32 1
207  store i8 0, i8* %a.gep.1
208  %a.gep.5 = getelementptr i8, i8* %a, i32 5
209  store i8 1, i8* %a.gep.5
210  ret i8* %res
211}
212