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
6 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
8 declare nonnull ptr @ret_nonnull()
9 declare void @llvm.assume(i1)
11 ; Return a pointer trivially nonnull (call return attribute)
13 ; CHECK-LABEL: define {{[^@]+}}@test1() {
14 ; CHECK-NEXT: [[RET:%.*]] = call nonnull ptr @ret_nonnull()
15 ; CHECK-NEXT: ret ptr [[RET]]
17 %ret = call ptr @ret_nonnull()
21 ; Return a pointer trivially nonnull (argument attribute)
22 define ptr @test2(ptr nonnull %p) {
23 ; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
24 ; CHECK-LABEL: define {{[^@]+}}@test2
25 ; CHECK-SAME: (ptr nofree nonnull readnone returned "no-capture-maybe-returned" [[P:%.*]]) #[[ATTR1:[0-9]+]] {
26 ; CHECK-NEXT: ret ptr [[P]]
31 define ptr @test2A(i1 %c, ptr %ret) {
32 ; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(inaccessiblemem: write)
33 ; CHECK-LABEL: define {{[^@]+}}@test2A
34 ; CHECK-SAME: (i1 noundef [[C:%.*]], ptr nofree nonnull readnone returned "no-capture-maybe-returned" [[RET:%.*]]) #[[ATTR2:[0-9]+]] {
35 ; CHECK-NEXT: br i1 [[C]], label [[A:%.*]], label [[B:%.*]]
37 ; CHECK-NEXT: call void @llvm.assume(i1 noundef true) #[[ATTR15:[0-9]+]] [ "nonnull"(ptr [[RET]]) ]
38 ; CHECK-NEXT: ret ptr [[RET]]
40 ; CHECK-NEXT: call void @llvm.assume(i1 noundef true) #[[ATTR15]] [ "nonnull"(ptr [[RET]]) ]
41 ; CHECK-NEXT: ret ptr [[RET]]
43 br i1 %c, label %A, label %B
45 call void @llvm.assume(i1 true) [ "nonnull"(ptr %ret) ]
48 call void @llvm.assume(i1 true) [ "nonnull"(ptr %ret) ]
52 define ptr @test2B(i1 %c, ptr %ret) {
53 ; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(inaccessiblemem: write)
54 ; CHECK-LABEL: define {{[^@]+}}@test2B
55 ; CHECK-SAME: (i1 noundef [[C:%.*]], ptr nofree nonnull readnone returned dereferenceable(4) "no-capture-maybe-returned" [[RET:%.*]]) #[[ATTR2]] {
56 ; CHECK-NEXT: br i1 [[C]], label [[A:%.*]], label [[B:%.*]]
58 ; CHECK-NEXT: call void @llvm.assume(i1 noundef true) #[[ATTR15]] [ "dereferenceable"(ptr [[RET]], i32 4) ]
59 ; CHECK-NEXT: ret ptr [[RET]]
61 ; CHECK-NEXT: call void @llvm.assume(i1 noundef true) #[[ATTR15]] [ "dereferenceable"(ptr [[RET]], i32 4) ]
62 ; CHECK-NEXT: ret ptr [[RET]]
64 br i1 %c, label %A, label %B
66 call void @llvm.assume(i1 true) [ "dereferenceable"(ptr %ret, i32 4) ]
69 call void @llvm.assume(i1 true) [ "dereferenceable"(ptr %ret, i32 4) ]
73 ; Given an SCC where one of the functions can not be marked nonnull,
74 ; can we still mark the other one which is trivially nonnull
75 define ptr @scc_binder(i1 %c) {
76 ; CHECK-LABEL: define {{[^@]+}}@scc_binder
77 ; CHECK-SAME: (i1 noundef [[C:%.*]]) {
78 ; CHECK-NEXT: br i1 [[C]], label [[REC:%.*]], label [[END:%.*]]
80 ; CHECK-NEXT: [[TMP1:%.*]] = call ptr @test3(i1 noundef [[C]])
81 ; CHECK-NEXT: br label [[END]]
83 ; CHECK-NEXT: ret ptr null
85 br i1 %c, label %rec, label %end
87 call ptr @test3(i1 %c)
93 define ptr @test3(i1 %c) {
94 ; CHECK-LABEL: define {{[^@]+}}@test3
95 ; CHECK-SAME: (i1 [[C:%.*]]) {
96 ; CHECK-NEXT: [[TMP1:%.*]] = call ptr @scc_binder(i1 noundef [[C]])
97 ; CHECK-NEXT: [[RET:%.*]] = call nonnull ptr @ret_nonnull()
98 ; CHECK-NEXT: ret ptr [[RET]]
100 call ptr @scc_binder(i1 %c)
101 %ret = call ptr @ret_nonnull()
105 ; Given a mutual recursive set of functions, we can mark them
106 ; nonnull if neither can ever return null. (In this case, they
107 ; just never return period.)
108 define ptr @test4_helper() {
109 ; TUNIT: Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
110 ; TUNIT-LABEL: define {{[^@]+}}@test4_helper
111 ; TUNIT-SAME: () #[[ATTR3:[0-9]+]] {
112 ; TUNIT-NEXT: ret ptr undef
114 ; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
115 ; CGSCC-LABEL: define {{[^@]+}}@test4_helper
116 ; CGSCC-SAME: () #[[ATTR1]] {
117 ; CGSCC-NEXT: ret ptr undef
119 %ret = call ptr @test4()
123 define ptr @test4() {
124 ; TUNIT: Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
125 ; TUNIT-LABEL: define {{[^@]+}}@test4
126 ; TUNIT-SAME: () #[[ATTR3]] {
127 ; TUNIT-NEXT: ret ptr undef
129 ; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
130 ; CGSCC-LABEL: define {{[^@]+}}@test4
131 ; CGSCC-SAME: () #[[ATTR1]] {
132 ; CGSCC-NEXT: ret ptr undef
134 %ret = call ptr @test4_helper()
138 ; Given a mutual recursive set of functions which *can* return null
139 ; make sure we haven't marked them as nonnull.
140 define ptr @test5_helper(i1 %c) {
141 ; TUNIT: Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
142 ; TUNIT-LABEL: define {{[^@]+}}@test5_helper
143 ; TUNIT-SAME: (i1 noundef [[C:%.*]]) #[[ATTR3]] {
144 ; TUNIT-NEXT: br i1 [[C]], label [[REC:%.*]], label [[END:%.*]]
146 ; TUNIT-NEXT: br label [[END]]
148 ; TUNIT-NEXT: ret ptr null
150 ; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
151 ; CGSCC-LABEL: define {{[^@]+}}@test5_helper
152 ; CGSCC-SAME: (i1 noundef [[C:%.*]]) #[[ATTR1]] {
153 ; CGSCC-NEXT: br i1 [[C]], label [[REC:%.*]], label [[END:%.*]]
155 ; CGSCC-NEXT: br label [[END]]
157 ; CGSCC-NEXT: ret ptr null
159 br i1 %c, label %rec, label %end
161 %ret = call ptr @test5(i1 %c)
167 define ptr @test5(i1 %c) {
168 ; TUNIT: Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
169 ; TUNIT-LABEL: define {{[^@]+}}@test5
170 ; TUNIT-SAME: (i1 [[C:%.*]]) #[[ATTR3]] {
171 ; TUNIT-NEXT: ret ptr null
173 ; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
174 ; CGSCC-LABEL: define {{[^@]+}}@test5
175 ; CGSCC-SAME: (i1 [[C:%.*]]) #[[ATTR1]] {
176 ; CGSCC-NEXT: ret ptr null
178 %ret = call ptr @test5_helper(i1 %c)
182 ; Local analysis, but going through a self recursive phi
183 define ptr @test6a() {
185 ; TUNIT: Function Attrs: noreturn
186 ; TUNIT-LABEL: define {{[^@]+}}@test6a
187 ; TUNIT-SAME: () #[[ATTR4:[0-9]+]] {
189 ; TUNIT-NEXT: [[RET:%.*]] = call ptr @ret_nonnull()
190 ; TUNIT-NEXT: br label [[LOOP:%.*]]
192 ; TUNIT-NEXT: unreachable
194 ; TUNIT-NEXT: unreachable
196 ; CGSCC: Function Attrs: noreturn
197 ; CGSCC-LABEL: define {{[^@]+}}@test6a
198 ; CGSCC-SAME: () #[[ATTR3:[0-9]+]] {
200 ; CGSCC-NEXT: [[RET:%.*]] = call ptr @ret_nonnull()
201 ; CGSCC-NEXT: br label [[LOOP:%.*]]
203 ; CGSCC-NEXT: unreachable
205 ; CGSCC-NEXT: unreachable
208 %ret = call ptr @ret_nonnull()
211 %phi = phi ptr [%ret, %entry], [%phi, %loop]
212 br i1 undef, label %loop, label %exit
217 define ptr @test6b(i1 %c) {
218 ; CHECK-LABEL: define {{[^@]+}}@test6b
219 ; CHECK-SAME: (i1 [[C:%.*]]) {
221 ; CHECK-NEXT: [[RET:%.*]] = call nonnull ptr @ret_nonnull()
222 ; CHECK-NEXT: br label [[LOOP:%.*]]
224 ; CHECK-NEXT: [[PHI:%.*]] = phi ptr [ [[RET]], [[ENTRY:%.*]] ], [ [[RET]], [[LOOP]] ]
225 ; CHECK-NEXT: br i1 [[C]], label [[LOOP]], label [[EXIT:%.*]]
227 ; CHECK-NEXT: ret ptr [[RET]]
230 %ret = call ptr @ret_nonnull()
233 %phi = phi ptr [%ret, %entry], [%phi, %loop]
234 br i1 %c, label %loop, label %exit
239 define ptr @test7(ptr %a) {
240 ; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
241 ; CHECK-LABEL: define {{[^@]+}}@test7
242 ; CHECK-SAME: (ptr nofree readnone returned "no-capture-maybe-returned" [[A:%.*]]) #[[ATTR1]] {
243 ; CHECK-NEXT: ret ptr [[A]]
248 define ptr @test8(ptr %a) {
249 ; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
250 ; CHECK-LABEL: define {{[^@]+}}@test8
251 ; CHECK-SAME: (ptr nofree readnone "no-capture-maybe-returned" [[A:%.*]]) #[[ATTR1]] {
252 ; CHECK-NEXT: [[B:%.*]] = getelementptr inbounds i8, ptr [[A]], i64 1
253 ; CHECK-NEXT: ret ptr [[B]]
255 %b = getelementptr inbounds i8, ptr %a, i64 1
259 define ptr @test9(ptr %a, i64 %n) {
260 ; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
261 ; CHECK-LABEL: define {{[^@]+}}@test9
262 ; CHECK-SAME: (ptr nofree readnone "no-capture-maybe-returned" [[A:%.*]], i64 [[N:%.*]]) #[[ATTR1]] {
263 ; CHECK-NEXT: [[B:%.*]] = getelementptr inbounds i8, ptr [[A]], i64 [[N]]
264 ; CHECK-NEXT: ret ptr [[B]]
266 %b = getelementptr inbounds i8, ptr %a, i64 %n
270 ; ATTRIBUTOR_OPM: define ptr @test10
271 ; ATTRIBUTOR_NPM: define nonnull ptr @test10
272 define ptr @test10(ptr %a, i64 %n) {
273 ; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(inaccessiblemem: write)
274 ; CHECK-LABEL: define {{[^@]+}}@test10
275 ; CHECK-SAME: (ptr nofree readnone "no-capture-maybe-returned" [[A:%.*]], i64 [[N:%.*]]) #[[ATTR2]] {
276 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i64 [[N]], 0
277 ; CHECK-NEXT: call void @llvm.assume(i1 noundef [[CMP]]) #[[ATTR15]]
278 ; CHECK-NEXT: [[B:%.*]] = getelementptr inbounds i8, ptr [[A]], i64 [[N]]
279 ; CHECK-NEXT: ret ptr [[B]]
281 %cmp = icmp ne i64 %n, 0
282 call void @llvm.assume(i1 %cmp)
283 %b = getelementptr inbounds i8, ptr %a, i64 %n
288 ; char* test11(char *p) {
289 ; return p? p: nonnull();
291 ; FIXME: missing nonnull
292 define ptr @test11(ptr) local_unnamed_addr {
293 ; CHECK-LABEL: define {{[^@]+}}@test11
294 ; CHECK-SAME: (ptr [[TMP0:%.*]]) local_unnamed_addr {
295 ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq ptr [[TMP0]], null
296 ; CHECK-NEXT: br i1 [[TMP2]], label [[TMP3:%.*]], label [[TMP5:%.*]]
298 ; CHECK-NEXT: [[TMP4:%.*]] = tail call ptr @ret_nonnull()
299 ; CHECK-NEXT: br label [[TMP5]]
301 ; CHECK-NEXT: [[TMP6:%.*]] = phi ptr [ [[TMP4]], [[TMP3]] ], [ [[TMP0]], [[TMP1:%.*]] ]
302 ; CHECK-NEXT: ret ptr [[TMP6]]
304 %2 = icmp eq ptr %0, null
305 br i1 %2, label %3, label %5
307 ; <label>:3: ; preds = %1
308 %4 = tail call ptr @ret_nonnull()
311 ; <label>:5: ; preds = %3, %1
312 %6 = phi ptr [ %4, %3 ], [ %0, %1 ]
317 ; Simple CallSite Test
318 declare void @test12_helper(ptr)
319 define void @test12(ptr nonnull %a) {
320 ; CHECK-LABEL: define {{[^@]+}}@test12
321 ; CHECK-SAME: (ptr nonnull [[A:%.*]]) {
322 ; CHECK-NEXT: tail call void @test12_helper(ptr nonnull [[A]])
323 ; CHECK-NEXT: ret void
325 tail call void @test12_helper(ptr %a)
330 ; Simple Argument Tests
331 declare ptr @unknown()
332 define void @test13_helper() {
333 ; TUNIT-LABEL: define {{[^@]+}}@test13_helper() {
334 ; TUNIT-NEXT: [[NONNULLPTR:%.*]] = tail call nonnull ptr @ret_nonnull()
335 ; TUNIT-NEXT: [[MAYBENULLPTR:%.*]] = tail call ptr @unknown()
336 ; TUNIT-NEXT: tail call void @test13(ptr noalias nocapture nofree nonnull readnone [[NONNULLPTR]], ptr noalias nocapture nofree nonnull readnone [[NONNULLPTR]], ptr noalias nocapture nofree readnone [[MAYBENULLPTR]]) #[[ATTR5:[0-9]+]]
337 ; TUNIT-NEXT: tail call void @test13(ptr noalias nocapture nofree nonnull readnone [[NONNULLPTR]], ptr noalias nocapture nofree readnone [[MAYBENULLPTR]], ptr noalias nocapture nofree nonnull readnone [[NONNULLPTR]]) #[[ATTR5]]
338 ; TUNIT-NEXT: ret void
340 ; CGSCC-LABEL: define {{[^@]+}}@test13_helper() {
341 ; CGSCC-NEXT: [[NONNULLPTR:%.*]] = tail call nonnull ptr @ret_nonnull()
342 ; CGSCC-NEXT: [[MAYBENULLPTR:%.*]] = tail call ptr @unknown()
343 ; CGSCC-NEXT: tail call void @test13(ptr noalias nocapture nofree nonnull readnone [[NONNULLPTR]], ptr noalias nocapture nofree nonnull readnone [[NONNULLPTR]], ptr noalias nocapture nofree readnone [[MAYBENULLPTR]]) #[[ATTR4:[0-9]+]]
344 ; CGSCC-NEXT: tail call void @test13(ptr noalias nocapture nofree nonnull readnone [[NONNULLPTR]], ptr noalias nocapture nofree readnone [[MAYBENULLPTR]], ptr noalias nocapture nofree nonnull readnone [[NONNULLPTR]]) #[[ATTR4]]
345 ; CGSCC-NEXT: ret void
347 %nonnullptr = tail call ptr @ret_nonnull()
348 %maybenullptr = tail call ptr @unknown()
349 tail call void @test13(ptr %nonnullptr, ptr %nonnullptr, ptr %maybenullptr)
350 tail call void @test13(ptr %nonnullptr, ptr %maybenullptr, ptr %nonnullptr)
353 define internal void @test13(ptr %a, ptr %b, ptr %c) {
355 ; TUNIT: Function Attrs: nounwind
356 ; TUNIT-LABEL: define {{[^@]+}}@test13
357 ; TUNIT-SAME: (ptr noalias nocapture nofree nonnull readnone [[A:%.*]], ptr noalias nocapture nofree readnone [[B:%.*]], ptr noalias nocapture nofree readnone [[C:%.*]]) #[[ATTR5]] {
358 ; TUNIT-NEXT: call void @use_i8_ptr(ptr noalias nocapture nofree nonnull readnone [[A]]) #[[ATTR5]]
359 ; TUNIT-NEXT: call void @use_i8_ptr(ptr noalias nocapture nofree readnone [[B]]) #[[ATTR5]]
360 ; TUNIT-NEXT: call void @use_i8_ptr(ptr noalias nocapture nofree readnone [[C]]) #[[ATTR5]]
361 ; TUNIT-NEXT: ret void
363 ; CGSCC: Function Attrs: nounwind
364 ; CGSCC-LABEL: define {{[^@]+}}@test13
365 ; CGSCC-SAME: (ptr noalias nocapture nofree nonnull readnone [[A:%.*]], ptr noalias nocapture nofree readnone [[B:%.*]], ptr noalias nocapture nofree readnone [[C:%.*]]) #[[ATTR4]] {
366 ; CGSCC-NEXT: call void @use_i8_ptr(ptr noalias nocapture nofree nonnull readnone [[A]]) #[[ATTR4]]
367 ; CGSCC-NEXT: call void @use_i8_ptr(ptr noalias nocapture nofree readnone [[B]]) #[[ATTR4]]
368 ; CGSCC-NEXT: call void @use_i8_ptr(ptr noalias nocapture nofree readnone [[C]]) #[[ATTR4]]
369 ; CGSCC-NEXT: ret void
371 call void @use_i8_ptr(ptr %a)
372 call void @use_i8_ptr(ptr %b)
373 call void @use_i8_ptr(ptr %c)
377 declare nonnull ptr @nonnull()
380 ; Complex propagation
381 ; Argument of f1, f2, f3 can be marked with nonnull.
384 ; 1. In f1:bb6, %arg can be marked with nonnull because of the comparison in bb1
385 ; 2. Because f2 is internal function, f2(ptr %arg) -> @f2(ptr nonnull %arg)
386 ; 3. In f1:bb4 %tmp5 is nonnull and f3 is internal function.
387 ; Then, f3(ptr %arg) -> @f3(ptr nonnull %arg)
388 ; 4. We get nonnull in whole f1 call sites so f1(ptr %arg) -> @f1(ptr nonnull %arg)
391 define internal ptr @f1(ptr %arg) {
392 ; FIXME: missing nonnull It should be nonnull @f1(ptr nonnull readonly %arg)
393 ; TUNIT: Function Attrs: nofree nosync nounwind memory(argmem: read)
394 ; TUNIT-LABEL: define {{[^@]+}}@f1
395 ; TUNIT-SAME: (ptr nofree readonly [[ARG:%.*]]) #[[ATTR6:[0-9]+]] {
397 ; TUNIT-NEXT: [[TMP:%.*]] = icmp eq ptr [[ARG]], null
398 ; TUNIT-NEXT: br i1 [[TMP]], label [[BB9:%.*]], label [[BB1:%.*]]
400 ; TUNIT-NEXT: [[TRUETMP2:%.*]] = load i32, ptr [[ARG]], align 4
401 ; TUNIT-NEXT: [[TRUETMP3:%.*]] = icmp eq i32 [[TRUETMP2]], 0
402 ; TUNIT-NEXT: br i1 [[TRUETMP3]], label [[BB6:%.*]], label [[BB4:%.*]]
404 ; TUNIT-NEXT: [[TRUETMP5:%.*]] = getelementptr inbounds i32, ptr [[ARG]], i64 1
405 ; TUNIT-NEXT: [[TMP5B:%.*]] = tail call ptr @f3(ptr nofree nonnull readonly [[TRUETMP5]]) #[[ATTR16:[0-9]+]]
406 ; TUNIT-NEXT: [[TMP5C:%.*]] = getelementptr inbounds i32, ptr [[TMP5B]], i64 -1
407 ; TUNIT-NEXT: br label [[BB9]]
409 ; TUNIT-NEXT: [[TRUETMP7:%.*]] = tail call ptr @f2(ptr nofree nonnull readonly align 4 dereferenceable(4) [[ARG]]) #[[ATTR16]]
410 ; TUNIT-NEXT: ret ptr [[TRUETMP7]]
412 ; TUNIT-NEXT: [[TRUETMP10:%.*]] = phi ptr [ [[TMP5C]], [[BB4]] ], [ inttoptr (i64 4 to ptr), [[BB:%.*]] ]
413 ; TUNIT-NEXT: ret ptr [[TRUETMP10]]
415 ; CGSCC: Function Attrs: nofree nosync nounwind memory(argmem: read)
416 ; CGSCC-LABEL: define {{[^@]+}}@f1
417 ; CGSCC-SAME: (ptr nofree readonly [[ARG:%.*]]) #[[ATTR5:[0-9]+]] {
419 ; CGSCC-NEXT: [[TMP:%.*]] = icmp eq ptr [[ARG]], null
420 ; CGSCC-NEXT: br i1 [[TMP]], label [[BB9:%.*]], label [[BB1:%.*]]
422 ; CGSCC-NEXT: [[TRUETMP2:%.*]] = load i32, ptr [[ARG]], align 4
423 ; CGSCC-NEXT: [[TRUETMP3:%.*]] = icmp eq i32 [[TRUETMP2]], 0
424 ; CGSCC-NEXT: br i1 [[TRUETMP3]], label [[BB6:%.*]], label [[BB4:%.*]]
426 ; CGSCC-NEXT: [[TRUETMP5:%.*]] = getelementptr inbounds i32, ptr [[ARG]], i64 1
427 ; CGSCC-NEXT: [[TMP5B:%.*]] = tail call ptr @f3(ptr nofree nonnull readonly [[TRUETMP5]]) #[[ATTR16:[0-9]+]]
428 ; CGSCC-NEXT: [[TMP5C:%.*]] = getelementptr inbounds i32, ptr [[TMP5B]], i64 -1
429 ; CGSCC-NEXT: br label [[BB9]]
431 ; CGSCC-NEXT: [[TRUETMP7:%.*]] = tail call ptr @f2(ptr nofree nonnull readonly align 4 dereferenceable(4) [[ARG]]) #[[ATTR16]]
432 ; CGSCC-NEXT: ret ptr [[TRUETMP7]]
434 ; CGSCC-NEXT: [[TRUETMP10:%.*]] = phi ptr [ [[TMP5C]], [[BB4]] ], [ inttoptr (i64 4 to ptr), [[BB:%.*]] ]
435 ; CGSCC-NEXT: ret ptr [[TRUETMP10]]
439 %tmp = icmp eq ptr %arg, null
440 br i1 %tmp, label %bb9, label %bb1
443 %tmp2 = load i32, ptr %arg, align 4
444 %tmp3 = icmp eq i32 %tmp2, 0
445 br i1 %tmp3, label %bb6, label %bb4
448 %tmp5 = getelementptr inbounds i32, ptr %arg, i64 1
449 %tmp5b = tail call ptr @f3(ptr %tmp5)
450 %tmp5c = getelementptr inbounds i32, ptr %tmp5b, i64 -1
454 %tmp7 = tail call ptr @f2(ptr %arg)
457 bb9: ; preds = %bb4, %bb
458 %tmp10 = phi ptr [ %tmp5c, %bb4 ], [ inttoptr (i64 4 to ptr), %bb ]
462 define internal ptr @f2(ptr %arg) {
463 ; TUNIT: Function Attrs: nofree nosync nounwind memory(argmem: read)
464 ; TUNIT-LABEL: define {{[^@]+}}@f2
465 ; TUNIT-SAME: (ptr nofree nonnull readonly align 4 dereferenceable(4) [[ARG:%.*]]) #[[ATTR6]] {
467 ; TUNIT-NEXT: [[TMP:%.*]] = tail call ptr @f1(ptr nofree readonly [[ARG]]) #[[ATTR16]]
468 ; TUNIT-NEXT: ret ptr [[TMP]]
470 ; CGSCC: Function Attrs: nofree nosync nounwind memory(argmem: read)
471 ; CGSCC-LABEL: define {{[^@]+}}@f2
472 ; CGSCC-SAME: (ptr nofree nonnull readonly align 4 dereferenceable(4) [[ARG:%.*]]) #[[ATTR5]] {
474 ; CGSCC-NEXT: [[TMP:%.*]] = tail call ptr @f1(ptr nofree readonly [[ARG]]) #[[ATTR16]]
475 ; CGSCC-NEXT: ret ptr [[TMP]]
478 %tmp = tail call ptr @f1(ptr %arg)
482 define dso_local noalias ptr @f3(ptr %arg) {
483 ; FIXME: missing nonnull. It should be nonnull @f3(ptr nonnull readonly %arg)
484 ; TUNIT: Function Attrs: nofree nosync nounwind memory(argmem: read)
485 ; TUNIT-LABEL: define {{[^@]+}}@f3
486 ; TUNIT-SAME: (ptr nofree readonly [[ARG:%.*]]) #[[ATTR6]] {
488 ; TUNIT-NEXT: [[TMP:%.*]] = call ptr @f1(ptr nofree readonly [[ARG]]) #[[ATTR16]]
489 ; TUNIT-NEXT: ret ptr [[TMP]]
491 ; CGSCC: Function Attrs: nofree nosync nounwind memory(argmem: read)
492 ; CGSCC-LABEL: define {{[^@]+}}@f3
493 ; CGSCC-SAME: (ptr nofree readonly [[ARG:%.*]]) #[[ATTR5]] {
495 ; CGSCC-NEXT: [[TMP:%.*]] = call ptr @f1(ptr nofree readonly [[ARG]]) #[[ATTR16]]
496 ; CGSCC-NEXT: ret ptr [[TMP]]
499 ; FIXME: missing nonnull. It should be @f1(ptr nonnull readonly %arg)
500 %tmp = call ptr @f1(ptr %arg)
505 define void @f15(ptr %arg) {
506 ; CHECK-LABEL: define {{[^@]+}}@f15
507 ; CHECK-SAME: (ptr noundef nonnull dereferenceable(4) [[ARG:%.*]]) {
508 ; CHECK-NEXT: tail call void @use1(ptr noundef nonnull dereferenceable(4) [[ARG]])
509 ; CHECK-NEXT: ret void
512 tail call void @use1(ptr dereferenceable(4) %arg)
516 declare void @fun0() #1
517 declare void @fun1(ptr) #1
518 declare void @fun2(ptr, ptr) #1
519 declare void @fun3(ptr, ptr, ptr) #1
520 ; TEST 16 simple path test
522 ; fun2(nonnull %a, nonnull %b)
524 ; fun2(nonnull %a, %b)
525 ; We can say that %a is nonnull but %b is not.
526 define void @f16(ptr %a, ptr %b, i8 %c) {
527 ; TUNIT: Function Attrs: mustprogress nounwind willreturn
528 ; TUNIT-LABEL: define {{[^@]+}}@f16
529 ; TUNIT-SAME: (ptr nonnull [[A:%.*]], ptr [[B:%.*]], i8 [[C:%.*]]) #[[ATTR8:[0-9]+]] {
530 ; TUNIT-NEXT: [[CMP:%.*]] = icmp eq i8 [[C]], 0
531 ; TUNIT-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
533 ; TUNIT-NEXT: tail call void @fun2(ptr nonnull [[A]], ptr nonnull [[B]]) #[[ATTR7:[0-9]+]]
534 ; TUNIT-NEXT: ret void
536 ; TUNIT-NEXT: tail call void @fun2(ptr nonnull [[A]], ptr [[B]]) #[[ATTR7]]
537 ; TUNIT-NEXT: ret void
539 ; CGSCC: Function Attrs: mustprogress nounwind willreturn
540 ; CGSCC-LABEL: define {{[^@]+}}@f16
541 ; CGSCC-SAME: (ptr nonnull [[A:%.*]], ptr [[B:%.*]], i8 [[C:%.*]]) #[[ATTR7:[0-9]+]] {
542 ; CGSCC-NEXT: [[CMP:%.*]] = icmp eq i8 [[C]], 0
543 ; CGSCC-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
545 ; CGSCC-NEXT: tail call void @fun2(ptr nonnull [[A]], ptr nonnull [[B]]) #[[ATTR6:[0-9]+]]
546 ; CGSCC-NEXT: ret void
548 ; CGSCC-NEXT: tail call void @fun2(ptr nonnull [[A]], ptr [[B]]) #[[ATTR6]]
549 ; CGSCC-NEXT: ret void
551 %cmp = icmp eq i8 %c, 0
552 br i1 %cmp, label %if.then, label %if.else
554 tail call void @fun2(ptr nonnull %a, ptr nonnull %b)
557 tail call void @fun2(ptr nonnull %a, ptr %b)
560 ; TEST 17 explore child BB test
562 ; ... (willreturn & nounwind)
564 ; ... (willreturn & nounwind)
566 ; We can say that %a is nonnull
567 define void @f17(ptr %a, i8 %c) {
569 ; TUNIT: Function Attrs: mustprogress nounwind willreturn
570 ; TUNIT-LABEL: define {{[^@]+}}@f17
571 ; TUNIT-SAME: (ptr nonnull [[A:%.*]], i8 [[C:%.*]]) #[[ATTR8]] {
572 ; TUNIT-NEXT: [[CMP:%.*]] = icmp eq i8 [[C]], 0
573 ; TUNIT-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
575 ; TUNIT-NEXT: tail call void @fun0() #[[ATTR7]]
576 ; TUNIT-NEXT: br label [[CONT:%.*]]
578 ; TUNIT-NEXT: tail call void @fun0() #[[ATTR7]]
579 ; TUNIT-NEXT: br label [[CONT]]
581 ; TUNIT-NEXT: tail call void @fun1(ptr nonnull [[A]]) #[[ATTR7]]
582 ; TUNIT-NEXT: ret void
584 ; CGSCC: Function Attrs: mustprogress nounwind willreturn
585 ; CGSCC-LABEL: define {{[^@]+}}@f17
586 ; CGSCC-SAME: (ptr nonnull [[A:%.*]], i8 [[C:%.*]]) #[[ATTR7]] {
587 ; CGSCC-NEXT: [[CMP:%.*]] = icmp eq i8 [[C]], 0
588 ; CGSCC-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
590 ; CGSCC-NEXT: tail call void @fun0() #[[ATTR6]]
591 ; CGSCC-NEXT: br label [[CONT:%.*]]
593 ; CGSCC-NEXT: tail call void @fun0() #[[ATTR6]]
594 ; CGSCC-NEXT: br label [[CONT]]
596 ; CGSCC-NEXT: tail call void @fun1(ptr nonnull [[A]]) #[[ATTR6]]
597 ; CGSCC-NEXT: ret void
599 %cmp = icmp eq i8 %c, 0
600 br i1 %cmp, label %if.then, label %if.else
602 tail call void @fun0()
605 tail call void @fun0()
608 tail call void @fun1(ptr nonnull %a)
611 ; TEST 18 More complex test
613 ; ... (willreturn & nounwind)
615 ; ... (willreturn & nounwind)
617 ; ... (willreturn & nounwind)
619 ; ... (willreturn & nounwind)
622 define void @f18(ptr %a, ptr %b, i8 %c) {
623 ; TUNIT: Function Attrs: mustprogress nounwind willreturn
624 ; TUNIT-LABEL: define {{[^@]+}}@f18
625 ; TUNIT-SAME: (ptr nonnull [[A:%.*]], ptr [[B:%.*]], i8 [[C:%.*]]) #[[ATTR8]] {
626 ; TUNIT-NEXT: [[CMP1:%.*]] = icmp eq i8 [[C]], 0
627 ; TUNIT-NEXT: br i1 [[CMP1]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
629 ; TUNIT-NEXT: tail call void @fun0() #[[ATTR7]]
630 ; TUNIT-NEXT: br label [[CONT:%.*]]
632 ; TUNIT-NEXT: tail call void @fun0() #[[ATTR7]]
633 ; TUNIT-NEXT: br label [[CONT]]
635 ; TUNIT-NEXT: [[CMP2:%.*]] = icmp eq i8 [[C]], 1
636 ; TUNIT-NEXT: br i1 [[CMP2]], label [[CONT_THEN:%.*]], label [[CONT_ELSE:%.*]]
638 ; TUNIT-NEXT: tail call void @fun1(ptr nonnull [[B]]) #[[ATTR7]]
639 ; TUNIT-NEXT: br label [[CONT2:%.*]]
641 ; TUNIT-NEXT: tail call void @fun0() #[[ATTR7]]
642 ; TUNIT-NEXT: br label [[CONT2]]
644 ; TUNIT-NEXT: tail call void @fun1(ptr nonnull [[A]]) #[[ATTR7]]
645 ; TUNIT-NEXT: ret void
647 ; CGSCC: Function Attrs: mustprogress nounwind willreturn
648 ; CGSCC-LABEL: define {{[^@]+}}@f18
649 ; CGSCC-SAME: (ptr nonnull [[A:%.*]], ptr [[B:%.*]], i8 [[C:%.*]]) #[[ATTR7]] {
650 ; CGSCC-NEXT: [[CMP1:%.*]] = icmp eq i8 [[C]], 0
651 ; CGSCC-NEXT: br i1 [[CMP1]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
653 ; CGSCC-NEXT: tail call void @fun0() #[[ATTR6]]
654 ; CGSCC-NEXT: br label [[CONT:%.*]]
656 ; CGSCC-NEXT: tail call void @fun0() #[[ATTR6]]
657 ; CGSCC-NEXT: br label [[CONT]]
659 ; CGSCC-NEXT: [[CMP2:%.*]] = icmp eq i8 [[C]], 1
660 ; CGSCC-NEXT: br i1 [[CMP2]], label [[CONT_THEN:%.*]], label [[CONT_ELSE:%.*]]
662 ; CGSCC-NEXT: tail call void @fun1(ptr nonnull [[B]]) #[[ATTR6]]
663 ; CGSCC-NEXT: br label [[CONT2:%.*]]
665 ; CGSCC-NEXT: tail call void @fun0() #[[ATTR6]]
666 ; CGSCC-NEXT: br label [[CONT2]]
668 ; CGSCC-NEXT: tail call void @fun1(ptr nonnull [[A]]) #[[ATTR6]]
669 ; CGSCC-NEXT: ret void
671 %cmp1 = icmp eq i8 %c, 0
672 br i1 %cmp1, label %if.then, label %if.else
674 tail call void @fun0()
677 tail call void @fun0()
680 %cmp2 = icmp eq i8 %c, 1
681 br i1 %cmp2, label %cont.then, label %cont.else
683 tail call void @fun1(ptr nonnull %b)
686 tail call void @fun0()
689 tail call void @fun1(ptr nonnull %a)
695 define void @f19(ptr %a, ptr %b, i8 %c) {
696 ; TUNIT: Function Attrs: nounwind
697 ; TUNIT-LABEL: define {{[^@]+}}@f19
698 ; TUNIT-SAME: (ptr [[A:%.*]], ptr nonnull [[B:%.*]], i8 [[C:%.*]]) #[[ATTR5]] {
699 ; TUNIT-NEXT: br label [[LOOP_HEADER:%.*]]
700 ; TUNIT: loop.header:
701 ; TUNIT-NEXT: [[CMP2:%.*]] = icmp eq i8 [[C]], 0
702 ; TUNIT-NEXT: br i1 [[CMP2]], label [[LOOP_BODY:%.*]], label [[LOOP_EXIT:%.*]]
704 ; TUNIT-NEXT: tail call void @fun1(ptr nonnull [[B]]) #[[ATTR5]]
705 ; TUNIT-NEXT: tail call void @fun1(ptr nonnull [[A]]) #[[ATTR5]]
706 ; TUNIT-NEXT: br label [[LOOP_HEADER]]
708 ; TUNIT-NEXT: tail call void @fun1(ptr nonnull [[B]]) #[[ATTR5]]
709 ; TUNIT-NEXT: ret void
711 ; CGSCC: Function Attrs: nounwind
712 ; CGSCC-LABEL: define {{[^@]+}}@f19
713 ; CGSCC-SAME: (ptr [[A:%.*]], ptr nonnull [[B:%.*]], i8 [[C:%.*]]) #[[ATTR4]] {
714 ; CGSCC-NEXT: br label [[LOOP_HEADER:%.*]]
715 ; CGSCC: loop.header:
716 ; CGSCC-NEXT: [[CMP2:%.*]] = icmp eq i8 [[C]], 0
717 ; CGSCC-NEXT: br i1 [[CMP2]], label [[LOOP_BODY:%.*]], label [[LOOP_EXIT:%.*]]
719 ; CGSCC-NEXT: tail call void @fun1(ptr nonnull [[B]]) #[[ATTR4]]
720 ; CGSCC-NEXT: tail call void @fun1(ptr nonnull [[A]]) #[[ATTR4]]
721 ; CGSCC-NEXT: br label [[LOOP_HEADER]]
723 ; CGSCC-NEXT: tail call void @fun1(ptr nonnull [[B]]) #[[ATTR4]]
724 ; CGSCC-NEXT: ret void
726 br label %loop.header
728 %cmp2 = icmp eq i8 %c, 0
729 br i1 %cmp2, label %loop.body, label %loop.exit
731 tail call void @fun1(ptr nonnull %b)
732 tail call void @fun1(ptr nonnull %a)
733 br label %loop.header
735 tail call void @fun1(ptr nonnull %b)
739 ; Test propagation of nonnull callsite args back to caller.
741 declare void @use1(ptr %x)
742 declare void @use2(ptr %x, ptr %y);
743 declare void @use3(ptr %x, ptr %y, ptr %z);
745 declare void @use1nonnull(ptr nonnull %x);
746 declare void @use2nonnull(ptr nonnull %x, ptr nonnull %y);
747 declare void @use3nonnull(ptr nonnull %x, ptr nonnull %y, ptr nonnull %z);
749 declare i8 @use1safecall(ptr %x) readonly nounwind willreturn ; nounwind+willreturn guarantees that execution continues to successor
751 ; Can't extend non-null to parent for any argument because the 2nd call is not guaranteed to execute.
753 define void @parent1(ptr %a, ptr %b, ptr %c) {
754 ; CHECK-LABEL: define {{[^@]+}}@parent1
755 ; CHECK-SAME: (ptr [[A:%.*]], ptr [[B:%.*]], ptr [[C:%.*]]) {
756 ; CHECK-NEXT: call void @use3(ptr [[C]], ptr [[A]], ptr [[B]])
757 ; CHECK-NEXT: call void @use3nonnull(ptr nonnull [[B]], ptr nonnull [[C]], ptr nonnull [[A]])
758 ; CHECK-NEXT: ret void
760 call void @use3(ptr %c, ptr %a, ptr %b)
761 call void @use3nonnull(ptr %b, ptr %c, ptr %a)
765 ; Extend non-null to parent for all arguments.
767 define void @parent2(ptr %a, ptr %b, ptr %c) {
768 ; CHECK-LABEL: define {{[^@]+}}@parent2
769 ; CHECK-SAME: (ptr nonnull [[A:%.*]], ptr nonnull [[B:%.*]], ptr nonnull [[C:%.*]]) {
770 ; CHECK-NEXT: call void @use3nonnull(ptr nonnull [[B]], ptr nonnull [[C]], ptr nonnull [[A]])
771 ; CHECK-NEXT: call void @use3(ptr nonnull [[C]], ptr nonnull [[A]], ptr nonnull [[B]])
772 ; CHECK-NEXT: ret void
775 call void @use3nonnull(ptr %b, ptr %c, ptr %a)
776 call void @use3(ptr %c, ptr %a, ptr %b)
780 ; Extend non-null to parent for 1st argument.
782 define void @parent3(ptr %a, ptr %b, ptr %c) {
783 ; CHECK-LABEL: define {{[^@]+}}@parent3
784 ; CHECK-SAME: (ptr nonnull [[A:%.*]], ptr [[B:%.*]], ptr [[C:%.*]]) {
785 ; CHECK-NEXT: call void @use1nonnull(ptr nonnull [[A]])
786 ; CHECK-NEXT: call void @use3(ptr [[C]], ptr [[B]], ptr nonnull [[A]])
787 ; CHECK-NEXT: ret void
791 call void @use1nonnull(ptr %a)
792 call void @use3(ptr %c, ptr %b, ptr %a)
796 ; Extend non-null to parent for last 2 arguments.
798 define void @parent4(ptr %a, ptr %b, ptr %c) {
799 ; CHECK-LABEL: define {{[^@]+}}@parent4
800 ; CHECK-SAME: (ptr [[A:%.*]], ptr nonnull [[B:%.*]], ptr nonnull [[C:%.*]]) {
801 ; CHECK-NEXT: call void @use2nonnull(ptr nonnull [[C]], ptr nonnull [[B]])
802 ; CHECK-NEXT: call void @use2(ptr [[A]], ptr nonnull [[C]])
803 ; CHECK-NEXT: call void @use1(ptr nonnull [[B]])
804 ; CHECK-NEXT: ret void
809 call void @use2nonnull(ptr %c, ptr %b)
810 call void @use2(ptr %a, ptr %c)
811 call void @use1(ptr %b)
815 ; The callsite must execute in order for the attribute to transfer to the parent.
816 ; It appears benign to extend non-null to the parent in this case, but we can't do that
817 ; because it would incorrectly propagate the wrong information to its callers.
819 define void @parent5(ptr %a, i1 %a_is_notnull) {
820 ; CHECK-LABEL: define {{[^@]+}}@parent5
821 ; CHECK-SAME: (ptr [[A:%.*]], i1 noundef [[A_IS_NOTNULL:%.*]]) {
822 ; CHECK-NEXT: br i1 [[A_IS_NOTNULL]], label [[T:%.*]], label [[F:%.*]]
824 ; CHECK-NEXT: call void @use1nonnull(ptr nonnull [[A]])
825 ; CHECK-NEXT: ret void
827 ; CHECK-NEXT: ret void
830 br i1 %a_is_notnull, label %t, label %f
832 call void @use1nonnull(ptr %a)
838 ; The callsite must execute in order for the attribute to transfer to the parent.
839 ; The volatile load can't trap, so we can guarantee that we'll get to the call.
841 define i8 @parent6(ptr %a, ptr %b) {
842 ; CHECK-LABEL: define {{[^@]+}}@parent6
843 ; CHECK-SAME: (ptr nonnull [[A:%.*]], ptr nofree noundef [[B:%.*]]) {
844 ; CHECK-NEXT: [[C:%.*]] = load volatile i8, ptr [[B]], align 1
845 ; CHECK-NEXT: call void @use1nonnull(ptr nonnull [[A]])
846 ; CHECK-NEXT: ret i8 [[C]]
849 %c = load volatile i8, ptr %b
850 call void @use1nonnull(ptr %a)
854 ; The nonnull callsite is guaranteed to execute, so the argument must be nonnull throughout the parent.
856 define i8 @parent7(ptr %a) {
857 ; CHECK-LABEL: define {{[^@]+}}@parent7
858 ; CHECK-SAME: (ptr nonnull [[A:%.*]]) {
859 ; CHECK-NEXT: [[RET:%.*]] = call i8 @use1safecall(ptr nonnull readonly [[A]]) #[[ATTR17:[0-9]+]]
860 ; CHECK-NEXT: call void @use1nonnull(ptr nonnull [[A]])
861 ; CHECK-NEXT: ret i8 [[RET]]
865 %ret = call i8 @use1safecall(ptr %a)
866 call void @use1nonnull(ptr %a)
870 ; Make sure that an invoke works similarly to a call.
872 declare i32 @esfp(...)
874 define i1 @parent8(ptr %a, ptr %bogus1, ptr %b) personality ptr @esfp{
875 ; TUNIT: Function Attrs: nounwind
876 ; TUNIT-LABEL: define {{[^@]+}}@parent8
877 ; TUNIT-SAME: (ptr nonnull [[A:%.*]], ptr nocapture nofree readnone [[BOGUS1:%.*]], ptr nonnull [[B:%.*]]) #[[ATTR5]] personality ptr @esfp {
879 ; TUNIT-NEXT: invoke void @use2nonnull(ptr nonnull [[A]], ptr nonnull [[B]])
880 ; TUNIT-NEXT: to label [[CONT:%.*]] unwind label [[EXC:%.*]]
882 ; TUNIT-NEXT: ret i1 false
884 ; TUNIT-NEXT: [[LP:%.*]] = landingpad { ptr, i32 }
885 ; TUNIT-NEXT: filter [0 x ptr] zeroinitializer
886 ; TUNIT-NEXT: unreachable
888 ; CGSCC: Function Attrs: nounwind
889 ; CGSCC-LABEL: define {{[^@]+}}@parent8
890 ; CGSCC-SAME: (ptr nonnull [[A:%.*]], ptr nocapture nofree readnone [[BOGUS1:%.*]], ptr nonnull [[B:%.*]]) #[[ATTR4]] personality ptr @esfp {
892 ; CGSCC-NEXT: invoke void @use2nonnull(ptr nonnull [[A]], ptr nonnull [[B]])
893 ; CGSCC-NEXT: to label [[CONT:%.*]] unwind label [[EXC:%.*]]
895 ; CGSCC-NEXT: ret i1 false
897 ; CGSCC-NEXT: [[LP:%.*]] = landingpad { ptr, i32 }
898 ; CGSCC-NEXT: filter [0 x ptr] zeroinitializer
899 ; CGSCC-NEXT: unreachable
903 invoke void @use2nonnull(ptr %a, ptr %b)
904 to label %cont unwind label %exc
907 %null_check = icmp eq ptr %b, null
911 %lp = landingpad { ptr, i32 }
912 filter [0 x ptr] zeroinitializer
916 define ptr @gep1(ptr %p) {
917 ; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
918 ; CHECK-LABEL: define {{[^@]+}}@gep1
919 ; CHECK-SAME: (ptr nofree readnone "no-capture-maybe-returned" [[P:%.*]]) #[[ATTR1]] {
920 ; CHECK-NEXT: [[Q:%.*]] = getelementptr inbounds i32, ptr [[P]], i32 1
921 ; CHECK-NEXT: ret ptr [[Q]]
923 %q = getelementptr inbounds i32, ptr %p, i32 1
927 define ptr @gep1_no_null_opt(ptr %p) #0 {
928 ; Should't be able to derive nonnull based on gep.
929 ; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind null_pointer_is_valid willreturn memory(none)
930 ; TUNIT-LABEL: define {{[^@]+}}@gep1_no_null_opt
931 ; TUNIT-SAME: (ptr nofree readnone "no-capture-maybe-returned" [[P:%.*]]) #[[ATTR10:[0-9]+]] {
932 ; TUNIT-NEXT: [[Q:%.*]] = getelementptr inbounds i32, ptr [[P]], i32 1
933 ; TUNIT-NEXT: ret ptr [[Q]]
935 ; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind null_pointer_is_valid willreturn memory(none)
936 ; CGSCC-LABEL: define {{[^@]+}}@gep1_no_null_opt
937 ; CGSCC-SAME: (ptr nofree readnone "no-capture-maybe-returned" [[P:%.*]]) #[[ATTR9:[0-9]+]] {
938 ; CGSCC-NEXT: [[Q:%.*]] = getelementptr inbounds i32, ptr [[P]], i32 1
939 ; CGSCC-NEXT: ret ptr [[Q]]
941 %q = getelementptr inbounds i32, ptr %p, i32 1
945 define ptr addrspace(3) @gep2(ptr addrspace(3) %p) {
946 ; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
947 ; CHECK-LABEL: define {{[^@]+}}@gep2
948 ; CHECK-SAME: (ptr addrspace(3) nofree readnone "no-capture-maybe-returned" [[P:%.*]]) #[[ATTR1]] {
949 ; CHECK-NEXT: [[Q:%.*]] = getelementptr inbounds i32, ptr addrspace(3) [[P]], i32 1
950 ; CHECK-NEXT: ret ptr addrspace(3) [[Q]]
952 %q = getelementptr inbounds i32, ptr addrspace(3) %p, i32 1
953 ret ptr addrspace(3) %q
956 ; FIXME: We should propagate dereferenceable here but *not* nonnull
957 define ptr addrspace(3) @as(ptr addrspace(3) dereferenceable(4) %p) {
958 ; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
959 ; CHECK-LABEL: define {{[^@]+}}@as
960 ; CHECK-SAME: (ptr addrspace(3) nofree noundef readnone returned dereferenceable(4) dereferenceable_or_null(4) "no-capture-maybe-returned" [[P:%.*]]) #[[ATTR1]] {
961 ; CHECK-NEXT: ret ptr addrspace(3) [[P]]
963 ret ptr addrspace(3) %p
967 define internal ptr @g2() {
968 ; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
969 ; CGSCC-LABEL: define {{[^@]+}}@g2
970 ; CGSCC-SAME: () #[[ATTR1]] {
971 ; CGSCC-NEXT: ret ptr inttoptr (i64 4 to ptr)
973 ret ptr inttoptr (i64 4 to ptr)
977 ; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
978 ; TUNIT-LABEL: define {{[^@]+}}@g1
979 ; TUNIT-SAME: () #[[ATTR1]] {
980 ; TUNIT-NEXT: ret ptr inttoptr (i64 4 to ptr)
982 ; CGSCC: Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
983 ; CGSCC-LABEL: define {{[^@]+}}@g1
984 ; CGSCC-SAME: () #[[ATTR10:[0-9]+]] {
985 ; CGSCC-NEXT: [[C:%.*]] = call noundef nonnull align 4 ptr @g2() #[[ATTR18:[0-9]+]]
986 ; CGSCC-NEXT: ret ptr [[C]]
992 declare void @use_i32_ptr(ptr readnone nocapture) nounwind
993 define internal void @called_by_weak(ptr %a) {
994 ; TUNIT: Function Attrs: nounwind
995 ; TUNIT-LABEL: define {{[^@]+}}@called_by_weak
996 ; TUNIT-SAME: (ptr noalias nocapture nofree nonnull readnone [[A:%.*]]) #[[ATTR5]] {
997 ; TUNIT-NEXT: call void @use_i32_ptr(ptr noalias nocapture nofree nonnull readnone [[A]]) #[[ATTR5]]
998 ; TUNIT-NEXT: ret void
1000 ; CGSCC: Function Attrs: nounwind
1001 ; CGSCC-LABEL: define {{[^@]+}}@called_by_weak
1002 ; CGSCC-SAME: (ptr noalias nocapture nofree nonnull readnone [[A:%.*]]) #[[ATTR4]] {
1003 ; CGSCC-NEXT: call void @use_i32_ptr(ptr noalias nocapture nofree nonnull readnone [[A]]) #[[ATTR4]]
1004 ; CGSCC-NEXT: ret void
1006 call void @use_i32_ptr(ptr %a)
1010 ; Check we do not annotate the function interface of this weak function.
1011 define weak_odr void @weak_caller(ptr nonnull %a) {
1013 ; TUNIT-LABEL: define {{[^@]+}}@weak_caller
1014 ; TUNIT-SAME: (ptr nonnull [[A:%.*]]) {
1015 ; TUNIT-NEXT: call void @called_by_weak(ptr noalias nocapture nofree nonnull readnone [[A]]) #[[ATTR5]]
1016 ; TUNIT-NEXT: ret void
1018 ; CGSCC-LABEL: define {{[^@]+}}@weak_caller
1019 ; CGSCC-SAME: (ptr nonnull [[A:%.*]]) {
1020 ; CGSCC-NEXT: call void @called_by_weak(ptr noalias nocapture nofree nonnull readnone [[A]]) #[[ATTR4]]
1021 ; CGSCC-NEXT: ret void
1023 call void @called_by_weak(ptr %a)
1028 define internal void @control(ptr dereferenceable(4) %a) {
1029 ; TUNIT: Function Attrs: nounwind
1030 ; TUNIT-LABEL: define {{[^@]+}}@control
1031 ; TUNIT-SAME: (ptr noalias nocapture nofree noundef nonnull readnone align 16 dereferenceable(8) [[A:%.*]]) #[[ATTR5]] {
1032 ; TUNIT-NEXT: call void @use_i32_ptr(ptr noalias nocapture nofree noundef nonnull readnone align 16 dereferenceable(8) [[A]]) #[[ATTR5]]
1033 ; TUNIT-NEXT: ret void
1035 ; CGSCC: Function Attrs: nounwind
1036 ; CGSCC-LABEL: define {{[^@]+}}@control
1037 ; CGSCC-SAME: (ptr noalias nocapture nofree noundef nonnull readnone align 16 dereferenceable(8) [[A:%.*]]) #[[ATTR4]] {
1038 ; CGSCC-NEXT: call void @use_i32_ptr(ptr noalias nocapture nofree noundef nonnull readnone align 16 dereferenceable(8) [[A]]) #[[ATTR4]]
1039 ; CGSCC-NEXT: ret void
1041 call void @use_i32_ptr(ptr %a)
1044 ; Avoid nonnull as we do not touch naked functions
1045 define internal void @naked(ptr dereferenceable(4) %a) naked {
1046 ; CHECK: Function Attrs: naked
1047 ; CHECK-LABEL: define {{[^@]+}}@naked
1048 ; CHECK-SAME: (ptr noundef nonnull dereferenceable(4) [[A:%.*]]) #[[ATTR11:[0-9]+]] {
1049 ; CHECK-NEXT: call void @use_i32_ptr(ptr nocapture nofree noundef nonnull [[A]])
1050 ; CHECK-NEXT: ret void
1052 call void @use_i32_ptr(ptr %a)
1055 ; Avoid nonnull as we do not touch optnone
1056 define internal void @optnone(ptr dereferenceable(4) %a) optnone noinline {
1058 ; CHECK: Function Attrs: noinline optnone
1059 ; CHECK-LABEL: define {{[^@]+}}@optnone
1060 ; CHECK-SAME: (ptr noundef nonnull dereferenceable(4) [[A:%.*]]) #[[ATTR12:[0-9]+]] {
1061 ; CHECK-NEXT: call void @use_i32_ptr(ptr nocapture nofree noundef nonnull [[A]])
1062 ; CHECK-NEXT: ret void
1064 call void @use_i32_ptr(ptr %a)
1067 define void @make_live(ptr nonnull dereferenceable(8) %a) {
1068 ; TUNIT-LABEL: define {{[^@]+}}@make_live
1069 ; TUNIT-SAME: (ptr noundef nonnull align 16 dereferenceable(8) [[A:%.*]]) {
1070 ; TUNIT-NEXT: call void @naked(ptr noundef nonnull align 16 dereferenceable(8) [[A]])
1071 ; TUNIT-NEXT: call void @control(ptr noalias nocapture nofree noundef nonnull readnone align 16 dereferenceable(8) [[A]]) #[[ATTR5]]
1072 ; TUNIT-NEXT: call void @optnone(ptr noundef nonnull align 16 dereferenceable(8) [[A]])
1073 ; TUNIT-NEXT: ret void
1075 ; CGSCC-LABEL: define {{[^@]+}}@make_live
1076 ; CGSCC-SAME: (ptr noundef nonnull align 16 dereferenceable(8) [[A:%.*]]) {
1077 ; CGSCC-NEXT: call void @naked(ptr noundef nonnull align 16 dereferenceable(8) [[A]])
1078 ; CGSCC-NEXT: call void @control(ptr noalias nocapture nofree noundef nonnull readnone align 16 dereferenceable(8) [[A]]) #[[ATTR4]]
1079 ; CGSCC-NEXT: call void @optnone(ptr noundef nonnull align 16 dereferenceable(8) [[A]])
1080 ; CGSCC-NEXT: ret void
1082 call void @naked(ptr nonnull dereferenceable(8) align 16 %a)
1083 call void @control(ptr nonnull dereferenceable(8) align 16 %a)
1084 call void @optnone(ptr nonnull dereferenceable(8) align 16 %a)
1089 ;int f(int *u, int n){
1090 ; for(int i = 0;i<n;i++){
1093 ; return g(nonnull u);
1095 declare void @h(ptr) willreturn nounwind
1096 declare i32 @g(ptr) willreturn nounwind
1097 define i32 @nonnull_exec_ctx_1(ptr %a, i32 %b) {
1099 ; TUNIT: Function Attrs: mustprogress nounwind willreturn
1100 ; TUNIT-LABEL: define {{[^@]+}}@nonnull_exec_ctx_1
1101 ; TUNIT-SAME: (ptr [[A:%.*]], i32 [[B:%.*]]) #[[ATTR8]] {
1103 ; TUNIT-NEXT: [[TRUETMP3:%.*]] = icmp eq i32 [[B]], 0
1104 ; TUNIT-NEXT: br i1 [[TRUETMP3]], label [[EX:%.*]], label [[HD:%.*]]
1106 ; TUNIT-NEXT: [[TRUETMP5:%.*]] = tail call i32 @g(ptr nonnull [[A]]) #[[ATTR7]]
1107 ; TUNIT-NEXT: ret i32 [[TRUETMP5]]
1109 ; TUNIT-NEXT: [[TRUETMP7:%.*]] = phi i32 [ [[TRUETMP8:%.*]], [[HD]] ], [ 0, [[EN:%.*]] ]
1110 ; TUNIT-NEXT: tail call void @h(ptr [[A]]) #[[ATTR7]]
1111 ; TUNIT-NEXT: [[TRUETMP8]] = add nuw i32 [[TRUETMP7]], 1
1112 ; TUNIT-NEXT: [[TRUETMP9:%.*]] = icmp eq i32 [[TRUETMP8]], [[B]]
1113 ; TUNIT-NEXT: br i1 [[TRUETMP9]], label [[EX]], label [[HD]]
1115 ; CGSCC: Function Attrs: mustprogress nounwind willreturn
1116 ; CGSCC-LABEL: define {{[^@]+}}@nonnull_exec_ctx_1
1117 ; CGSCC-SAME: (ptr [[A:%.*]], i32 [[B:%.*]]) #[[ATTR7]] {
1119 ; CGSCC-NEXT: [[TRUETMP3:%.*]] = icmp eq i32 [[B]], 0
1120 ; CGSCC-NEXT: br i1 [[TRUETMP3]], label [[EX:%.*]], label [[HD:%.*]]
1122 ; CGSCC-NEXT: [[TRUETMP5:%.*]] = tail call i32 @g(ptr nonnull [[A]]) #[[ATTR6]]
1123 ; CGSCC-NEXT: ret i32 [[TRUETMP5]]
1125 ; CGSCC-NEXT: [[TRUETMP7:%.*]] = phi i32 [ [[TRUETMP8:%.*]], [[HD]] ], [ 0, [[EN:%.*]] ]
1126 ; CGSCC-NEXT: tail call void @h(ptr [[A]]) #[[ATTR6]]
1127 ; CGSCC-NEXT: [[TRUETMP8]] = add nuw i32 [[TRUETMP7]], 1
1128 ; CGSCC-NEXT: [[TRUETMP9:%.*]] = icmp eq i32 [[TRUETMP8]], [[B]]
1129 ; CGSCC-NEXT: br i1 [[TRUETMP9]], label [[EX]], label [[HD]]
1132 %tmp3 = icmp eq i32 %b, 0
1133 br i1 %tmp3, label %ex, label %hd
1136 %tmp5 = tail call i32 @g(ptr nonnull %a)
1140 %tmp7 = phi i32 [ %tmp8, %hd ], [ 0, %en ]
1141 tail call void @h(ptr %a)
1142 %tmp8 = add nuw i32 %tmp7, 1
1143 %tmp9 = icmp eq i32 %tmp8, %b
1144 br i1 %tmp9, label %ex, label %hd
1147 define i32 @nonnull_exec_ctx_1b(ptr %a, i32 %b) {
1149 ; TUNIT: Function Attrs: mustprogress nounwind willreturn
1150 ; TUNIT-LABEL: define {{[^@]+}}@nonnull_exec_ctx_1b
1151 ; TUNIT-SAME: (ptr [[A:%.*]], i32 [[B:%.*]]) #[[ATTR8]] {
1153 ; TUNIT-NEXT: [[TRUETMP3:%.*]] = icmp eq i32 [[B]], 0
1154 ; TUNIT-NEXT: br i1 [[TRUETMP3]], label [[EX:%.*]], label [[HD:%.*]]
1156 ; TUNIT-NEXT: [[TRUETMP5:%.*]] = tail call i32 @g(ptr nonnull [[A]]) #[[ATTR7]]
1157 ; TUNIT-NEXT: ret i32 [[TRUETMP5]]
1159 ; TUNIT-NEXT: [[TRUETMP7:%.*]] = phi i32 [ [[TRUETMP8:%.*]], [[HD2:%.*]] ], [ 0, [[EN:%.*]] ]
1160 ; TUNIT-NEXT: tail call void @h(ptr [[A]]) #[[ATTR7]]
1161 ; TUNIT-NEXT: br label [[HD2]]
1163 ; TUNIT-NEXT: [[TRUETMP8]] = add nuw i32 [[TRUETMP7]], 1
1164 ; TUNIT-NEXT: [[TRUETMP9:%.*]] = icmp eq i32 [[TRUETMP8]], [[B]]
1165 ; TUNIT-NEXT: br i1 [[TRUETMP9]], label [[EX]], label [[HD]]
1167 ; CGSCC: Function Attrs: mustprogress nounwind willreturn
1168 ; CGSCC-LABEL: define {{[^@]+}}@nonnull_exec_ctx_1b
1169 ; CGSCC-SAME: (ptr [[A:%.*]], i32 [[B:%.*]]) #[[ATTR7]] {
1171 ; CGSCC-NEXT: [[TRUETMP3:%.*]] = icmp eq i32 [[B]], 0
1172 ; CGSCC-NEXT: br i1 [[TRUETMP3]], label [[EX:%.*]], label [[HD:%.*]]
1174 ; CGSCC-NEXT: [[TRUETMP5:%.*]] = tail call i32 @g(ptr nonnull [[A]]) #[[ATTR6]]
1175 ; CGSCC-NEXT: ret i32 [[TRUETMP5]]
1177 ; CGSCC-NEXT: [[TRUETMP7:%.*]] = phi i32 [ [[TRUETMP8:%.*]], [[HD2:%.*]] ], [ 0, [[EN:%.*]] ]
1178 ; CGSCC-NEXT: tail call void @h(ptr [[A]]) #[[ATTR6]]
1179 ; CGSCC-NEXT: br label [[HD2]]
1181 ; CGSCC-NEXT: [[TRUETMP8]] = add nuw i32 [[TRUETMP7]], 1
1182 ; CGSCC-NEXT: [[TRUETMP9:%.*]] = icmp eq i32 [[TRUETMP8]], [[B]]
1183 ; CGSCC-NEXT: br i1 [[TRUETMP9]], label [[EX]], label [[HD]]
1186 %tmp3 = icmp eq i32 %b, 0
1187 br i1 %tmp3, label %ex, label %hd
1190 %tmp5 = tail call i32 @g(ptr nonnull %a)
1194 %tmp7 = phi i32 [ %tmp8, %hd2 ], [ 0, %en ]
1195 tail call void @h(ptr %a)
1199 %tmp8 = add nuw i32 %tmp7, 1
1200 %tmp9 = icmp eq i32 %tmp8, %b
1201 br i1 %tmp9, label %ex, label %hd
1204 define i32 @nonnull_exec_ctx_2(ptr %a, i32 %b) willreturn nounwind {
1206 ; TUNIT: Function Attrs: mustprogress nounwind willreturn
1207 ; TUNIT-LABEL: define {{[^@]+}}@nonnull_exec_ctx_2
1208 ; TUNIT-SAME: (ptr nonnull [[A:%.*]], i32 [[B:%.*]]) #[[ATTR8]] {
1210 ; TUNIT-NEXT: [[TRUETMP3:%.*]] = icmp eq i32 [[B]], 0
1211 ; TUNIT-NEXT: br i1 [[TRUETMP3]], label [[EX:%.*]], label [[HD:%.*]]
1213 ; TUNIT-NEXT: [[TRUETMP5:%.*]] = tail call i32 @g(ptr nonnull [[A]]) #[[ATTR5]]
1214 ; TUNIT-NEXT: ret i32 [[TRUETMP5]]
1216 ; TUNIT-NEXT: [[TRUETMP7:%.*]] = phi i32 [ [[TRUETMP8:%.*]], [[HD]] ], [ 0, [[EN:%.*]] ]
1217 ; TUNIT-NEXT: tail call void @h(ptr nonnull [[A]]) #[[ATTR5]]
1218 ; TUNIT-NEXT: [[TRUETMP8]] = add nuw i32 [[TRUETMP7]], 1
1219 ; TUNIT-NEXT: [[TRUETMP9:%.*]] = icmp eq i32 [[TRUETMP8]], [[B]]
1220 ; TUNIT-NEXT: br i1 [[TRUETMP9]], label [[EX]], label [[HD]]
1222 ; CGSCC: Function Attrs: mustprogress nounwind willreturn
1223 ; CGSCC-LABEL: define {{[^@]+}}@nonnull_exec_ctx_2
1224 ; CGSCC-SAME: (ptr nonnull [[A:%.*]], i32 [[B:%.*]]) #[[ATTR7]] {
1226 ; CGSCC-NEXT: [[TRUETMP3:%.*]] = icmp eq i32 [[B]], 0
1227 ; CGSCC-NEXT: br i1 [[TRUETMP3]], label [[EX:%.*]], label [[HD:%.*]]
1229 ; CGSCC-NEXT: [[TRUETMP5:%.*]] = tail call i32 @g(ptr nonnull [[A]]) #[[ATTR4]]
1230 ; CGSCC-NEXT: ret i32 [[TRUETMP5]]
1232 ; CGSCC-NEXT: [[TRUETMP7:%.*]] = phi i32 [ [[TRUETMP8:%.*]], [[HD]] ], [ 0, [[EN:%.*]] ]
1233 ; CGSCC-NEXT: tail call void @h(ptr nonnull [[A]]) #[[ATTR4]]
1234 ; CGSCC-NEXT: [[TRUETMP8]] = add nuw i32 [[TRUETMP7]], 1
1235 ; CGSCC-NEXT: [[TRUETMP9:%.*]] = icmp eq i32 [[TRUETMP8]], [[B]]
1236 ; CGSCC-NEXT: br i1 [[TRUETMP9]], label [[EX]], label [[HD]]
1239 %tmp3 = icmp eq i32 %b, 0
1240 br i1 %tmp3, label %ex, label %hd
1243 %tmp5 = tail call i32 @g(ptr nonnull %a)
1247 %tmp7 = phi i32 [ %tmp8, %hd ], [ 0, %en ]
1248 tail call void @h(ptr %a)
1249 %tmp8 = add nuw i32 %tmp7, 1
1250 %tmp9 = icmp eq i32 %tmp8, %b
1251 br i1 %tmp9, label %ex, label %hd
1254 define i32 @nonnull_exec_ctx_2b(ptr %a, i32 %b) willreturn nounwind {
1256 ; TUNIT: Function Attrs: mustprogress nounwind willreturn
1257 ; TUNIT-LABEL: define {{[^@]+}}@nonnull_exec_ctx_2b
1258 ; TUNIT-SAME: (ptr nonnull [[A:%.*]], i32 [[B:%.*]]) #[[ATTR8]] {
1260 ; TUNIT-NEXT: [[TRUETMP3:%.*]] = icmp eq i32 [[B]], 0
1261 ; TUNIT-NEXT: br i1 [[TRUETMP3]], label [[EX:%.*]], label [[HD:%.*]]
1263 ; TUNIT-NEXT: [[TRUETMP5:%.*]] = tail call i32 @g(ptr nonnull [[A]]) #[[ATTR5]]
1264 ; TUNIT-NEXT: ret i32 [[TRUETMP5]]
1266 ; TUNIT-NEXT: [[TRUETMP7:%.*]] = phi i32 [ [[TRUETMP8:%.*]], [[HD2:%.*]] ], [ 0, [[EN:%.*]] ]
1267 ; TUNIT-NEXT: tail call void @h(ptr nonnull [[A]]) #[[ATTR5]]
1268 ; TUNIT-NEXT: br label [[HD2]]
1270 ; TUNIT-NEXT: [[TRUETMP8]] = add nuw i32 [[TRUETMP7]], 1
1271 ; TUNIT-NEXT: [[TRUETMP9:%.*]] = icmp eq i32 [[TRUETMP8]], [[B]]
1272 ; TUNIT-NEXT: br i1 [[TRUETMP9]], label [[EX]], label [[HD]]
1274 ; CGSCC: Function Attrs: mustprogress nounwind willreturn
1275 ; CGSCC-LABEL: define {{[^@]+}}@nonnull_exec_ctx_2b
1276 ; CGSCC-SAME: (ptr nonnull [[A:%.*]], i32 [[B:%.*]]) #[[ATTR7]] {
1278 ; CGSCC-NEXT: [[TRUETMP3:%.*]] = icmp eq i32 [[B]], 0
1279 ; CGSCC-NEXT: br i1 [[TRUETMP3]], label [[EX:%.*]], label [[HD:%.*]]
1281 ; CGSCC-NEXT: [[TRUETMP5:%.*]] = tail call i32 @g(ptr nonnull [[A]]) #[[ATTR4]]
1282 ; CGSCC-NEXT: ret i32 [[TRUETMP5]]
1284 ; CGSCC-NEXT: [[TRUETMP7:%.*]] = phi i32 [ [[TRUETMP8:%.*]], [[HD2:%.*]] ], [ 0, [[EN:%.*]] ]
1285 ; CGSCC-NEXT: tail call void @h(ptr nonnull [[A]]) #[[ATTR4]]
1286 ; CGSCC-NEXT: br label [[HD2]]
1288 ; CGSCC-NEXT: [[TRUETMP8]] = add nuw i32 [[TRUETMP7]], 1
1289 ; CGSCC-NEXT: [[TRUETMP9:%.*]] = icmp eq i32 [[TRUETMP8]], [[B]]
1290 ; CGSCC-NEXT: br i1 [[TRUETMP9]], label [[EX]], label [[HD]]
1293 %tmp3 = icmp eq i32 %b, 0
1294 br i1 %tmp3, label %ex, label %hd
1297 %tmp5 = tail call i32 @g(ptr nonnull %a)
1301 %tmp7 = phi i32 [ %tmp8, %hd2 ], [ 0, %en ]
1302 tail call void @h(ptr %a)
1306 %tmp8 = add nuw i32 %tmp7, 1
1307 %tmp9 = icmp eq i32 %tmp8, %b
1308 br i1 %tmp9, label %ex, label %hd
1311 ; Original from PR43833
1312 declare void @sink(ptr)
1314 define void @PR43833(ptr %0, i32 %1) {
1315 ; CHECK-LABEL: define {{[^@]+}}@PR43833
1316 ; CHECK-SAME: (ptr [[TMP0:%.*]], i32 [[TMP1:%.*]]) {
1317 ; CHECK-NEXT: [[TMP3:%.*]] = icmp sgt i32 [[TMP1]], 1
1318 ; CHECK-NEXT: br i1 [[TMP3]], label [[TMP4:%.*]], label [[TMP7:%.*]]
1320 ; CHECK-NEXT: [[TMP5:%.*]] = zext i32 [[TMP1]] to i64
1321 ; CHECK-NEXT: [[TMP6:%.*]] = getelementptr inbounds i32, ptr [[TMP0]], i64 [[TMP5]]
1322 ; CHECK-NEXT: br label [[TMP8:%.*]]
1324 ; CHECK-NEXT: ret void
1326 ; CHECK-NEXT: [[TMP9:%.*]] = phi i32 [ 1, [[TMP4]] ], [ [[TMP10:%.*]], [[TMP8]] ]
1327 ; CHECK-NEXT: tail call void @sink(ptr nonnull [[TMP6]])
1328 ; CHECK-NEXT: [[TMP10]] = add nuw nsw i32 [[TMP9]], 1
1329 ; CHECK-NEXT: [[TMP11:%.*]] = icmp eq i32 [[TMP10]], [[TMP1]]
1330 ; CHECK-NEXT: br i1 [[TMP11]], label [[TMP7]], label [[TMP8]]
1332 %3 = icmp sgt i32 %1, 1
1333 br i1 %3, label %4, label %7
1336 %5 = zext i32 %1 to i64
1337 %6 = getelementptr inbounds i32, ptr %0, i64 %5
1344 %9 = phi i32 [ 1, %4 ], [ %10, %8 ]
1345 tail call void @sink(ptr %6)
1346 %10 = add nuw nsw i32 %9, 1
1347 %11 = icmp eq i32 %10, %1
1348 br i1 %11, label %7, label %8
1351 ; Adjusted from PR43833
1352 define void @PR43833_simple(ptr %0, i32 %1) {
1353 ; CHECK-LABEL: define {{[^@]+}}@PR43833_simple
1354 ; CHECK-SAME: (ptr [[TMP0:%.*]], i32 [[TMP1:%.*]]) {
1355 ; CHECK-NEXT: [[TMP3:%.*]] = icmp ne i32 [[TMP1]], 0
1356 ; CHECK-NEXT: br i1 [[TMP3]], label [[TMP4:%.*]], label [[TMP7:%.*]]
1358 ; CHECK-NEXT: [[TMP5:%.*]] = zext i32 [[TMP1]] to i64
1359 ; CHECK-NEXT: [[TMP6:%.*]] = getelementptr inbounds i32, ptr [[TMP0]], i64 [[TMP5]]
1360 ; CHECK-NEXT: br label [[TMP8:%.*]]
1362 ; CHECK-NEXT: ret void
1364 ; CHECK-NEXT: [[TMP9:%.*]] = phi i32 [ 1, [[TMP4]] ], [ [[TMP10:%.*]], [[TMP8]] ]
1365 ; CHECK-NEXT: tail call void @sink(ptr nonnull [[TMP6]])
1366 ; CHECK-NEXT: [[TMP10]] = add nuw nsw i32 [[TMP9]], 1
1367 ; CHECK-NEXT: [[TMP11:%.*]] = icmp eq i32 [[TMP10]], [[TMP1]]
1368 ; CHECK-NEXT: br i1 [[TMP11]], label [[TMP7]], label [[TMP8]]
1370 %3 = icmp ne i32 %1, 0
1371 br i1 %3, label %4, label %7
1374 %5 = zext i32 %1 to i64
1375 %6 = getelementptr inbounds i32, ptr %0, i64 %5
1382 %9 = phi i32 [ 1, %4 ], [ %10, %8 ]
1383 tail call void @sink(ptr %6)
1384 %10 = add nuw nsw i32 %9, 1
1385 %11 = icmp eq i32 %10, %1
1386 br i1 %11, label %7, label %8
1389 declare ptr @strrchr(ptr %0, i32 %1) nofree nounwind readonly willreturn
1391 ; We should not mark the return of @strrchr as `nonnull`, it may well be NULL!
1392 define ptr @mybasename(ptr nofree readonly %str) {
1393 ; TUNIT: Function Attrs: mustprogress nofree nosync nounwind willreturn memory(read)
1394 ; TUNIT-LABEL: define {{[^@]+}}@mybasename
1395 ; TUNIT-SAME: (ptr nofree readonly [[STR:%.*]]) #[[ATTR14:[0-9]+]] {
1396 ; TUNIT-NEXT: [[CALL:%.*]] = call ptr @strrchr(ptr nofree readonly [[STR]], i32 noundef 47) #[[ATTR18:[0-9]+]]
1397 ; TUNIT-NEXT: [[TOBOOL:%.*]] = icmp ne ptr [[CALL]], null
1398 ; TUNIT-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds i8, ptr [[CALL]], i64 1
1399 ; TUNIT-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], ptr [[ADD_PTR]], ptr [[STR]]
1400 ; TUNIT-NEXT: ret ptr [[COND]]
1402 ; CGSCC: Function Attrs: mustprogress nofree nosync nounwind willreturn memory(read)
1403 ; CGSCC-LABEL: define {{[^@]+}}@mybasename
1404 ; CGSCC-SAME: (ptr nofree readonly [[STR:%.*]]) #[[ATTR14:[0-9]+]] {
1405 ; CGSCC-NEXT: [[CALL:%.*]] = call ptr @strrchr(ptr nofree readonly [[STR]], i32 noundef 47) #[[ATTR19:[0-9]+]]
1406 ; CGSCC-NEXT: [[TOBOOL:%.*]] = icmp ne ptr [[CALL]], null
1407 ; CGSCC-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds i8, ptr [[CALL]], i64 1
1408 ; CGSCC-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], ptr [[ADD_PTR]], ptr [[STR]]
1409 ; CGSCC-NEXT: ret ptr [[COND]]
1411 %call = call ptr @strrchr(ptr %str, i32 47)
1412 %tobool = icmp ne ptr %call, null
1413 %add.ptr = getelementptr inbounds i8, ptr %call, i64 1
1414 %cond = select i1 %tobool, ptr %add.ptr, ptr %str
1418 define void @nonnull_assume_pos(ptr %arg) {
1419 ; ATTRIBUTOR-LABEL: define {{[^@]+}}@nonnull_assume_pos
1420 ; ATTRIBUTOR-SAME: (ptr nocapture nofree nonnull readnone [[ARG:%.*]])
1421 ; ATTRIBUTOR-NEXT: call void @llvm.assume(i1 true) #11 [ "nonnull"(ptr [[ARG]]) ]
1422 ; ATTRIBUTOR-NEXT: call void @use_i8_ptr(ptr noalias nocapture nofree nonnull readnone [[ARG]])
1423 ; ATTRIBUTOR-NEXT: [[TMP1:%.*]] = call ptr @unknown()
1424 ; ATTRIBUTOR-NEXT: ret void
1426 ; TUNIT-LABEL: define {{[^@]+}}@nonnull_assume_pos
1427 ; TUNIT-SAME: (ptr nocapture nofree nonnull readnone [[ARG:%.*]]) {
1428 ; TUNIT-NEXT: call void @llvm.assume(i1 noundef true) #[[ATTR15]] [ "nonnull"(ptr [[ARG]]) ]
1429 ; TUNIT-NEXT: call void @use_i8_ptr(ptr noalias nocapture nofree nonnull readnone [[ARG]]) #[[ATTR5]]
1430 ; TUNIT-NEXT: [[TMP1:%.*]] = call ptr @unknown()
1431 ; TUNIT-NEXT: ret void
1433 ; CGSCC-LABEL: define {{[^@]+}}@nonnull_assume_pos
1434 ; CGSCC-SAME: (ptr nocapture nofree nonnull readnone [[ARG:%.*]]) {
1435 ; CGSCC-NEXT: call void @llvm.assume(i1 noundef true) #[[ATTR15]] [ "nonnull"(ptr [[ARG]]) ]
1436 ; CGSCC-NEXT: call void @use_i8_ptr(ptr noalias nocapture nofree nonnull readnone [[ARG]]) #[[ATTR4]]
1437 ; CGSCC-NEXT: [[TMP1:%.*]] = call ptr @unknown()
1438 ; CGSCC-NEXT: ret void
1440 call void @llvm.assume(i1 true) ["nonnull"(ptr %arg)]
1441 call void @use_i8_ptr(ptr %arg)
1445 define void @nonnull_assume_neg(ptr %arg) {
1446 ; ATTRIBUTOR-LABEL: define {{[^@]+}}@nonnull_assume_neg
1447 ; ATTRIBUTOR-SAME: (ptr nocapture nofree readnone [[ARG:%.*]])
1448 ; ATTRIBUTOR-NEXT: [[TMP1:%.*]] = call ptr @unknown()
1449 ; ATTRIBUTOR-NEXT: call void @use_i8_ptr(ptr noalias nocapture nofree readnone [[ARG]])
1450 ; ATTRIBUTOR-NEXT: call void @llvm.assume(i1 true) [ "nonnull"(ptr [[ARG]]) ]
1451 ; ATTRIBUTOR-NEXT: call void @use_i8_ptr(ptr noalias nocapture nofree nonnull readnone [[ARG]])
1452 ; ATTRIBUTOR-NEXT: [[TMP2:%.*]] = call ptr @unknown()
1453 ; ATTRIBUTOR-NEXT: call void @use_i8_ptr_ret(ptr noalias nocapture nofree nonnull readnone [[ARG]])
1454 ; ATTRIBUTOR-NEXT: call void @llvm.assume(i1 true) [ "nonnull"(ptr [[ARG]]) ]
1455 ; ATTRIBUTOR-NEXT: call void @use_i8_ptr_ret(ptr noalias nocapture nofree nonnull readnone [[ARG]])
1456 ; ATTRIBUTOR-NEXT: ret void
1459 ; TUNIT-LABEL: define {{[^@]+}}@nonnull_assume_neg
1460 ; TUNIT-SAME: (ptr nocapture nofree readnone [[ARG:%.*]]) {
1461 ; TUNIT-NEXT: [[TMP1:%.*]] = call ptr @unknown()
1462 ; TUNIT-NEXT: call void @use_i8_ptr(ptr noalias nocapture nofree readnone [[ARG]]) #[[ATTR5]]
1463 ; TUNIT-NEXT: call void @llvm.assume(i1 noundef true) [ "nonnull"(ptr [[ARG]]) ]
1464 ; TUNIT-NEXT: call void @use_i8_ptr(ptr noalias nocapture nofree nonnull readnone [[ARG]]) #[[ATTR5]]
1465 ; TUNIT-NEXT: [[TMP2:%.*]] = call ptr @unknown()
1466 ; TUNIT-NEXT: call void @use_i8_ptr_ret(ptr noalias nocapture nofree nonnull readnone [[ARG]]) #[[ATTR5]]
1467 ; TUNIT-NEXT: call void @llvm.assume(i1 noundef true) [ "nonnull"(ptr [[ARG]]) ]
1468 ; TUNIT-NEXT: call void @use_i8_ptr_ret(ptr noalias nocapture nofree nonnull readnone [[ARG]]) #[[ATTR5]]
1469 ; TUNIT-NEXT: ret void
1471 ; CGSCC-LABEL: define {{[^@]+}}@nonnull_assume_neg
1472 ; CGSCC-SAME: (ptr nocapture nofree readnone [[ARG:%.*]]) {
1473 ; CGSCC-NEXT: [[TMP1:%.*]] = call ptr @unknown()
1474 ; CGSCC-NEXT: call void @use_i8_ptr(ptr noalias nocapture nofree readnone [[ARG]]) #[[ATTR4]]
1475 ; CGSCC-NEXT: call void @llvm.assume(i1 noundef true) [ "nonnull"(ptr [[ARG]]) ]
1476 ; CGSCC-NEXT: call void @use_i8_ptr(ptr noalias nocapture nofree nonnull readnone [[ARG]]) #[[ATTR4]]
1477 ; CGSCC-NEXT: [[TMP2:%.*]] = call ptr @unknown()
1478 ; CGSCC-NEXT: call void @use_i8_ptr_ret(ptr noalias nocapture nofree nonnull readnone [[ARG]]) #[[ATTR4]]
1479 ; CGSCC-NEXT: call void @llvm.assume(i1 noundef true) [ "nonnull"(ptr [[ARG]]) ]
1480 ; CGSCC-NEXT: call void @use_i8_ptr_ret(ptr noalias nocapture nofree nonnull readnone [[ARG]]) #[[ATTR4]]
1481 ; CGSCC-NEXT: ret void
1484 call void @use_i8_ptr(ptr %arg)
1485 call void @llvm.assume(i1 true) ["nonnull"(ptr %arg)]
1486 call void @use_i8_ptr(ptr %arg)
1488 call void @use_i8_ptr_ret(ptr %arg)
1489 call void @llvm.assume(i1 true) ["nonnull"(ptr %arg)]
1490 call void @use_i8_ptr_ret(ptr %arg)
1493 declare void @use_i8_ptr(ptr nofree nocapture readnone) nounwind
1494 declare void @use_i8_ptr_ret(ptr nofree nocapture readnone) nounwind willreturn
1496 define ptr @nonnull_function_ptr_1() {
1497 ; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
1498 ; CHECK-LABEL: define {{[^@]+}}@nonnull_function_ptr_1
1499 ; CHECK-SAME: () #[[ATTR1]] {
1500 ; CHECK-NEXT: ret ptr @nonnull_function_ptr_1
1502 ret ptr @nonnull_function_ptr_1
1505 declare ptr @function_decl()
1506 define ptr @nonnull_function_ptr_2() {
1507 ; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
1508 ; CHECK-LABEL: define {{[^@]+}}@nonnull_function_ptr_2
1509 ; CHECK-SAME: () #[[ATTR1]] {
1510 ; CHECK-NEXT: ret ptr @function_decl
1512 ret ptr @function_decl
1515 ; FIXME: nonnull should not be propagated to the caller's p unless there is noundef
1516 define void @nonnull_caller(ptr %p) {
1517 ; CHECK-LABEL: define {{[^@]+}}@nonnull_caller
1518 ; CHECK-SAME: (ptr nonnull [[P:%.*]]) {
1519 ; CHECK-NEXT: call void @nonnull_callee(ptr nonnull [[P]])
1520 ; CHECK-NEXT: ret void
1522 call void @nonnull_callee(ptr %p)
1525 declare void @nonnull_callee(ptr nonnull %p)
1527 define ptr @phi(ptr %p) {
1528 ; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
1529 ; CHECK-LABEL: define {{[^@]+}}@phi
1530 ; CHECK-SAME: (ptr nofree readnone [[P:%.*]]) #[[ATTR1]] {
1531 ; CHECK-NEXT: [[C:%.*]] = icmp eq ptr [[P]], null
1532 ; CHECK-NEXT: [[G:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 1
1533 ; CHECK-NEXT: br i1 [[C]], label [[NULL:%.*]], label [[NNULL:%.*]]
1535 ; CHECK-NEXT: br label [[MERGE:%.*]]
1537 ; CHECK-NEXT: br label [[MERGE]]
1539 ; CHECK-NEXT: [[PHI:%.*]] = phi ptr [ [[P]], [[NNULL]] ], [ [[G]], [[NULL]] ]
1540 ; CHECK-NEXT: ret ptr [[PHI]]
1542 %c = icmp eq ptr %p, null
1543 %g = getelementptr inbounds i8, ptr %p, i64 1
1544 br i1 %c, label %NULL, label %NNULL
1550 %phi = phi ptr [%p, %NNULL], [%g, %NULL]
1553 define void @phi_caller(ptr %p) {
1554 ; TUNIT: Function Attrs: nounwind
1555 ; TUNIT-LABEL: define {{[^@]+}}@phi_caller
1556 ; TUNIT-SAME: (ptr nofree [[P:%.*]]) #[[ATTR5]] {
1557 ; TUNIT-NEXT: [[C:%.*]] = call nonnull ptr @phi(ptr noalias nofree readnone [[P]]) #[[ATTR19:[0-9]+]]
1558 ; TUNIT-NEXT: call void @use_i8_ptr(ptr noalias nocapture nofree nonnull readnone [[C]]) #[[ATTR5]]
1559 ; TUNIT-NEXT: ret void
1561 ; CGSCC: Function Attrs: nounwind
1562 ; CGSCC-LABEL: define {{[^@]+}}@phi_caller
1563 ; CGSCC-SAME: (ptr nofree [[P:%.*]]) #[[ATTR4]] {
1564 ; CGSCC-NEXT: [[C:%.*]] = call nonnull ptr @phi(ptr noalias nofree readnone [[P]]) #[[ATTR20:[0-9]+]]
1565 ; CGSCC-NEXT: call void @use_i8_ptr(ptr noalias nocapture nofree nonnull readnone [[C]]) #[[ATTR4]]
1566 ; CGSCC-NEXT: ret void
1568 %c = call ptr @phi(ptr %p)
1569 call void @use_i8_ptr(ptr %c)
1573 define ptr @multi_ret(ptr %p) {
1574 ; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
1575 ; CHECK-LABEL: define {{[^@]+}}@multi_ret
1576 ; CHECK-SAME: (ptr nofree readnone [[P:%.*]]) #[[ATTR1]] {
1577 ; CHECK-NEXT: [[C:%.*]] = icmp eq ptr [[P]], null
1578 ; CHECK-NEXT: br i1 [[C]], label [[NULL:%.*]], label [[NNULL:%.*]]
1580 ; CHECK-NEXT: ret ptr [[P]]
1582 ; CHECK-NEXT: [[G:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 1
1583 ; CHECK-NEXT: ret ptr [[G]]
1585 %c = icmp eq ptr %p, null
1586 br i1 %c, label %NULL, label %NNULL
1590 %g = getelementptr inbounds i8, ptr %p, i64 1
1593 define void @multi_ret_caller(ptr %p) {
1594 ; TUNIT: Function Attrs: nounwind
1595 ; TUNIT-LABEL: define {{[^@]+}}@multi_ret_caller
1596 ; TUNIT-SAME: (ptr nofree [[P:%.*]]) #[[ATTR5]] {
1597 ; TUNIT-NEXT: [[C:%.*]] = call nonnull ptr @multi_ret(ptr noalias nofree readnone [[P]]) #[[ATTR19]]
1598 ; TUNIT-NEXT: call void @use_i8_ptr(ptr noalias nocapture nofree nonnull readnone [[C]]) #[[ATTR5]]
1599 ; TUNIT-NEXT: ret void
1601 ; CGSCC: Function Attrs: nounwind
1602 ; CGSCC-LABEL: define {{[^@]+}}@multi_ret_caller
1603 ; CGSCC-SAME: (ptr nofree [[P:%.*]]) #[[ATTR4]] {
1604 ; CGSCC-NEXT: [[C:%.*]] = call nonnull ptr @multi_ret(ptr noalias nofree readnone [[P]]) #[[ATTR20]]
1605 ; CGSCC-NEXT: call void @use_i8_ptr(ptr noalias nocapture nofree nonnull readnone [[C]]) #[[ATTR4]]
1606 ; CGSCC-NEXT: ret void
1608 %c = call ptr @multi_ret(ptr %p)
1609 call void @use_i8_ptr(ptr %c)
1613 attributes #0 = { null_pointer_is_valid }
1614 attributes #1 = { nounwind willreturn}
1616 ; TUNIT: attributes #[[ATTR0:[0-9]+]] = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }
1617 ; TUNIT: attributes #[[ATTR1]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) }
1618 ; TUNIT: attributes #[[ATTR2]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(inaccessiblemem: write) }
1619 ; TUNIT: attributes #[[ATTR3]] = { mustprogress nofree nosync nounwind willreturn memory(none) }
1620 ; TUNIT: attributes #[[ATTR4]] = { noreturn }
1621 ; TUNIT: attributes #[[ATTR5]] = { nounwind }
1622 ; TUNIT: attributes #[[ATTR6]] = { nofree nosync nounwind memory(argmem: read) }
1623 ; TUNIT: attributes #[[ATTR7]] = { nounwind willreturn }
1624 ; TUNIT: attributes #[[ATTR8]] = { mustprogress nounwind willreturn }
1625 ; TUNIT: attributes #[[ATTR9:[0-9]+]] = { nounwind willreturn memory(read) }
1626 ; TUNIT: attributes #[[ATTR10]] = { mustprogress nofree norecurse nosync nounwind null_pointer_is_valid willreturn memory(none) }
1627 ; TUNIT: attributes #[[ATTR11]] = { naked }
1628 ; TUNIT: attributes #[[ATTR12]] = { noinline optnone }
1629 ; TUNIT: attributes #[[ATTR13:[0-9]+]] = { nofree nounwind willreturn memory(read) }
1630 ; TUNIT: attributes #[[ATTR14]] = { mustprogress nofree nosync nounwind willreturn memory(read) }
1631 ; TUNIT: attributes #[[ATTR15]] = { nofree willreturn memory(write) }
1632 ; TUNIT: attributes #[[ATTR16]] = { nofree nosync nounwind memory(read) }
1633 ; TUNIT: attributes #[[ATTR17]] = { nosync willreturn memory(read) }
1634 ; TUNIT: attributes #[[ATTR18]] = { nofree nosync willreturn memory(read) }
1635 ; TUNIT: attributes #[[ATTR19]] = { nofree nosync nounwind willreturn memory(none) }
1637 ; CGSCC: attributes #[[ATTR0:[0-9]+]] = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }
1638 ; CGSCC: attributes #[[ATTR1]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) }
1639 ; CGSCC: attributes #[[ATTR2]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(inaccessiblemem: write) }
1640 ; CGSCC: attributes #[[ATTR3]] = { noreturn }
1641 ; CGSCC: attributes #[[ATTR4]] = { nounwind }
1642 ; CGSCC: attributes #[[ATTR5]] = { nofree nosync nounwind memory(argmem: read) }
1643 ; CGSCC: attributes #[[ATTR6]] = { nounwind willreturn }
1644 ; CGSCC: attributes #[[ATTR7]] = { mustprogress nounwind willreturn }
1645 ; CGSCC: attributes #[[ATTR8:[0-9]+]] = { nounwind willreturn memory(read) }
1646 ; CGSCC: attributes #[[ATTR9]] = { mustprogress nofree norecurse nosync nounwind null_pointer_is_valid willreturn memory(none) }
1647 ; CGSCC: attributes #[[ATTR10]] = { mustprogress nofree nosync nounwind willreturn memory(none) }
1648 ; CGSCC: attributes #[[ATTR11]] = { naked }
1649 ; CGSCC: attributes #[[ATTR12]] = { noinline optnone }
1650 ; CGSCC: attributes #[[ATTR13:[0-9]+]] = { nofree nounwind willreturn memory(read) }
1651 ; CGSCC: attributes #[[ATTR14]] = { mustprogress nofree nosync nounwind willreturn memory(read) }
1652 ; CGSCC: attributes #[[ATTR15]] = { nofree willreturn memory(write) }
1653 ; CGSCC: attributes #[[ATTR16]] = { nofree nosync nounwind memory(read) }
1654 ; CGSCC: attributes #[[ATTR17]] = { nosync willreturn memory(read) }
1655 ; CGSCC: attributes #[[ATTR18]] = { nofree nosync willreturn }
1656 ; CGSCC: attributes #[[ATTR19]] = { nofree nosync willreturn memory(read) }
1657 ; CGSCC: attributes #[[ATTR20]] = { nofree willreturn }