1 ; RUN: opt -attributor -attributor-manifest-internal --attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=2 -S < %s | FileCheck %s --check-prefix=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 readnone dereferenceable(4) "no-capture-maybe-returned" %0, double* nonnull readnone 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* readnone dereferenceable_or_null(4) "no-capture-maybe-returned" %0, double* nonnull readnone 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 readnone 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* readnone 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 readnone dereferenceable(8) "no-capture-maybe-returned" %0, i32* nonnull readnone 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 readnone 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 ; ATTRIBUTOR: call void @deref_phi_user(i32* nonnull 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 ; ATTRIBUTOR: call void @deref_phi_user(i32* nonnull %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
116 ; share known infomation in must-be-executed-context
117 declare i32* @unkown_ptr() willreturn nounwind
118 declare i32 @unkown_f(i32*) willreturn nounwind
119 define i32* @f7_0(i32* %ptr) {
120 ; ATTRIBUTOR: define nonnull dereferenceable(8) i32* @f7_0(i32* nonnull returned dereferenceable(8) %ptr)
121 %T = tail call i32 @unkown_f(i32* dereferenceable(8) %ptr)
125 ; ATTRIBUTOR: define void @f7_1(i32* nonnull dereferenceable(4) %ptr, i1 %c)
126 define void @f7_1(i32* %ptr, i1 %c) {
128 ; ATTRIBUTOR: %A = tail call i32 @unkown_f(i32* nonnull dereferenceable(4) %ptr)
129 %A = tail call i32 @unkown_f(i32* %ptr)
131 %ptr.0 = load i32, i32* %ptr
134 ; FIXME: this should be %B = tail call i32 @unkown_f(i32* nonnull dereferenceable(4) %ptr)
135 ; ATTRIBUTOR: %B = tail call i32 @unkown_f(i32* nonnull dereferenceable(4) %ptr)
136 %B = tail call i32 @unkown_f(i32* dereferenceable(1) %ptr)
138 br i1%c, label %if.true, label %if.false
140 ; ATTRIBUTOR: %C = tail call i32 @unkown_f(i32* nonnull dereferenceable(8) %ptr)
141 %C = tail call i32 @unkown_f(i32* %ptr)
143 ; ATTRIBUTOR: %D = tail call i32 @unkown_f(i32* nonnull dereferenceable(8) %ptr)
144 %D = tail call i32 @unkown_f(i32* dereferenceable(8) %ptr)
146 ; FIXME: This should be tail call i32 @unkown_f(i32* nonnull dereferenceable(8) %ptr)
147 ; Making must-be-executed-context backward exploration will fix this.
148 ; ATTRIBUTOR: %E = tail call i32 @unkown_f(i32* nonnull dereferenceable(4) %ptr)
149 %E = tail call i32 @unkown_f(i32* %ptr)
157 ; ATTRIBUTOR: define void @f7_2(i1 %c)
158 define void @f7_2(i1 %c) {
160 %ptr = tail call i32* @unkown_ptr()
162 ; ATTRIBUTOR: %A = tail call i32 @unkown_f(i32* nonnull dereferenceable(4) %ptr)
163 %A = tail call i32 @unkown_f(i32* %ptr)
165 %arg_a.0 = load i32, i32* %ptr
168 ; ATTRIBUTOR: %B = tail call i32 @unkown_f(i32* nonnull dereferenceable(4) %ptr)
169 %B = tail call i32 @unkown_f(i32* dereferenceable(1) %ptr)
171 br i1%c, label %if.true, label %if.false
174 ; ATTRIBUTOR: %C = tail call i32 @unkown_f(i32* nonnull dereferenceable(8) %ptr)
175 %C = tail call i32 @unkown_f(i32* %ptr)
177 ; ATTRIBUTOR: %D = tail call i32 @unkown_f(i32* nonnull dereferenceable(8) %ptr)
178 %D = tail call i32 @unkown_f(i32* dereferenceable(8) %ptr)
180 %E = tail call i32 @unkown_f(i32* %ptr)
181 ; FIXME: This should be @unkown_f(i32* nonnull dereferenceable(8) %ptr)
182 ; Making must-be-executed-context backward exploration will fix this.
183 ; ATTRIBUTOR: %E = tail call i32 @unkown_f(i32* nonnull dereferenceable(4) %ptr)
191 define i32* @f7_3() {
192 ; ATTRIBUTOR: define nonnull dereferenceable(4) i32* @f7_3()
193 %ptr = tail call i32* @unkown_ptr()
194 store i32 10, i32* %ptr, align 16
198 define i32* @test_for_minus_index(i32* %p) {
199 ; FIXME: This should be define nonnull dereferenceable(8) i32* @test_for_minus_index(i32* nonnull %p)
200 ; ATTRIBUTOR: define nonnull dereferenceable(8) i32* @test_for_minus_index(i32* writeonly "no-capture-maybe-returned" %p)
201 %q = getelementptr inbounds i32, i32* %p, i32 -2