1 ; RUN: opt -attributor -attributor-manifest-internal --attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=1 -S < %s | FileCheck %s --check-prefixes=ATTRIBUTOR
4 declare void @deref_phi_user(i32* %a);
7 ; take mininimum of return values
9 define i32* @test1(i32* dereferenceable(4) %0, double* dereferenceable(8) %1, i1 zeroext %2) local_unnamed_addr {
10 ; ATTRIBUTOR: define nonnull dereferenceable(4) i32* @test1(i32* nonnull dereferenceable(4) "no-capture-maybe-returned" %0, double* nonnull dereferenceable(8) "no-capture-maybe-returned" %1, i1 zeroext %2)
11 %4 = bitcast double* %1 to i32*
12 %5 = select i1 %2, i32* %0, i32* %4
17 define i32* @test2(i32* dereferenceable_or_null(4) %0, double* dereferenceable(8) %1, i1 zeroext %2) local_unnamed_addr {
18 ; ATTRIBUTOR: define dereferenceable_or_null(4) i32* @test2(i32* dereferenceable_or_null(4) "no-capture-maybe-returned" %0, double* nonnull dereferenceable(8) "no-capture-maybe-returned" %1, i1 zeroext %2)
19 %4 = bitcast double* %1 to i32*
20 %5 = select i1 %2, i32* %0, i32* %4
26 define i32* @test3_1(i32* dereferenceable(8) %0) local_unnamed_addr {
27 ; ATTRIBUTOR: define nonnull dereferenceable(4) i32* @test3_1(i32* nonnull dereferenceable(8) "no-capture-maybe-returned" %0)
28 %ret = getelementptr inbounds i32, i32* %0, i64 1
32 define i32* @test3_2(i32* dereferenceable_or_null(32) %0) local_unnamed_addr {
33 ; FIXME: Argument should be mark dereferenceable because of GEP `inbounds`.
34 ; ATTRIBUTOR: define nonnull dereferenceable(16) i32* @test3_2(i32* dereferenceable_or_null(32) "no-capture-maybe-returned" %0)
35 %ret = getelementptr inbounds i32, i32* %0, i64 4
39 define i32* @test3_3(i32* dereferenceable(8) %0, i32* dereferenceable(16) %1, i1 %2) local_unnamed_addr {
40 ; ATTRIBUTOR: define nonnull dereferenceable(4) i32* @test3_3(i32* nonnull dereferenceable(8) "no-capture-maybe-returned" %0, i32* nonnull dereferenceable(16) "no-capture-maybe-returned" %1, i1 %2) local_unnamed_addr
41 %ret1 = getelementptr inbounds i32, i32* %0, i64 1
42 %ret2 = getelementptr inbounds i32, i32* %1, i64 2
43 %ret = select i1 %2, i32* %ret1, i32* %ret2
48 ; Better than known in IR.
50 define dereferenceable(4) i32* @test4(i32* dereferenceable(8) %0) local_unnamed_addr {
51 ; ATTRIBUTOR: define nonnull dereferenceable(8) i32* @test4(i32* nonnull returned dereferenceable(8) "no-capture-maybe-returned" %0)
56 ; loop in which dereferenceabily "grows"
57 define void @deref_phi_growing(i32* dereferenceable(4000) %a) {
61 for.cond: ; preds = %for.inc, %entry
62 %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
63 %a.addr.0 = phi i32* [ %a, %entry ], [ %incdec.ptr, %for.inc ]
64 ; CHECK: call void @deref_phi_user(i32* dereferenceable(4000) %a.addr.0)
65 call void @deref_phi_user(i32* %a.addr.0)
66 %tmp = load i32, i32* %a.addr.0, align 4
67 %cmp = icmp slt i32 %i.0, %tmp
68 br i1 %cmp, label %for.body, label %for.cond.cleanup
70 for.cond.cleanup: ; preds = %for.cond
73 for.body: ; preds = %for.cond
76 for.inc: ; preds = %for.body
77 %incdec.ptr = getelementptr inbounds i32, i32* %a.addr.0, i64 -1
78 %inc = add nuw nsw i32 %i.0, 1
81 for.end: ; preds = %for.cond.cleanup
86 ; loop in which dereferenceabily "shrinks"
87 define void @deref_phi_shrinking(i32* dereferenceable(4000) %a) {
91 for.cond: ; preds = %for.inc, %entry
92 %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
93 %a.addr.0 = phi i32* [ %a, %entry ], [ %incdec.ptr, %for.inc ]
94 ; CHECK: call void @deref_phi_user(i32* %a.addr.0)
95 call void @deref_phi_user(i32* %a.addr.0)
96 %tmp = load i32, i32* %a.addr.0, align 4
97 %cmp = icmp slt i32 %i.0, %tmp
98 br i1 %cmp, label %for.body, label %for.cond.cleanup
100 for.cond.cleanup: ; preds = %for.cond
103 for.body: ; preds = %for.cond
106 for.inc: ; preds = %for.body
107 %incdec.ptr = getelementptr inbounds i32, i32* %a.addr.0, i64 1
108 %inc = add nuw nsw i32 %i.0, 1
111 for.end: ; preds = %for.cond.cleanup