1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-attributes --check-globals
2 ; RUN: opt -aa-pipeline=basic-aa -passes=attributor -attributor-manifest-internal -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=TUNIT
3 ; RUN: opt -aa-pipeline=basic-aa -passes=attributor-cgscc -attributor-manifest-internal -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CGSCC
6 define internal i8 @read_arg(ptr %p) {
7 ; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read)
8 ; CGSCC-LABEL: define {{[^@]+}}@read_arg
9 ; CGSCC-SAME: (ptr nocapture nofree noundef nonnull readonly dereferenceable(1022) [[P:%.*]]) #[[ATTR0:[0-9]+]] {
11 ; CGSCC-NEXT: [[L:%.*]] = load i8, ptr [[P]], align 1
12 ; CGSCC-NEXT: ret i8 [[L]]
15 %l = load i8, ptr %p, align 1
19 define internal i8 @read_arg_index(ptr %p, i64 %index) {
20 ; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read)
21 ; CGSCC-LABEL: define {{[^@]+}}@read_arg_index
22 ; CGSCC-SAME: (ptr nocapture nofree noundef nonnull readonly align 16 dereferenceable(1024) [[P:%.*]]) #[[ATTR0]] {
24 ; CGSCC-NEXT: [[G:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 2
25 ; CGSCC-NEXT: [[L:%.*]] = load i8, ptr [[G]], align 1
26 ; CGSCC-NEXT: ret i8 [[L]]
29 %g = getelementptr inbounds i8, ptr %p, i64 %index
30 %l = load i8, ptr %g, align 1
34 define i8 @call_simplifiable_1() {
35 ; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
36 ; TUNIT-LABEL: define {{[^@]+}}@call_simplifiable_1
37 ; TUNIT-SAME: () #[[ATTR0:[0-9]+]] {
39 ; TUNIT-NEXT: [[BYTES:%.*]] = alloca [1024 x i8], align 16
40 ; TUNIT-NEXT: [[I0:%.*]] = getelementptr inbounds [1024 x i8], ptr [[BYTES]], i64 0, i64 2
41 ; TUNIT-NEXT: ret i8 2
43 ; CGSCC: Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
44 ; CGSCC-LABEL: define {{[^@]+}}@call_simplifiable_1
45 ; CGSCC-SAME: () #[[ATTR1:[0-9]+]] {
47 ; CGSCC-NEXT: [[BYTES:%.*]] = alloca [1024 x i8], align 16
48 ; CGSCC-NEXT: [[I0:%.*]] = getelementptr inbounds [1024 x i8], ptr [[BYTES]], i64 0, i64 2
49 ; CGSCC-NEXT: store i8 2, ptr [[I0]], align 2
50 ; CGSCC-NEXT: [[R:%.*]] = call i8 @read_arg(ptr nocapture nofree noundef nonnull readonly align 2 dereferenceable(1022) [[I0]]) #[[ATTR4:[0-9]+]]
51 ; CGSCC-NEXT: ret i8 [[R]]
54 %Bytes = alloca [1024 x i8], align 16
55 %i0 = getelementptr inbounds [1024 x i8], ptr %Bytes, i64 0, i64 2
56 store i8 2, ptr %i0, align 1
57 %r = call i8 @read_arg(ptr %i0)
61 ;;; Same as read_arg, but we need a copy to form distinct leaves in the callgraph.
63 define internal i8 @read_arg_1(ptr %p) {
64 ; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read)
65 ; CGSCC-LABEL: define {{[^@]+}}@read_arg_1
66 ; CGSCC-SAME: (ptr nocapture nofree noundef nonnull readonly dereferenceable(1) [[P:%.*]]) #[[ATTR0]] {
68 ; CGSCC-NEXT: [[L:%.*]] = load i8, ptr [[P]], align 1
69 ; CGSCC-NEXT: ret i8 [[L]]
72 %l = load i8, ptr %p, align 1
76 define internal i8 @sum_two_same_loads(ptr %p) {
77 ; CGSCC: Function Attrs: mustprogress nofree nosync nounwind willreturn memory(argmem: read)
78 ; CGSCC-LABEL: define {{[^@]+}}@sum_two_same_loads
79 ; CGSCC-SAME: (ptr nocapture nofree noundef nonnull readonly dereferenceable(1022) [[P:%.*]]) #[[ATTR2:[0-9]+]] {
80 ; CGSCC-NEXT: [[X:%.*]] = call i8 @read_arg_1(ptr nocapture nofree noundef nonnull readonly dereferenceable(1022) [[P]]) #[[ATTR4]]
81 ; CGSCC-NEXT: [[Y:%.*]] = call i8 @read_arg_1(ptr nocapture nofree noundef nonnull readonly dereferenceable(1022) [[P]]) #[[ATTR4]]
82 ; CGSCC-NEXT: [[Z:%.*]] = add nsw i8 [[X]], [[Y]]
83 ; CGSCC-NEXT: ret i8 [[Z]]
85 %x = call i8 @read_arg_1(ptr %p)
86 %y = call i8 @read_arg_1(ptr %p)
87 %z = add nsw i8 %x, %y
91 define i8 @call_simplifiable_2() {
92 ; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
93 ; TUNIT-LABEL: define {{[^@]+}}@call_simplifiable_2
94 ; TUNIT-SAME: () #[[ATTR0]] {
96 ; TUNIT-NEXT: [[BYTES:%.*]] = alloca [1024 x i8], align 16
97 ; TUNIT-NEXT: [[I0:%.*]] = getelementptr inbounds [1024 x i8], ptr [[BYTES]], i64 0, i64 2
98 ; TUNIT-NEXT: [[I1:%.*]] = getelementptr inbounds [1024 x i8], ptr [[BYTES]], i64 0, i64 3
99 ; TUNIT-NEXT: ret i8 4
101 ; CGSCC: Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
102 ; CGSCC-LABEL: define {{[^@]+}}@call_simplifiable_2
103 ; CGSCC-SAME: () #[[ATTR1]] {
105 ; CGSCC-NEXT: [[BYTES:%.*]] = alloca [1024 x i8], align 16
106 ; CGSCC-NEXT: [[I0:%.*]] = getelementptr inbounds [1024 x i8], ptr [[BYTES]], i64 0, i64 2
107 ; CGSCC-NEXT: store i8 2, ptr [[I0]], align 2
108 ; CGSCC-NEXT: [[I1:%.*]] = getelementptr inbounds [1024 x i8], ptr [[BYTES]], i64 0, i64 3
109 ; CGSCC-NEXT: store i8 3, ptr [[I1]], align 1
110 ; CGSCC-NEXT: [[R:%.*]] = call i8 @sum_two_same_loads(ptr nocapture nofree noundef nonnull readonly align 2 dereferenceable(1022) [[I0]]) #[[ATTR4]]
111 ; CGSCC-NEXT: ret i8 [[R]]
114 %Bytes = alloca [1024 x i8], align 16
115 %i0 = getelementptr inbounds [1024 x i8], ptr %Bytes, i64 0, i64 2
117 %i1 = getelementptr inbounds [1024 x i8], ptr %Bytes, i64 0, i64 3
119 %r = call i8 @sum_two_same_loads(ptr %i0)
123 define i8 @call_simplifiable_3() {
124 ; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
125 ; TUNIT-LABEL: define {{[^@]+}}@call_simplifiable_3
126 ; TUNIT-SAME: () #[[ATTR0]] {
128 ; TUNIT-NEXT: [[BYTES:%.*]] = alloca [1024 x i8], align 16
129 ; TUNIT-NEXT: [[I2:%.*]] = getelementptr inbounds [1024 x i8], ptr [[BYTES]], i64 0, i64 2
130 ; TUNIT-NEXT: ret i8 2
132 ; CGSCC: Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
133 ; CGSCC-LABEL: define {{[^@]+}}@call_simplifiable_3
134 ; CGSCC-SAME: () #[[ATTR1]] {
136 ; CGSCC-NEXT: [[BYTES:%.*]] = alloca [1024 x i8], align 16
137 ; CGSCC-NEXT: [[I2:%.*]] = getelementptr inbounds [1024 x i8], ptr [[BYTES]], i64 0, i64 2
138 ; CGSCC-NEXT: store i8 2, ptr [[I2]], align 2
139 ; CGSCC-NEXT: [[R:%.*]] = call i8 @read_arg_index(ptr nocapture nofree noundef nonnull readonly align 16 dereferenceable(1024) [[BYTES]]) #[[ATTR4]]
140 ; CGSCC-NEXT: ret i8 [[R]]
143 %Bytes = alloca [1024 x i8], align 16
144 %i0 = getelementptr inbounds [1024 x i8], ptr %Bytes, i64 0, i64 0
145 %i2 = getelementptr inbounds [1024 x i8], ptr %Bytes, i64 0, i64 2
146 store i8 2, ptr %i2, align 1
147 %r = call i8 @read_arg_index(ptr %i0, i64 2)
151 ;;; Same as read_arg, but we need a copy to form distinct leaves in the callgraph.
153 define internal i8 @read_arg_2(ptr %p) {
154 ; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read)
155 ; TUNIT-LABEL: define {{[^@]+}}@read_arg_2
156 ; TUNIT-SAME: (ptr nocapture nofree noundef nonnull readonly dereferenceable(971) [[P:%.*]]) #[[ATTR1:[0-9]+]] {
158 ; TUNIT-NEXT: [[L:%.*]] = load i8, ptr [[P]], align 1
159 ; TUNIT-NEXT: ret i8 [[L]]
161 ; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read)
162 ; CGSCC-LABEL: define {{[^@]+}}@read_arg_2
163 ; CGSCC-SAME: (ptr nocapture nofree noundef nonnull readonly dereferenceable(1) [[P:%.*]]) #[[ATTR0]] {
165 ; CGSCC-NEXT: [[L:%.*]] = load i8, ptr [[P]], align 1
166 ; CGSCC-NEXT: ret i8 [[L]]
169 %l = load i8, ptr %p, align 1
173 define internal i8 @sum_two_different_loads(ptr %p, ptr %q) {
174 ; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read)
175 ; TUNIT-LABEL: define {{[^@]+}}@sum_two_different_loads
176 ; TUNIT-SAME: (ptr nocapture nofree nonnull readonly dereferenceable(972) [[P:%.*]], ptr nocapture nofree noundef nonnull readonly dereferenceable(971) [[Q:%.*]]) #[[ATTR1]] {
177 ; TUNIT-NEXT: [[X:%.*]] = call i8 @read_arg_2(ptr nocapture nofree noundef nonnull readonly dereferenceable(972) [[P]]) #[[ATTR3:[0-9]+]]
178 ; TUNIT-NEXT: [[Y:%.*]] = call i8 @read_arg_2(ptr nocapture nofree noundef nonnull readonly dereferenceable(971) [[Q]]) #[[ATTR3]]
179 ; TUNIT-NEXT: [[Z:%.*]] = add nsw i8 [[X]], [[Y]]
180 ; TUNIT-NEXT: ret i8 [[Z]]
182 ; CGSCC: Function Attrs: mustprogress nofree nosync nounwind willreturn memory(argmem: read)
183 ; CGSCC-LABEL: define {{[^@]+}}@sum_two_different_loads
184 ; CGSCC-SAME: (ptr nocapture nofree noundef nonnull readonly dereferenceable(972) [[P:%.*]], ptr nocapture nofree noundef nonnull readonly dereferenceable(971) [[Q:%.*]]) #[[ATTR2]] {
185 ; CGSCC-NEXT: [[X:%.*]] = call i8 @read_arg_2(ptr nocapture nofree noundef nonnull readonly dereferenceable(972) [[P]]) #[[ATTR4]]
186 ; CGSCC-NEXT: [[Y:%.*]] = call i8 @read_arg_2(ptr nocapture nofree noundef nonnull readonly dereferenceable(971) [[Q]]) #[[ATTR4]]
187 ; CGSCC-NEXT: [[Z:%.*]] = add nsw i8 [[X]], [[Y]]
188 ; CGSCC-NEXT: ret i8 [[Z]]
190 %x = call i8 @read_arg_2(ptr %p)
191 %y = call i8 @read_arg_2(ptr %q)
192 %z = add nsw i8 %x, %y
196 define i8 @call_partially_simplifiable_1() {
197 ; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
198 ; TUNIT-LABEL: define {{[^@]+}}@call_partially_simplifiable_1
199 ; TUNIT-SAME: () #[[ATTR0]] {
201 ; TUNIT-NEXT: [[BYTES:%.*]] = alloca [1024 x i8], align 16
202 ; TUNIT-NEXT: [[I2:%.*]] = getelementptr inbounds [1024 x i8], ptr [[BYTES]], i64 0, i64 2
203 ; TUNIT-NEXT: store i8 2, ptr [[I2]], align 2
204 ; TUNIT-NEXT: [[I3:%.*]] = getelementptr inbounds [1024 x i8], ptr [[BYTES]], i64 0, i64 3
205 ; TUNIT-NEXT: store i8 3, ptr [[I3]], align 1
206 ; TUNIT-NEXT: [[I4:%.*]] = getelementptr inbounds [1024 x i8], ptr [[BYTES]], i64 0, i64 4
207 ; TUNIT-NEXT: [[R:%.*]] = call i8 @sum_two_different_loads(ptr nocapture nofree noundef nonnull readonly align 2 dereferenceable(1022) [[I2]], ptr nocapture nofree noundef nonnull readonly dereferenceable(1021) [[I3]]) #[[ATTR3]]
208 ; TUNIT-NEXT: ret i8 [[R]]
210 ; CGSCC: Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
211 ; CGSCC-LABEL: define {{[^@]+}}@call_partially_simplifiable_1
212 ; CGSCC-SAME: () #[[ATTR1]] {
214 ; CGSCC-NEXT: [[BYTES:%.*]] = alloca [1024 x i8], align 16
215 ; CGSCC-NEXT: [[I2:%.*]] = getelementptr inbounds [1024 x i8], ptr [[BYTES]], i64 0, i64 2
216 ; CGSCC-NEXT: store i8 2, ptr [[I2]], align 2
217 ; CGSCC-NEXT: [[I3:%.*]] = getelementptr inbounds [1024 x i8], ptr [[BYTES]], i64 0, i64 3
218 ; CGSCC-NEXT: store i8 3, ptr [[I3]], align 1
219 ; CGSCC-NEXT: [[I4:%.*]] = getelementptr inbounds [1024 x i8], ptr [[BYTES]], i64 0, i64 4
220 ; CGSCC-NEXT: store i8 4, ptr [[I4]], align 4
221 ; CGSCC-NEXT: [[R:%.*]] = call i8 @sum_two_different_loads(ptr nocapture nofree noundef nonnull readonly align 2 dereferenceable(1022) [[I2]], ptr nocapture nofree noundef nonnull readonly dereferenceable(1021) [[I3]]) #[[ATTR4]]
222 ; CGSCC-NEXT: ret i8 [[R]]
225 %Bytes = alloca [1024 x i8], align 16
226 %i2 = getelementptr inbounds [1024 x i8], ptr %Bytes, i64 0, i64 2
228 %i3 = getelementptr inbounds [1024 x i8], ptr %Bytes, i64 0, i64 3
230 %i4 = getelementptr inbounds [1024 x i8], ptr %Bytes, i64 0, i64 4
231 ;;; This store is redundant, hence removed.
233 %r = call i8 @sum_two_different_loads(ptr %i2, ptr %i3)
237 define i8 @call_partially_simplifiable_2(i1 %cond) {
238 ; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn
239 ; TUNIT-LABEL: define {{[^@]+}}@call_partially_simplifiable_2
240 ; TUNIT-SAME: (i1 [[COND:%.*]]) #[[ATTR2:[0-9]+]] {
242 ; TUNIT-NEXT: [[BYTES:%.*]] = alloca [1024 x i8], align 16
243 ; TUNIT-NEXT: [[I51:%.*]] = getelementptr inbounds [1024 x i8], ptr [[BYTES]], i64 0, i64 51
244 ; TUNIT-NEXT: [[I52:%.*]] = getelementptr inbounds [1024 x i8], ptr [[BYTES]], i64 0, i64 52
245 ; TUNIT-NEXT: store i8 2, ptr [[I52]], align 4
246 ; TUNIT-NEXT: [[I53:%.*]] = getelementptr inbounds [1024 x i8], ptr [[BYTES]], i64 0, i64 53
247 ; TUNIT-NEXT: store i8 3, ptr [[I53]], align 1
248 ; TUNIT-NEXT: [[I54:%.*]] = getelementptr inbounds [1024 x i8], ptr [[BYTES]], i64 0, i64 54
249 ; TUNIT-NEXT: [[SEL:%.*]] = select i1 [[COND]], ptr [[I51]], ptr [[I52]]
250 ; TUNIT-NEXT: [[R:%.*]] = call i8 @sum_two_different_loads(ptr nocapture nofree nonnull readonly dereferenceable(972) [[SEL]], ptr nocapture nofree noundef nonnull readonly dereferenceable(971) [[I53]]) #[[ATTR3]]
251 ; TUNIT-NEXT: ret i8 [[R]]
253 ; CGSCC: Function Attrs: mustprogress nofree nosync nounwind willreturn
254 ; CGSCC-LABEL: define {{[^@]+}}@call_partially_simplifiable_2
255 ; CGSCC-SAME: (i1 [[COND:%.*]]) #[[ATTR3:[0-9]+]] {
257 ; CGSCC-NEXT: [[BYTES:%.*]] = alloca [1024 x i8], align 16
258 ; CGSCC-NEXT: [[I51:%.*]] = getelementptr inbounds [1024 x i8], ptr [[BYTES]], i64 0, i64 51
259 ; CGSCC-NEXT: [[I52:%.*]] = getelementptr inbounds [1024 x i8], ptr [[BYTES]], i64 0, i64 52
260 ; CGSCC-NEXT: store i8 2, ptr [[I52]], align 4
261 ; CGSCC-NEXT: [[I53:%.*]] = getelementptr inbounds [1024 x i8], ptr [[BYTES]], i64 0, i64 53
262 ; CGSCC-NEXT: store i8 3, ptr [[I53]], align 1
263 ; CGSCC-NEXT: [[I54:%.*]] = getelementptr inbounds [1024 x i8], ptr [[BYTES]], i64 0, i64 54
264 ; CGSCC-NEXT: store i8 4, ptr [[I54]], align 2
265 ; CGSCC-NEXT: [[SEL:%.*]] = select i1 [[COND]], ptr [[I51]], ptr [[I52]]
266 ; CGSCC-NEXT: [[R:%.*]] = call i8 @sum_two_different_loads(ptr nocapture nofree noundef nonnull readonly dereferenceable(972) [[SEL]], ptr nocapture nofree noundef nonnull readonly dereferenceable(971) [[I53]]) #[[ATTR4]]
267 ; CGSCC-NEXT: ret i8 [[R]]
270 %Bytes = alloca [1024 x i8], align 16
271 %i51 = getelementptr inbounds [1024 x i8], ptr %Bytes, i64 0, i64 51
272 %i52 = getelementptr inbounds [1024 x i8], ptr %Bytes, i64 0, i64 52
274 %i53 = getelementptr inbounds [1024 x i8], ptr %Bytes, i64 0, i64 53
276 %i54 = getelementptr inbounds [1024 x i8], ptr %Bytes, i64 0, i64 54
277 ;;; This store is redundant, hence removed. Not affected by the select.
279 %sel = select i1 %cond, ptr %i51, ptr %i52
280 %r = call i8 @sum_two_different_loads(ptr %sel, ptr %i53)
285 ; TUNIT: attributes #[[ATTR0]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) }
286 ; TUNIT: attributes #[[ATTR1]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) }
287 ; TUNIT: attributes #[[ATTR2]] = { mustprogress nofree norecurse nosync nounwind willreturn }
288 ; TUNIT: attributes #[[ATTR3]] = { nofree nosync nounwind willreturn memory(read) }
290 ; CGSCC: attributes #[[ATTR0]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) }
291 ; CGSCC: attributes #[[ATTR1]] = { mustprogress nofree nosync nounwind willreturn memory(none) }
292 ; CGSCC: attributes #[[ATTR2]] = { mustprogress nofree nosync nounwind willreturn memory(argmem: read) }
293 ; CGSCC: attributes #[[ATTR3]] = { mustprogress nofree nosync nounwind willreturn }
294 ; CGSCC: attributes #[[ATTR4]] = { nofree willreturn memory(read) }