xref: /llvm-project/llvm/test/Transforms/Attributor/nocapture-1.ll (revision 29441e4f5fa5f5c7709f7cf180815ba97f611297)
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=CHECK,TUNIT
3; RUN: opt -aa-pipeline=basic-aa -passes=attributor-cgscc -attributor-manifest-internal  -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,CGSCC
4
5@g = global ptr null		; <ptr> [#uses=1]
6
7;.
8; CHECK: @g = global ptr null
9; CHECK: @lookup_table = global [2 x i1] [i1 false, i1 true]
10; CHECK: @g2 = global ptr null
11; CHECK: @g3 = global ptr null
12;.
13define ptr @c1(ptr %q) {
14; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
15; CHECK-LABEL: define {{[^@]+}}@c1
16; CHECK-SAME: (ptr nofree readnone returned "no-capture-maybe-returned" [[Q:%.*]]) #[[ATTR0:[0-9]+]] {
17; CHECK-NEXT:    ret ptr [[Q]]
18;
19  ret ptr %q
20}
21
22; It would also be acceptable to mark %q as readnone. Update @c3 too.
23define void @c2(ptr %q) {
24; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write)
25; CHECK-LABEL: define {{[^@]+}}@c2
26; CHECK-SAME: (ptr nofree writeonly [[Q:%.*]]) #[[ATTR1:[0-9]+]] {
27; CHECK-NEXT:    store ptr [[Q]], ptr @g, align 8
28; CHECK-NEXT:    ret void
29;
30  store ptr %q, ptr @g
31  ret void
32}
33
34define void @c3(ptr %q) {
35; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write)
36; TUNIT-LABEL: define {{[^@]+}}@c3
37; TUNIT-SAME: (ptr nofree writeonly [[Q:%.*]]) #[[ATTR1]] {
38; TUNIT-NEXT:    call void @c2(ptr nofree writeonly [[Q]]) #[[ATTR17:[0-9]+]]
39; TUNIT-NEXT:    ret void
40;
41; CGSCC: Function Attrs: mustprogress nofree nosync nounwind willreturn memory(write)
42; CGSCC-LABEL: define {{[^@]+}}@c3
43; CGSCC-SAME: (ptr nofree writeonly [[Q:%.*]]) #[[ATTR2:[0-9]+]] {
44; CGSCC-NEXT:    call void @c2(ptr nofree writeonly [[Q]]) #[[ATTR20:[0-9]+]]
45; CGSCC-NEXT:    ret void
46;
47  call void @c2(ptr %q)
48  ret void
49}
50
51define i1 @c4(ptr %q, i32 %bitno) {
52; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
53; CHECK-LABEL: define {{[^@]+}}@c4
54; CHECK-SAME: (ptr nofree readnone [[Q:%.*]], i32 [[BITNO:%.*]]) #[[ATTR0]] {
55; CHECK-NEXT:    [[TMP:%.*]] = ptrtoint ptr [[Q]] to i32
56; CHECK-NEXT:    [[TMP2:%.*]] = lshr i32 [[TMP]], [[BITNO]]
57; CHECK-NEXT:    [[BIT:%.*]] = trunc i32 [[TMP2]] to i1
58; CHECK-NEXT:    br i1 [[BIT]], label [[L1:%.*]], label [[L0:%.*]]
59; CHECK:       l0:
60; CHECK-NEXT:    ret i1 false
61; CHECK:       l1:
62; CHECK-NEXT:    ret i1 true
63;
64  %tmp = ptrtoint ptr %q to i32
65  %tmp2 = lshr i32 %tmp, %bitno
66  %bit = trunc i32 %tmp2 to i1
67  br i1 %bit, label %l1, label %l0
68l0:
69  ret i1 0 ; escaping value not caught by def-use chaining.
70l1:
71  ret i1 1 ; escaping value not caught by def-use chaining.
72}
73
74; c4b is c4 but without the escaping part
75define i1 @c4b(ptr %q, i32 %bitno) {
76; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
77; CHECK-LABEL: define {{[^@]+}}@c4b
78; CHECK-SAME: (ptr nofree readnone captures(none) [[Q:%.*]], i32 [[BITNO:%.*]]) #[[ATTR0]] {
79; CHECK-NEXT:    [[TMP:%.*]] = ptrtoint ptr [[Q]] to i32
80; CHECK-NEXT:    [[TMP2:%.*]] = lshr i32 [[TMP]], [[BITNO]]
81; CHECK-NEXT:    [[BIT:%.*]] = trunc i32 [[TMP2]] to i1
82; CHECK-NEXT:    br i1 [[BIT]], label [[L1:%.*]], label [[L0:%.*]]
83; CHECK:       l0:
84; CHECK-NEXT:    ret i1 false
85; CHECK:       l1:
86; CHECK-NEXT:    ret i1 false
87;
88  %tmp = ptrtoint ptr %q to i32
89  %tmp2 = lshr i32 %tmp, %bitno
90  %bit = trunc i32 %tmp2 to i1
91  br i1 %bit, label %l1, label %l0
92l0:
93  ret i1 0 ; not escaping!
94l1:
95  ret i1 0 ; not escaping!
96}
97
98@lookup_table = global [2 x i1] [ i1 0, i1 1 ]
99
100define i1 @c5(ptr %q, i32 %bitno) {
101; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read)
102; TUNIT-LABEL: define {{[^@]+}}@c5
103; TUNIT-SAME: (ptr nofree readonly [[Q:%.*]], i32 [[BITNO:%.*]]) #[[ATTR2:[0-9]+]] {
104; TUNIT-NEXT:    [[TMP:%.*]] = ptrtoint ptr [[Q]] to i32
105; TUNIT-NEXT:    [[TMP2:%.*]] = lshr i32 [[TMP]], [[BITNO]]
106; TUNIT-NEXT:    [[BIT:%.*]] = and i32 [[TMP2]], 1
107; TUNIT-NEXT:    [[LOOKUP:%.*]] = getelementptr [2 x i1], ptr @lookup_table, i32 0, i32 [[BIT]]
108; TUNIT-NEXT:    [[VAL:%.*]] = load i1, ptr [[LOOKUP]], align 1
109; TUNIT-NEXT:    ret i1 [[VAL]]
110;
111; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read)
112; CGSCC-LABEL: define {{[^@]+}}@c5
113; CGSCC-SAME: (ptr nofree readonly [[Q:%.*]], i32 [[BITNO:%.*]]) #[[ATTR3:[0-9]+]] {
114; CGSCC-NEXT:    [[TMP:%.*]] = ptrtoint ptr [[Q]] to i32
115; CGSCC-NEXT:    [[TMP2:%.*]] = lshr i32 [[TMP]], [[BITNO]]
116; CGSCC-NEXT:    [[BIT:%.*]] = and i32 [[TMP2]], 1
117; CGSCC-NEXT:    [[LOOKUP:%.*]] = getelementptr [2 x i1], ptr @lookup_table, i32 0, i32 [[BIT]]
118; CGSCC-NEXT:    [[VAL:%.*]] = load i1, ptr [[LOOKUP]], align 1
119; CGSCC-NEXT:    ret i1 [[VAL]]
120;
121  %tmp = ptrtoint ptr %q to i32
122  %tmp2 = lshr i32 %tmp, %bitno
123  %bit = and i32 %tmp2, 1
124  ; subtle escape mechanism follows
125  %lookup = getelementptr [2 x i1], ptr @lookup_table, i32 0, i32 %bit
126  %val = load i1, ptr %lookup
127  ret i1 %val
128}
129
130declare void @throw_if_bit_set(ptr, i8) readonly
131
132define i1 @c6(ptr %q, i8 %bit) personality ptr @__gxx_personality_v0 {
133; TUNIT: Function Attrs: nosync memory(read)
134; TUNIT-LABEL: define {{[^@]+}}@c6
135; TUNIT-SAME: (ptr readonly [[Q:%.*]], i8 [[BIT:%.*]]) #[[ATTR4:[0-9]+]] personality ptr @__gxx_personality_v0 {
136; TUNIT-NEXT:    invoke void @throw_if_bit_set(ptr readonly [[Q]], i8 [[BIT]]) #[[ATTR4]]
137; TUNIT-NEXT:            to label [[RET0:%.*]] unwind label [[RET1:%.*]]
138; TUNIT:       ret0:
139; TUNIT-NEXT:    ret i1 false
140; TUNIT:       ret1:
141; TUNIT-NEXT:    [[EXN:%.*]] = landingpad { ptr, i32 }
142; TUNIT-NEXT:            cleanup
143; TUNIT-NEXT:    ret i1 true
144;
145; CGSCC: Function Attrs: nosync memory(read)
146; CGSCC-LABEL: define {{[^@]+}}@c6
147; CGSCC-SAME: (ptr readonly [[Q:%.*]], i8 [[BIT:%.*]]) #[[ATTR5:[0-9]+]] personality ptr @__gxx_personality_v0 {
148; CGSCC-NEXT:    invoke void @throw_if_bit_set(ptr readonly [[Q]], i8 [[BIT]]) #[[ATTR5]]
149; CGSCC-NEXT:            to label [[RET0:%.*]] unwind label [[RET1:%.*]]
150; CGSCC:       ret0:
151; CGSCC-NEXT:    ret i1 false
152; CGSCC:       ret1:
153; CGSCC-NEXT:    [[EXN:%.*]] = landingpad { ptr, i32 }
154; CGSCC-NEXT:            cleanup
155; CGSCC-NEXT:    ret i1 true
156;
157  invoke void @throw_if_bit_set(ptr %q, i8 %bit)
158  to label %ret0 unwind label %ret1
159ret0:
160  ret i1 0
161ret1:
162  %exn = landingpad {ptr, i32}
163  cleanup
164  ret i1 1
165}
166
167declare i32 @__gxx_personality_v0(...)
168
169define ptr @lookup_bit(ptr %q, i32 %bitno) readnone nounwind {
170; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
171; CHECK-LABEL: define {{[^@]+}}@lookup_bit
172; CHECK-SAME: (ptr nofree readnone [[Q:%.*]], i32 [[BITNO:%.*]]) #[[ATTR0]] {
173; CHECK-NEXT:    [[TMP:%.*]] = ptrtoint ptr [[Q]] to i32
174; CHECK-NEXT:    [[TMP2:%.*]] = lshr i32 [[TMP]], [[BITNO]]
175; CHECK-NEXT:    [[BIT:%.*]] = and i32 [[TMP2]], 1
176; CHECK-NEXT:    [[LOOKUP:%.*]] = getelementptr [2 x i1], ptr @lookup_table, i32 0, i32 [[BIT]]
177; CHECK-NEXT:    ret ptr [[LOOKUP]]
178;
179  %tmp = ptrtoint ptr %q to i32
180  %tmp2 = lshr i32 %tmp, %bitno
181  %bit = and i32 %tmp2, 1
182  %lookup = getelementptr [2 x i1], ptr @lookup_table, i32 0, i32 %bit
183  ret ptr %lookup
184}
185
186define i1 @c7(ptr %q, i32 %bitno) {
187; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read)
188; TUNIT-LABEL: define {{[^@]+}}@c7
189; TUNIT-SAME: (ptr nofree readonly [[Q:%.*]], i32 [[BITNO:%.*]]) #[[ATTR2]] {
190; TUNIT-NEXT:    [[PTR:%.*]] = call ptr @lookup_bit(ptr noalias nofree readnone [[Q]], i32 [[BITNO]]) #[[ATTR18:[0-9]+]]
191; TUNIT-NEXT:    [[VAL:%.*]] = load i1, ptr [[PTR]], align 1
192; TUNIT-NEXT:    ret i1 [[VAL]]
193;
194; CGSCC: Function Attrs: mustprogress nofree nosync nounwind willreturn memory(read)
195; CGSCC-LABEL: define {{[^@]+}}@c7
196; CGSCC-SAME: (ptr nofree readonly [[Q:%.*]], i32 [[BITNO:%.*]]) #[[ATTR6:[0-9]+]] {
197; CGSCC-NEXT:    [[PTR:%.*]] = call ptr @lookup_bit(ptr noalias nofree readnone [[Q]], i32 [[BITNO]]) #[[ATTR21:[0-9]+]]
198; CGSCC-NEXT:    [[VAL:%.*]] = load i1, ptr [[PTR]], align 1
199; CGSCC-NEXT:    ret i1 [[VAL]]
200;
201  %ptr = call ptr @lookup_bit(ptr %q, i32 %bitno)
202  %val = load i1, ptr %ptr
203  ret i1 %val
204}
205
206
207define i32 @nc1(ptr %q, ptr %p, i1 %b) {
208; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn
209; TUNIT-LABEL: define {{[^@]+}}@nc1
210; TUNIT-SAME: (ptr nofree [[Q:%.*]], ptr nofree captures(none) [[P:%.*]], i1 [[B:%.*]]) #[[ATTR5:[0-9]+]] {
211; TUNIT-NEXT:  e:
212; TUNIT-NEXT:    br label [[L:%.*]]
213; TUNIT:       l:
214; TUNIT-NEXT:    [[X:%.*]] = phi ptr [ [[P]], [[E:%.*]] ]
215; TUNIT-NEXT:    [[Y:%.*]] = phi ptr [ [[Q]], [[E]] ]
216; TUNIT-NEXT:    [[TMP2:%.*]] = select i1 [[B]], ptr [[P]], ptr [[Q]]
217; TUNIT-NEXT:    [[VAL:%.*]] = load i32, ptr [[TMP2]], align 4
218; TUNIT-NEXT:    store i32 0, ptr [[P]], align 4
219; TUNIT-NEXT:    store ptr [[Q]], ptr @g, align 8
220; TUNIT-NEXT:    ret i32 [[VAL]]
221;
222; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn
223; CGSCC-LABEL: define {{[^@]+}}@nc1
224; CGSCC-SAME: (ptr nofree [[Q:%.*]], ptr nofree captures(none) [[P:%.*]], i1 [[B:%.*]]) #[[ATTR7:[0-9]+]] {
225; CGSCC-NEXT:  e:
226; CGSCC-NEXT:    br label [[L:%.*]]
227; CGSCC:       l:
228; CGSCC-NEXT:    [[X:%.*]] = phi ptr [ [[P]], [[E:%.*]] ]
229; CGSCC-NEXT:    [[Y:%.*]] = phi ptr [ [[Q]], [[E]] ]
230; CGSCC-NEXT:    [[TMP2:%.*]] = select i1 [[B]], ptr [[P]], ptr [[Q]]
231; CGSCC-NEXT:    [[VAL:%.*]] = load i32, ptr [[TMP2]], align 4
232; CGSCC-NEXT:    store i32 0, ptr [[P]], align 4
233; CGSCC-NEXT:    store ptr [[Q]], ptr @g, align 8
234; CGSCC-NEXT:    ret i32 [[VAL]]
235;
236e:
237  br label %l
238l:
239  %x = phi ptr [ %p, %e ]
240  %y = phi ptr [ %q, %e ]
241  %tmp2 = select i1 %b, ptr %x, ptr %y
242  %val = load i32, ptr %tmp2		; <i32> [#uses=1]
243  store i32 0, ptr %x
244  store ptr %y, ptr @g
245  ret i32 %val
246}
247
248define i32 @nc1_addrspace(ptr %q, ptr addrspace(1) %p, i1 %b) {
249; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn
250; TUNIT-LABEL: define {{[^@]+}}@nc1_addrspace
251; TUNIT-SAME: (ptr nofree [[Q:%.*]], ptr addrspace(1) nofree captures(none) [[P:%.*]], i1 [[B:%.*]]) #[[ATTR5]] {
252; TUNIT-NEXT:  e:
253; TUNIT-NEXT:    br label [[L:%.*]]
254; TUNIT:       l:
255; TUNIT-NEXT:    [[X:%.*]] = phi ptr addrspace(1) [ [[P]], [[E:%.*]] ]
256; TUNIT-NEXT:    [[Y:%.*]] = phi ptr [ [[Q]], [[E]] ]
257; TUNIT-NEXT:    [[TMP:%.*]] = addrspacecast ptr addrspace(1) [[P]] to ptr
258; TUNIT-NEXT:    [[TMP2:%.*]] = select i1 [[B]], ptr [[TMP]], ptr [[Q]]
259; TUNIT-NEXT:    [[VAL:%.*]] = load i32, ptr [[TMP2]], align 4
260; TUNIT-NEXT:    store i32 0, ptr [[TMP]], align 4
261; TUNIT-NEXT:    store ptr [[Q]], ptr @g, align 8
262; TUNIT-NEXT:    ret i32 [[VAL]]
263;
264; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn
265; CGSCC-LABEL: define {{[^@]+}}@nc1_addrspace
266; CGSCC-SAME: (ptr nofree [[Q:%.*]], ptr addrspace(1) nofree captures(none) [[P:%.*]], i1 [[B:%.*]]) #[[ATTR7]] {
267; CGSCC-NEXT:  e:
268; CGSCC-NEXT:    br label [[L:%.*]]
269; CGSCC:       l:
270; CGSCC-NEXT:    [[X:%.*]] = phi ptr addrspace(1) [ [[P]], [[E:%.*]] ]
271; CGSCC-NEXT:    [[Y:%.*]] = phi ptr [ [[Q]], [[E]] ]
272; CGSCC-NEXT:    [[TMP:%.*]] = addrspacecast ptr addrspace(1) [[P]] to ptr
273; CGSCC-NEXT:    [[TMP2:%.*]] = select i1 [[B]], ptr [[TMP]], ptr [[Q]]
274; CGSCC-NEXT:    [[VAL:%.*]] = load i32, ptr [[TMP2]], align 4
275; CGSCC-NEXT:    store i32 0, ptr [[TMP]], align 4
276; CGSCC-NEXT:    store ptr [[Q]], ptr @g, align 8
277; CGSCC-NEXT:    ret i32 [[VAL]]
278;
279e:
280  br label %l
281l:
282  %x = phi ptr addrspace(1) [ %p, %e ]
283  %y = phi ptr [ %q, %e ]
284  %tmp = addrspacecast ptr addrspace(1) %x to ptr		; <ptr> [#uses=2]
285  %tmp2 = select i1 %b, ptr %tmp, ptr %y
286  %val = load i32, ptr %tmp2		; <i32> [#uses=1]
287  store i32 0, ptr %tmp
288  store ptr %y, ptr @g
289  ret i32 %val
290}
291
292define void @nc2(ptr %p, ptr %q) {
293; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn
294; TUNIT-LABEL: define {{[^@]+}}@nc2
295; TUNIT-SAME: (ptr nofree captures(none) [[P:%.*]], ptr nofree [[Q:%.*]]) #[[ATTR5]] {
296; TUNIT-NEXT:    [[TMP1:%.*]] = call i32 @nc1(ptr nofree [[Q]], ptr nofree captures(none) [[P]], i1 noundef false) #[[ATTR19:[0-9]+]]
297; TUNIT-NEXT:    ret void
298;
299; CGSCC: Function Attrs: mustprogress nofree nosync nounwind willreturn
300; CGSCC-LABEL: define {{[^@]+}}@nc2
301; CGSCC-SAME: (ptr nofree align 4 captures(none) [[P:%.*]], ptr nofree [[Q:%.*]]) #[[ATTR8:[0-9]+]] {
302; CGSCC-NEXT:    [[TMP1:%.*]] = call i32 @nc1(ptr nofree [[Q]], ptr nofree align 4 captures(none) [[P]], i1 noundef false) #[[ATTR22:[0-9]+]]
303; CGSCC-NEXT:    ret void
304;
305  %1 = call i32 @nc1(ptr %q, ptr %p, i1 0)		; <i32> [#uses=0]
306  ret void
307}
308
309
310define void @nc3(ptr %p) {
311; CHECK-LABEL: define {{[^@]+}}@nc3
312; CHECK-SAME: (ptr nofree noundef nonnull captures(none) [[P:%.*]]) {
313; CHECK-NEXT:    call void [[P]]()
314; CHECK-NEXT:    ret void
315;
316  call void %p()
317  ret void
318}
319
320; The following test is tricky because improvements to AAIsDead can cause the call to be removed.
321; FIXME: readonly and nocapture missing on the pointer.
322declare void @external(ptr readonly) nounwind argmemonly
323define void @nc4(ptr %p) {
324; TUNIT: Function Attrs: nounwind memory(argmem: readwrite)
325; TUNIT-LABEL: define {{[^@]+}}@nc4
326; TUNIT-SAME: (ptr nofree [[P:%.*]]) #[[ATTR6:[0-9]+]] {
327; TUNIT-NEXT:    call void @external(ptr nofree readonly [[P]]) #[[ATTR20:[0-9]+]]
328; TUNIT-NEXT:    ret void
329;
330; CGSCC: Function Attrs: nounwind memory(argmem: readwrite)
331; CGSCC-LABEL: define {{[^@]+}}@nc4
332; CGSCC-SAME: (ptr nofree [[P:%.*]]) #[[ATTR9:[0-9]+]] {
333; CGSCC-NEXT:    call void @external(ptr nofree readonly [[P]]) #[[ATTR23:[0-9]+]]
334; CGSCC-NEXT:    ret void
335;
336  call void @external(ptr %p)
337  ret void
338}
339
340define void @nc5(ptr %f, ptr %p) {
341; CHECK-LABEL: define {{[^@]+}}@nc5
342; CHECK-SAME: (ptr nofree noundef nonnull captures(none) [[F:%.*]], ptr captures(none) [[P:%.*]]) {
343; CHECK-NEXT:    call void [[F]](ptr captures(none) [[P]])
344; CHECK-NEXT:    ret void
345;
346  call void %f(ptr %p) readonly nounwind
347  call void %f(ptr nocapture %p)
348  ret void
349}
350
351; It would be acceptable to add readnone to %y1_1 and %y1_2.
352define void @test1_1(ptr %x1_1, ptr %y1_1, i1 %c) {
353; TUNIT: Function Attrs: nofree nosync nounwind memory(write)
354; TUNIT-LABEL: define {{[^@]+}}@test1_1
355; TUNIT-SAME: (ptr nofree readnone captures(none) [[X1_1:%.*]], ptr nofree readnone captures(none) [[Y1_1:%.*]], i1 [[C:%.*]]) #[[ATTR7:[0-9]+]] {
356; TUNIT-NEXT:    [[TMP1:%.*]] = call ptr @test1_2(ptr noalias nofree readnone captures(none) undef, ptr noalias nofree readnone "no-capture-maybe-returned" [[Y1_1]], i1 noundef [[C]]) #[[ATTR7]]
357; TUNIT-NEXT:    store ptr null, ptr @g, align 8
358; TUNIT-NEXT:    ret void
359;
360; CGSCC: Function Attrs: nofree nosync nounwind memory(write)
361; CGSCC-LABEL: define {{[^@]+}}@test1_1
362; CGSCC-SAME: (ptr nofree readnone captures(none) [[X1_1:%.*]], ptr nofree readnone captures(none) [[Y1_1:%.*]], i1 [[C:%.*]]) #[[ATTR10:[0-9]+]] {
363; CGSCC-NEXT:    [[TMP1:%.*]] = call ptr @test1_2(ptr noalias nofree readnone captures(none) undef, ptr noalias nofree readnone "no-capture-maybe-returned" [[Y1_1]], i1 noundef [[C]]) #[[ATTR10]]
364; CGSCC-NEXT:    store ptr null, ptr @g, align 8
365; CGSCC-NEXT:    ret void
366;
367  call ptr @test1_2(ptr %x1_1, ptr %y1_1, i1 %c)
368  store ptr null, ptr @g
369  ret void
370}
371
372define ptr @test1_2(ptr %x1_2, ptr %y1_2, i1 %c) {
373; TUNIT: Function Attrs: nofree nosync nounwind memory(write)
374; TUNIT-LABEL: define {{[^@]+}}@test1_2
375; TUNIT-SAME: (ptr nofree readnone captures(none) [[X1_2:%.*]], ptr nofree readnone returned "no-capture-maybe-returned" [[Y1_2:%.*]], i1 noundef [[C:%.*]]) #[[ATTR7]] {
376; TUNIT-NEXT:    br i1 [[C]], label [[T:%.*]], label [[F:%.*]]
377; TUNIT:       t:
378; TUNIT-NEXT:    call void @test1_1(ptr noalias nofree readnone captures(none) undef, ptr noalias nofree readnone captures(none) [[Y1_2]], i1 noundef [[C]]) #[[ATTR7]]
379; TUNIT-NEXT:    store ptr null, ptr @g, align 8
380; TUNIT-NEXT:    br label [[F]]
381; TUNIT:       f:
382; TUNIT-NEXT:    ret ptr [[Y1_2]]
383;
384; CGSCC: Function Attrs: nofree nosync nounwind memory(write)
385; CGSCC-LABEL: define {{[^@]+}}@test1_2
386; CGSCC-SAME: (ptr nofree readnone captures(none) [[X1_2:%.*]], ptr nofree readnone returned "no-capture-maybe-returned" [[Y1_2:%.*]], i1 noundef [[C:%.*]]) #[[ATTR10]] {
387; CGSCC-NEXT:    br i1 [[C]], label [[T:%.*]], label [[F:%.*]]
388; CGSCC:       t:
389; CGSCC-NEXT:    call void @test1_1(ptr noalias nofree readnone captures(none) undef, ptr noalias nofree readnone captures(none) [[Y1_2]], i1 noundef [[C]]) #[[ATTR10]]
390; CGSCC-NEXT:    store ptr null, ptr @g, align 8
391; CGSCC-NEXT:    br label [[F]]
392; CGSCC:       f:
393; CGSCC-NEXT:    ret ptr [[Y1_2]]
394;
395  br i1 %c, label %t, label %f
396t:
397  call void @test1_1(ptr %x1_2, ptr %y1_2, i1 %c)
398  store ptr null, ptr @g
399  br label %f
400f:
401  ret ptr %y1_2
402}
403
404define void @test2(ptr %x2) {
405; TUNIT: Function Attrs: nofree nosync nounwind memory(write)
406; TUNIT-LABEL: define {{[^@]+}}@test2
407; TUNIT-SAME: (ptr nofree readnone captures(none) [[X2:%.*]]) #[[ATTR7]] {
408; TUNIT-NEXT:    call void @test2(ptr noalias nofree readnone captures(none) undef) #[[ATTR7]]
409; TUNIT-NEXT:    store ptr null, ptr @g, align 8
410; TUNIT-NEXT:    ret void
411;
412; CGSCC: Function Attrs: nofree nosync nounwind memory(write)
413; CGSCC-LABEL: define {{[^@]+}}@test2
414; CGSCC-SAME: (ptr nofree readnone captures(none) [[X2:%.*]]) #[[ATTR10]] {
415; CGSCC-NEXT:    call void @test2(ptr noalias nofree readnone captures(none) undef) #[[ATTR10]]
416; CGSCC-NEXT:    store ptr null, ptr @g, align 8
417; CGSCC-NEXT:    ret void
418;
419  call void @test2(ptr %x2)
420  store ptr null, ptr @g
421  ret void
422}
423
424define void @test3(ptr %x3, ptr %y3, ptr %z3) {
425; TUNIT: Function Attrs: nofree nosync nounwind memory(write)
426; TUNIT-LABEL: define {{[^@]+}}@test3
427; TUNIT-SAME: (ptr nofree readnone captures(none) [[X3:%.*]], ptr nofree readnone captures(none) [[Y3:%.*]], ptr nofree readnone captures(none) [[Z3:%.*]]) #[[ATTR7]] {
428; TUNIT-NEXT:    call void @test3(ptr noalias nofree readnone captures(none) undef, ptr noalias nofree readnone captures(none) undef, ptr noalias nofree readnone captures(none) undef) #[[ATTR7]]
429; TUNIT-NEXT:    store ptr null, ptr @g, align 8
430; TUNIT-NEXT:    ret void
431;
432; CGSCC: Function Attrs: nofree nosync nounwind memory(write)
433; CGSCC-LABEL: define {{[^@]+}}@test3
434; CGSCC-SAME: (ptr nofree readnone captures(none) [[X3:%.*]], ptr nofree readnone captures(none) [[Y3:%.*]], ptr nofree readnone captures(none) [[Z3:%.*]]) #[[ATTR10]] {
435; CGSCC-NEXT:    call void @test3(ptr noalias nofree readnone captures(none) undef, ptr noalias nofree readnone captures(none) undef, ptr noalias nofree readnone captures(none) undef) #[[ATTR10]]
436; CGSCC-NEXT:    store ptr null, ptr @g, align 8
437; CGSCC-NEXT:    ret void
438;
439  call void @test3(ptr %z3, ptr %y3, ptr %x3)
440  store ptr null, ptr @g
441  ret void
442}
443
444define void @test4_1(ptr %x4_1, i1 %c) {
445; TUNIT: Function Attrs: nofree nosync nounwind memory(write)
446; TUNIT-LABEL: define {{[^@]+}}@test4_1
447; TUNIT-SAME: (ptr nofree readnone captures(none) [[X4_1:%.*]], i1 [[C:%.*]]) #[[ATTR7]] {
448; TUNIT-NEXT:    [[TMP1:%.*]] = call ptr @test4_2(ptr noalias nofree readnone captures(none) undef, ptr noalias nofree readnone "no-capture-maybe-returned" [[X4_1]], ptr noalias nofree readnone captures(none) undef, i1 noundef [[C]]) #[[ATTR7]]
449; TUNIT-NEXT:    store ptr null, ptr @g, align 8
450; TUNIT-NEXT:    ret void
451;
452; CGSCC: Function Attrs: nofree nosync nounwind memory(write)
453; CGSCC-LABEL: define {{[^@]+}}@test4_1
454; CGSCC-SAME: (ptr nofree readnone captures(none) [[X4_1:%.*]], i1 [[C:%.*]]) #[[ATTR10]] {
455; CGSCC-NEXT:    [[TMP1:%.*]] = call ptr @test4_2(ptr noalias nofree readnone captures(none) undef, ptr noalias nofree readnone "no-capture-maybe-returned" [[X4_1]], ptr noalias nofree readnone captures(none) undef, i1 noundef [[C]]) #[[ATTR10]]
456; CGSCC-NEXT:    store ptr null, ptr @g, align 8
457; CGSCC-NEXT:    ret void
458;
459  call ptr @test4_2(ptr %x4_1, ptr %x4_1, ptr %x4_1, i1 %c)
460  store ptr null, ptr @g
461  ret void
462}
463
464define ptr @test4_2(ptr %x4_2, ptr %y4_2, ptr %z4_2, i1 %c) {
465; TUNIT: Function Attrs: nofree nosync nounwind memory(write)
466; TUNIT-LABEL: define {{[^@]+}}@test4_2
467; TUNIT-SAME: (ptr nofree readnone captures(none) [[X4_2:%.*]], ptr nofree readnone returned "no-capture-maybe-returned" [[Y4_2:%.*]], ptr nofree readnone captures(none) [[Z4_2:%.*]], i1 noundef [[C:%.*]]) #[[ATTR7]] {
468; TUNIT-NEXT:    br i1 [[C]], label [[T:%.*]], label [[F:%.*]]
469; TUNIT:       t:
470; TUNIT-NEXT:    call void @test4_1(ptr nofree noundef readnone align 4294967296 null, i1 noundef [[C]]) #[[ATTR7]]
471; TUNIT-NEXT:    store ptr null, ptr @g, align 8
472; TUNIT-NEXT:    br label [[F]]
473; TUNIT:       f:
474; TUNIT-NEXT:    ret ptr [[Y4_2]]
475;
476; CGSCC: Function Attrs: nofree nosync nounwind memory(write)
477; CGSCC-LABEL: define {{[^@]+}}@test4_2
478; CGSCC-SAME: (ptr nofree readnone captures(none) [[X4_2:%.*]], ptr nofree readnone returned "no-capture-maybe-returned" [[Y4_2:%.*]], ptr nofree readnone captures(none) [[Z4_2:%.*]], i1 noundef [[C:%.*]]) #[[ATTR10]] {
479; CGSCC-NEXT:    br i1 [[C]], label [[T:%.*]], label [[F:%.*]]
480; CGSCC:       t:
481; CGSCC-NEXT:    call void @test4_1(ptr nofree noundef readnone align 4294967296 null, i1 noundef [[C]]) #[[ATTR10]]
482; CGSCC-NEXT:    store ptr null, ptr @g, align 8
483; CGSCC-NEXT:    br label [[F]]
484; CGSCC:       f:
485; CGSCC-NEXT:    ret ptr [[Y4_2]]
486;
487  br i1 %c, label %t, label %f
488t:
489  call void @test4_1(ptr null, i1 %c)
490  store ptr null, ptr @g
491  br label %f
492f:
493  ret ptr %y4_2
494}
495
496declare ptr @test5_1(ptr %x5_1)
497
498define void @test5_2(ptr %x5_2) {
499; CHECK-LABEL: define {{[^@]+}}@test5_2
500; CHECK-SAME: (ptr [[X5_2:%.*]]) {
501; CHECK-NEXT:    [[TMP1:%.*]] = call ptr @test5_1(ptr [[X5_2]])
502; CHECK-NEXT:    store ptr null, ptr @g, align 8
503; CHECK-NEXT:    ret void
504;
505  call ptr @test5_1(ptr %x5_2)
506  store ptr null, ptr @g
507  ret void
508}
509
510declare void @test6_1(ptr %x6_1, ptr nocapture %y6_1, ...)
511
512define void @test6_2(ptr %x6_2, ptr %y6_2, ptr %z6_2) {
513; CHECK-LABEL: define {{[^@]+}}@test6_2
514; CHECK-SAME: (ptr [[X6_2:%.*]], ptr captures(none) [[Y6_2:%.*]], ptr [[Z6_2:%.*]]) {
515; CHECK-NEXT:    call void (ptr, ptr, ...) @test6_1(ptr [[X6_2]], ptr captures(none) [[Y6_2]], ptr [[Z6_2]])
516; CHECK-NEXT:    store ptr null, ptr @g, align 8
517; CHECK-NEXT:    ret void
518;
519  call void (ptr, ptr, ...) @test6_1(ptr %x6_2, ptr %y6_2, ptr %z6_2)
520  store ptr null, ptr @g
521  ret void
522}
523
524define void @test_cmpxchg(ptr %p) {
525; TUNIT: Function Attrs: mustprogress nofree norecurse nounwind willreturn memory(argmem: readwrite)
526; TUNIT-LABEL: define {{[^@]+}}@test_cmpxchg
527; TUNIT-SAME: (ptr nofree noundef nonnull align 4 captures(none) dereferenceable(4) [[P:%.*]]) #[[ATTR8:[0-9]+]] {
528; TUNIT-NEXT:    [[TMP1:%.*]] = cmpxchg ptr [[P]], i32 0, i32 1 acquire monotonic, align 4
529; TUNIT-NEXT:    ret void
530;
531; CGSCC: Function Attrs: mustprogress nofree norecurse nounwind willreturn memory(argmem: readwrite)
532; CGSCC-LABEL: define {{[^@]+}}@test_cmpxchg
533; CGSCC-SAME: (ptr nofree noundef nonnull align 4 captures(none) dereferenceable(4) [[P:%.*]]) #[[ATTR11:[0-9]+]] {
534; CGSCC-NEXT:    [[TMP1:%.*]] = cmpxchg ptr [[P]], i32 0, i32 1 acquire monotonic, align 4
535; CGSCC-NEXT:    ret void
536;
537  cmpxchg ptr %p, i32 0, i32 1 acquire monotonic
538  ret void
539}
540
541define void @test_cmpxchg_ptr(ptr %p, ptr %q) {
542; TUNIT: Function Attrs: mustprogress nofree norecurse nounwind willreturn memory(argmem: readwrite)
543; TUNIT-LABEL: define {{[^@]+}}@test_cmpxchg_ptr
544; TUNIT-SAME: (ptr nofree noundef nonnull align 8 captures(none) dereferenceable(8) [[P:%.*]], ptr nofree [[Q:%.*]]) #[[ATTR8]] {
545; TUNIT-NEXT:    [[TMP1:%.*]] = cmpxchg ptr [[P]], ptr null, ptr [[Q]] acquire monotonic, align 8
546; TUNIT-NEXT:    ret void
547;
548; CGSCC: Function Attrs: mustprogress nofree norecurse nounwind willreturn memory(argmem: readwrite)
549; CGSCC-LABEL: define {{[^@]+}}@test_cmpxchg_ptr
550; CGSCC-SAME: (ptr nofree noundef nonnull align 8 captures(none) dereferenceable(8) [[P:%.*]], ptr nofree [[Q:%.*]]) #[[ATTR11]] {
551; CGSCC-NEXT:    [[TMP1:%.*]] = cmpxchg ptr [[P]], ptr null, ptr [[Q]] acquire monotonic, align 8
552; CGSCC-NEXT:    ret void
553;
554  cmpxchg ptr %p, ptr null, ptr %q acquire monotonic
555  ret void
556}
557
558define void @test_atomicrmw(ptr %p) {
559; TUNIT: Function Attrs: mustprogress nofree norecurse nounwind willreturn memory(argmem: readwrite)
560; TUNIT-LABEL: define {{[^@]+}}@test_atomicrmw
561; TUNIT-SAME: (ptr nofree noundef nonnull align 4 captures(none) dereferenceable(4) [[P:%.*]]) #[[ATTR8]] {
562; TUNIT-NEXT:    [[TMP1:%.*]] = atomicrmw add ptr [[P]], i32 1 seq_cst, align 4
563; TUNIT-NEXT:    ret void
564;
565; CGSCC: Function Attrs: mustprogress nofree norecurse nounwind willreturn memory(argmem: readwrite)
566; CGSCC-LABEL: define {{[^@]+}}@test_atomicrmw
567; CGSCC-SAME: (ptr nofree noundef nonnull align 4 captures(none) dereferenceable(4) [[P:%.*]]) #[[ATTR11]] {
568; CGSCC-NEXT:    [[TMP1:%.*]] = atomicrmw add ptr [[P]], i32 1 seq_cst, align 4
569; CGSCC-NEXT:    ret void
570;
571  atomicrmw add ptr %p, i32 1 seq_cst
572  ret void
573}
574
575define void @test_volatile(ptr %x) {
576; TUNIT: Function Attrs: mustprogress nofree norecurse nounwind willreturn memory(argmem: readwrite)
577; TUNIT-LABEL: define {{[^@]+}}@test_volatile
578; TUNIT-SAME: (ptr nofree align 4 [[X:%.*]]) #[[ATTR8]] {
579; TUNIT-NEXT:  entry:
580; TUNIT-NEXT:    [[GEP:%.*]] = getelementptr i32, ptr [[X]], i64 1
581; TUNIT-NEXT:    store volatile i32 0, ptr [[GEP]], align 4
582; TUNIT-NEXT:    ret void
583;
584; CGSCC: Function Attrs: mustprogress nofree norecurse nounwind willreturn memory(argmem: readwrite)
585; CGSCC-LABEL: define {{[^@]+}}@test_volatile
586; CGSCC-SAME: (ptr nofree align 4 [[X:%.*]]) #[[ATTR11]] {
587; CGSCC-NEXT:  entry:
588; CGSCC-NEXT:    [[GEP:%.*]] = getelementptr i32, ptr [[X]], i64 1
589; CGSCC-NEXT:    store volatile i32 0, ptr [[GEP]], align 4
590; CGSCC-NEXT:    ret void
591;
592entry:
593  %gep = getelementptr i32, ptr %x, i64 1
594  store volatile i32 0, ptr %gep, align 4
595  ret void
596}
597
598define void @nocaptureLaunder(ptr %p) {
599; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite)
600; TUNIT-LABEL: define {{[^@]+}}@nocaptureLaunder
601; TUNIT-SAME: (ptr nofree captures(none) [[P:%.*]]) #[[ATTR9:[0-9]+]] {
602; TUNIT-NEXT:  entry:
603; TUNIT-NEXT:    [[B:%.*]] = call ptr @llvm.launder.invariant.group.p0(ptr nofree [[P]]) #[[ATTR21:[0-9]+]]
604; TUNIT-NEXT:    store i8 42, ptr [[B]], align 1
605; TUNIT-NEXT:    ret void
606;
607; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite)
608; CGSCC-LABEL: define {{[^@]+}}@nocaptureLaunder
609; CGSCC-SAME: (ptr nofree captures(none) [[P:%.*]]) #[[ATTR12:[0-9]+]] {
610; CGSCC-NEXT:  entry:
611; CGSCC-NEXT:    [[B:%.*]] = call ptr @llvm.launder.invariant.group.p0(ptr nofree [[P]]) #[[ATTR24:[0-9]+]]
612; CGSCC-NEXT:    store i8 42, ptr [[B]], align 1
613; CGSCC-NEXT:    ret void
614;
615entry:
616  %b = call ptr @llvm.launder.invariant.group.p0(ptr %p)
617  store i8 42, ptr %b
618  ret void
619}
620
621@g2 = global ptr null
622define void @captureLaunder(ptr %p) {
623; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn
624; TUNIT-LABEL: define {{[^@]+}}@captureLaunder
625; TUNIT-SAME: (ptr nofree [[P:%.*]]) #[[ATTR5]] {
626; TUNIT-NEXT:    [[B:%.*]] = call ptr @llvm.launder.invariant.group.p0(ptr nofree [[P]]) #[[ATTR21]]
627; TUNIT-NEXT:    store ptr [[B]], ptr @g2, align 8
628; TUNIT-NEXT:    ret void
629;
630; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn
631; CGSCC-LABEL: define {{[^@]+}}@captureLaunder
632; CGSCC-SAME: (ptr nofree [[P:%.*]]) #[[ATTR7]] {
633; CGSCC-NEXT:    [[B:%.*]] = call ptr @llvm.launder.invariant.group.p0(ptr nofree [[P]]) #[[ATTR24]]
634; CGSCC-NEXT:    store ptr [[B]], ptr @g2, align 8
635; CGSCC-NEXT:    ret void
636;
637  %b = call ptr @llvm.launder.invariant.group.p0(ptr %p)
638  store ptr %b, ptr @g2
639  ret void
640}
641
642define void @nocaptureStrip(ptr %p) {
643; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write)
644; TUNIT-LABEL: define {{[^@]+}}@nocaptureStrip
645; TUNIT-SAME: (ptr nofree writeonly captures(none) [[P:%.*]]) #[[ATTR10:[0-9]+]] {
646; TUNIT-NEXT:  entry:
647; TUNIT-NEXT:    [[B:%.*]] = call ptr @llvm.strip.invariant.group.p0(ptr noalias nofree readnone [[P]]) #[[ATTR22:[0-9]+]]
648; TUNIT-NEXT:    store i8 42, ptr [[B]], align 1
649; TUNIT-NEXT:    ret void
650;
651; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write)
652; CGSCC-LABEL: define {{[^@]+}}@nocaptureStrip
653; CGSCC-SAME: (ptr nofree writeonly captures(none) [[P:%.*]]) #[[ATTR13:[0-9]+]] {
654; CGSCC-NEXT:  entry:
655; CGSCC-NEXT:    [[B:%.*]] = call ptr @llvm.strip.invariant.group.p0(ptr noalias nofree readnone [[P]]) #[[ATTR21]]
656; CGSCC-NEXT:    store i8 42, ptr [[B]], align 1
657; CGSCC-NEXT:    ret void
658;
659entry:
660  %b = call ptr @llvm.strip.invariant.group.p0(ptr %p)
661  store i8 42, ptr %b
662  ret void
663}
664
665@g3 = global ptr null
666define void @captureStrip(ptr %p) {
667; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write)
668; TUNIT-LABEL: define {{[^@]+}}@captureStrip
669; TUNIT-SAME: (ptr nofree writeonly [[P:%.*]]) #[[ATTR1]] {
670; TUNIT-NEXT:    [[B:%.*]] = call ptr @llvm.strip.invariant.group.p0(ptr noalias nofree readnone [[P]]) #[[ATTR22]]
671; TUNIT-NEXT:    store ptr [[B]], ptr @g3, align 8
672; TUNIT-NEXT:    ret void
673;
674; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write)
675; CGSCC-LABEL: define {{[^@]+}}@captureStrip
676; CGSCC-SAME: (ptr nofree writeonly [[P:%.*]]) #[[ATTR1]] {
677; CGSCC-NEXT:    [[B:%.*]] = call ptr @llvm.strip.invariant.group.p0(ptr noalias nofree readnone [[P]]) #[[ATTR21]]
678; CGSCC-NEXT:    store ptr [[B]], ptr @g3, align 8
679; CGSCC-NEXT:    ret void
680;
681  %b = call ptr @llvm.strip.invariant.group.p0(ptr %p)
682  store ptr %b, ptr @g3
683  ret void
684}
685
686define i1 @captureICmp(ptr %x) {
687; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
688; CHECK-LABEL: define {{[^@]+}}@captureICmp
689; CHECK-SAME: (ptr nofree readnone [[X:%.*]]) #[[ATTR0]] {
690; CHECK-NEXT:    [[TMP1:%.*]] = icmp eq ptr [[X]], null
691; CHECK-NEXT:    ret i1 [[TMP1]]
692;
693  %1 = icmp eq ptr %x, null
694  ret i1 %1
695}
696
697define i1 @captureICmpRev(ptr %x) {
698; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
699; CHECK-LABEL: define {{[^@]+}}@captureICmpRev
700; CHECK-SAME: (ptr nofree readnone [[X:%.*]]) #[[ATTR0]] {
701; CHECK-NEXT:    [[TMP1:%.*]] = icmp eq ptr null, [[X]]
702; CHECK-NEXT:    ret i1 [[TMP1]]
703;
704  %1 = icmp eq ptr null, %x
705  ret i1 %1
706}
707
708define i1 @nocaptureInboundsGEPICmp(ptr %x) {
709; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
710; CHECK-LABEL: define {{[^@]+}}@nocaptureInboundsGEPICmp
711; CHECK-SAME: (ptr nofree readnone captures(none) [[X:%.*]]) #[[ATTR0]] {
712; CHECK-NEXT:    ret i1 false
713;
714  %1 = getelementptr inbounds i32, ptr %x, i32 5
715  %2 = icmp eq ptr %1, null
716  ret i1 %2
717}
718
719define i1 @nocaptureInboundsGEPICmpRev(ptr %x) {
720; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
721; CHECK-LABEL: define {{[^@]+}}@nocaptureInboundsGEPICmpRev
722; CHECK-SAME: (ptr nofree readnone captures(none) [[X:%.*]]) #[[ATTR0]] {
723; CHECK-NEXT:    ret i1 true
724;
725  %1 = getelementptr inbounds i32, ptr %x, i32 5
726  %2 = icmp ne ptr null, %1
727  ret i1 %2
728}
729
730define i1 @nocaptureDereferenceableOrNullICmp(ptr dereferenceable_or_null(4) %x) {
731; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
732; CHECK-LABEL: define {{[^@]+}}@nocaptureDereferenceableOrNullICmp
733; CHECK-SAME: (ptr nofree noundef readnone captures(none) dereferenceable_or_null(4) [[X:%.*]]) #[[ATTR0]] {
734; CHECK-NEXT:    [[TMP1:%.*]] = icmp eq ptr [[X]], null
735; CHECK-NEXT:    ret i1 [[TMP1]]
736;
737  %1 = icmp eq ptr %x, null
738  ret i1 %1
739}
740
741define i1 @captureDereferenceableOrNullICmp(ptr dereferenceable_or_null(4) %x) null_pointer_is_valid {
742; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind null_pointer_is_valid willreturn memory(none)
743; TUNIT-LABEL: define {{[^@]+}}@captureDereferenceableOrNullICmp
744; TUNIT-SAME: (ptr nofree noundef readnone dereferenceable_or_null(4) [[X:%.*]]) #[[ATTR11:[0-9]+]] {
745; TUNIT-NEXT:    [[TMP1:%.*]] = icmp eq ptr [[X]], null
746; TUNIT-NEXT:    ret i1 [[TMP1]]
747;
748; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind null_pointer_is_valid willreturn memory(none)
749; CGSCC-LABEL: define {{[^@]+}}@captureDereferenceableOrNullICmp
750; CGSCC-SAME: (ptr nofree noundef readnone dereferenceable_or_null(4) [[X:%.*]]) #[[ATTR14:[0-9]+]] {
751; CGSCC-NEXT:    [[TMP1:%.*]] = icmp eq ptr [[X]], null
752; CGSCC-NEXT:    ret i1 [[TMP1]]
753;
754  %1 = icmp eq ptr %x, null
755  ret i1 %1
756}
757
758declare void @unknown(ptr)
759; We know that 'null' in AS 0 does not alias anything and cannot be captured. Though the latter is not qurried -> derived atm.
760define void @test_callsite() {
761; CHECK-LABEL: define {{[^@]+}}@test_callsite() {
762; CHECK-NEXT:  entry:
763; CHECK-NEXT:    call void @unknown(ptr noundef align 4294967296 null)
764; CHECK-NEXT:    ret void
765;
766entry:
767  call void @unknown(ptr null)
768  ret void
769}
770
771declare ptr @unknownpi8pi8(ptr,ptr returned)
772define ptr @test_returned1(ptr %A, ptr returned %B) nounwind readonly {
773; TUNIT: Function Attrs: nosync nounwind memory(read)
774; TUNIT-LABEL: define {{[^@]+}}@test_returned1
775; TUNIT-SAME: (ptr captures(none) [[A:%.*]], ptr returned [[B:%.*]]) #[[ATTR12:[0-9]+]] {
776; TUNIT-NEXT:  entry:
777; TUNIT-NEXT:    [[P:%.*]] = call ptr @unknownpi8pi8(ptr [[A]], ptr [[B]])
778; TUNIT-NEXT:    ret ptr [[P]]
779;
780; CGSCC: Function Attrs: nosync nounwind memory(read)
781; CGSCC-LABEL: define {{[^@]+}}@test_returned1
782; CGSCC-SAME: (ptr captures(none) [[A:%.*]], ptr returned [[B:%.*]]) #[[ATTR15:[0-9]+]] {
783; CGSCC-NEXT:  entry:
784; CGSCC-NEXT:    [[P:%.*]] = call ptr @unknownpi8pi8(ptr [[A]], ptr [[B]])
785; CGSCC-NEXT:    ret ptr [[P]]
786;
787entry:
788  %p = call ptr @unknownpi8pi8(ptr %A, ptr %B)
789  ret ptr %p
790}
791
792define ptr @test_returned2(ptr %A, ptr %B) {
793; TUNIT: Function Attrs: nosync nounwind memory(read)
794; TUNIT-LABEL: define {{[^@]+}}@test_returned2
795; TUNIT-SAME: (ptr readonly [[A:%.*]], ptr readonly [[B:%.*]]) #[[ATTR12]] {
796; TUNIT-NEXT:  entry:
797; TUNIT-NEXT:    [[P:%.*]] = call ptr @unknownpi8pi8(ptr readonly [[A]], ptr readonly [[B]]) #[[ATTR12]]
798; TUNIT-NEXT:    ret ptr [[P]]
799;
800; CGSCC: Function Attrs: nosync nounwind memory(read)
801; CGSCC-LABEL: define {{[^@]+}}@test_returned2
802; CGSCC-SAME: (ptr readonly [[A:%.*]], ptr readonly [[B:%.*]]) #[[ATTR15]] {
803; CGSCC-NEXT:  entry:
804; CGSCC-NEXT:    [[P:%.*]] = call ptr @unknownpi8pi8(ptr readonly [[A]], ptr readonly [[B]]) #[[ATTR15]]
805; CGSCC-NEXT:    ret ptr [[P]]
806;
807entry:
808  %p = call ptr @unknownpi8pi8(ptr %A, ptr %B) nounwind readonly
809  ret ptr %p
810}
811
812declare ptr @maybe_returned_ptr(ptr readonly %ptr) readonly nounwind willreturn
813declare i8 @maybe_returned_val(ptr %ptr) readonly nounwind willreturn
814declare void @val_use(i8 %ptr) readonly nounwind willreturn
815
816; FIXME: Both pointers should be nocapture
817define void @ptr_uses(ptr %ptr, ptr %wptr) {
818; TUNIT: Function Attrs: mustprogress nosync nounwind willreturn
819; TUNIT-LABEL: define {{[^@]+}}@ptr_uses
820; TUNIT-SAME: (ptr nofree [[PTR:%.*]], ptr nofree noundef nonnull writeonly captures(none) dereferenceable(1) [[WPTR:%.*]]) #[[ATTR14:[0-9]+]] {
821; TUNIT-NEXT:    store i8 0, ptr [[WPTR]], align 1
822; TUNIT-NEXT:    ret void
823;
824; CGSCC: Function Attrs: mustprogress nosync nounwind willreturn
825; CGSCC-LABEL: define {{[^@]+}}@ptr_uses
826; CGSCC-SAME: (ptr nofree [[PTR:%.*]], ptr nofree noundef nonnull writeonly captures(none) dereferenceable(1) [[WPTR:%.*]]) #[[ATTR17:[0-9]+]] {
827; CGSCC-NEXT:    store i8 0, ptr [[WPTR]], align 1
828; CGSCC-NEXT:    ret void
829;
830  %call_ptr = call ptr @maybe_returned_ptr(ptr %ptr)
831  %call_val = call i8 @maybe_returned_val(ptr %call_ptr)
832  call void @val_use(i8 %call_val)
833  store i8 0, ptr %wptr
834  ret void
835}
836
837declare ptr @llvm.launder.invariant.group.p0(ptr)
838declare ptr @llvm.strip.invariant.group.p0(ptr)
839;.
840; TUNIT: attributes #[[ATTR0]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) }
841; TUNIT: attributes #[[ATTR1]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(write) }
842; TUNIT: attributes #[[ATTR2]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(read) }
843; TUNIT: attributes #[[ATTR3:[0-9]+]] = { memory(read) }
844; TUNIT: attributes #[[ATTR4]] = { nosync memory(read) }
845; TUNIT: attributes #[[ATTR5]] = { mustprogress nofree norecurse nosync nounwind willreturn }
846; TUNIT: attributes #[[ATTR6]] = { nounwind memory(argmem: readwrite) }
847; TUNIT: attributes #[[ATTR7]] = { nofree nosync nounwind memory(write) }
848; TUNIT: attributes #[[ATTR8]] = { mustprogress nofree norecurse nounwind willreturn memory(argmem: readwrite) }
849; TUNIT: attributes #[[ATTR9]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite) }
850; TUNIT: attributes #[[ATTR10]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) }
851; TUNIT: attributes #[[ATTR11]] = { mustprogress nofree norecurse nosync nounwind null_pointer_is_valid willreturn memory(none) }
852; TUNIT: attributes #[[ATTR12]] = { nosync nounwind memory(read) }
853; TUNIT: attributes #[[ATTR13:[0-9]+]] = { nounwind willreturn memory(read) }
854; TUNIT: attributes #[[ATTR14]] = { mustprogress nosync nounwind willreturn }
855; TUNIT: attributes #[[ATTR15:[0-9]+]] = { nocallback nofree nosync nounwind speculatable willreturn memory(inaccessiblemem: readwrite) }
856; TUNIT: attributes #[[ATTR16:[0-9]+]] = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
857; TUNIT: attributes #[[ATTR17]] = { nofree nosync nounwind willreturn memory(write) }
858; TUNIT: attributes #[[ATTR18]] = { nofree nosync nounwind willreturn memory(none) }
859; TUNIT: attributes #[[ATTR19]] = { nofree nosync nounwind willreturn }
860; TUNIT: attributes #[[ATTR20]] = { nounwind }
861; TUNIT: attributes #[[ATTR21]] = { nofree willreturn }
862; TUNIT: attributes #[[ATTR22]] = { nofree nosync willreturn }
863;.
864; CGSCC: attributes #[[ATTR0]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) }
865; CGSCC: attributes #[[ATTR1]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(write) }
866; CGSCC: attributes #[[ATTR2]] = { mustprogress nofree nosync nounwind willreturn memory(write) }
867; CGSCC: attributes #[[ATTR3]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(read) }
868; CGSCC: attributes #[[ATTR4:[0-9]+]] = { memory(read) }
869; CGSCC: attributes #[[ATTR5]] = { nosync memory(read) }
870; CGSCC: attributes #[[ATTR6]] = { mustprogress nofree nosync nounwind willreturn memory(read) }
871; CGSCC: attributes #[[ATTR7]] = { mustprogress nofree norecurse nosync nounwind willreturn }
872; CGSCC: attributes #[[ATTR8]] = { mustprogress nofree nosync nounwind willreturn }
873; CGSCC: attributes #[[ATTR9]] = { nounwind memory(argmem: readwrite) }
874; CGSCC: attributes #[[ATTR10]] = { nofree nosync nounwind memory(write) }
875; CGSCC: attributes #[[ATTR11]] = { mustprogress nofree norecurse nounwind willreturn memory(argmem: readwrite) }
876; CGSCC: attributes #[[ATTR12]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite) }
877; CGSCC: attributes #[[ATTR13]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) }
878; CGSCC: attributes #[[ATTR14]] = { mustprogress nofree norecurse nosync nounwind null_pointer_is_valid willreturn memory(none) }
879; CGSCC: attributes #[[ATTR15]] = { nosync nounwind memory(read) }
880; CGSCC: attributes #[[ATTR16:[0-9]+]] = { nounwind willreturn memory(read) }
881; CGSCC: attributes #[[ATTR17]] = { mustprogress nosync nounwind willreturn }
882; CGSCC: attributes #[[ATTR18:[0-9]+]] = { nocallback nofree nosync nounwind speculatable willreturn memory(inaccessiblemem: readwrite) }
883; CGSCC: attributes #[[ATTR19:[0-9]+]] = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
884; CGSCC: attributes #[[ATTR20]] = { nofree nounwind willreturn memory(write) }
885; CGSCC: attributes #[[ATTR21]] = { nofree nosync willreturn }
886; CGSCC: attributes #[[ATTR22]] = { nofree nounwind willreturn }
887; CGSCC: attributes #[[ATTR23]] = { nounwind }
888; CGSCC: attributes #[[ATTR24]] = { nofree willreturn }
889;.
890