1 ; RUN: opt < %s -functionattrs -S | FileCheck %s
2 ; RUN: opt < %s -passes=function-attrs -S | FileCheck %s
4 @g = global i32* null ; <i32**> [#uses=1]
6 ; CHECK: define i32* @c1(i32* readnone returned %q)
7 define i32* @c1(i32* %q) {
11 ; CHECK: define void @c2(i32* %q)
12 ; It would also be acceptable to mark %q as readnone. Update @c3 too.
13 define void @c2(i32* %q) {
14 store i32* %q, i32** @g
18 ; CHECK: define void @c3(i32* %q)
19 define void @c3(i32* %q) {
20 call void @c2(i32* %q)
24 ; CHECK: define i1 @c4(i32* %q, i32 %bitno)
25 define i1 @c4(i32* %q, i32 %bitno) {
26 %tmp = ptrtoint i32* %q to i32
27 %tmp2 = lshr i32 %tmp, %bitno
28 %bit = trunc i32 %tmp2 to i1
29 br i1 %bit, label %l1, label %l0
31 ret i1 0 ; escaping value not caught by def-use chaining.
33 ret i1 1 ; escaping value not caught by def-use chaining.
36 @lookup_table = global [2 x i1] [ i1 0, i1 1 ]
38 ; CHECK: define i1 @c5(i32* %q, i32 %bitno)
39 define i1 @c5(i32* %q, i32 %bitno) {
40 %tmp = ptrtoint i32* %q to i32
41 %tmp2 = lshr i32 %tmp, %bitno
42 %bit = and i32 %tmp2, 1
43 ; subtle escape mechanism follows
44 %lookup = getelementptr [2 x i1], [2 x i1]* @lookup_table, i32 0, i32 %bit
45 %val = load i1, i1* %lookup
49 declare void @throw_if_bit_set(i8*, i8) readonly
51 ; CHECK: define i1 @c6(i8* readonly %q, i8 %bit)
52 define i1 @c6(i8* %q, i8 %bit) personality i32 (...)* @__gxx_personality_v0 {
53 invoke void @throw_if_bit_set(i8* %q, i8 %bit)
54 to label %ret0 unwind label %ret1
58 %exn = landingpad {i8*, i32}
63 declare i32 @__gxx_personality_v0(...)
65 define i1* @lookup_bit(i32* %q, i32 %bitno) readnone nounwind {
66 %tmp = ptrtoint i32* %q to i32
67 %tmp2 = lshr i32 %tmp, %bitno
68 %bit = and i32 %tmp2, 1
69 %lookup = getelementptr [2 x i1], [2 x i1]* @lookup_table, i32 0, i32 %bit
73 ; CHECK: define i1 @c7(i32* readonly %q, i32 %bitno)
74 define i1 @c7(i32* %q, i32 %bitno) {
75 %ptr = call i1* @lookup_bit(i32* %q, i32 %bitno)
76 %val = load i1, i1* %ptr
81 ; CHECK: define i32 @nc1(i32* %q, i32* nocapture %p, i1 %b)
82 define i32 @nc1(i32* %q, i32* %p, i1 %b) {
86 %x = phi i32* [ %p, %e ]
87 %y = phi i32* [ %q, %e ]
88 %tmp = bitcast i32* %x to i32* ; <i32*> [#uses=2]
89 %tmp2 = select i1 %b, i32* %tmp, i32* %y
90 %val = load i32, i32* %tmp2 ; <i32> [#uses=1]
91 store i32 0, i32* %tmp
92 store i32* %y, i32** @g
96 ; CHECK: define i32 @nc1_addrspace(i32* %q, i32 addrspace(1)* nocapture %p, i1 %b)
97 define i32 @nc1_addrspace(i32* %q, i32 addrspace(1)* %p, i1 %b) {
101 %x = phi i32 addrspace(1)* [ %p, %e ]
102 %y = phi i32* [ %q, %e ]
103 %tmp = addrspacecast i32 addrspace(1)* %x to i32* ; <i32*> [#uses=2]
104 %tmp2 = select i1 %b, i32* %tmp, i32* %y
105 %val = load i32, i32* %tmp2 ; <i32> [#uses=1]
106 store i32 0, i32* %tmp
107 store i32* %y, i32** @g
111 ; CHECK: define void @nc2(i32* nocapture %p, i32* %q)
112 define void @nc2(i32* %p, i32* %q) {
113 %1 = call i32 @nc1(i32* %q, i32* %p, i1 0) ; <i32> [#uses=0]
117 ; CHECK: define void @nc3(void ()* nocapture %p)
118 define void @nc3(void ()* %p) {
123 declare void @external(i8*) readonly nounwind
124 ; CHECK: define void @nc4(i8* nocapture readonly %p)
125 define void @nc4(i8* %p) {
126 call void @external(i8* %p)
130 ; CHECK: define void @nc5(void (i8*)* nocapture %f, i8* nocapture %p)
131 define void @nc5(void (i8*)* %f, i8* %p) {
132 call void %f(i8* %p) readonly nounwind
133 call void %f(i8* nocapture %p)
137 ; CHECK: define void @test1_1(i8* nocapture readnone %x1_1, i8* %y1_1)
138 ; It would be acceptable to add readnone to %y1_1 and %y1_2.
139 define void @test1_1(i8* %x1_1, i8* %y1_1) {
140 call i8* @test1_2(i8* %x1_1, i8* %y1_1)
141 store i32* null, i32** @g
145 ; CHECK: define i8* @test1_2(i8* nocapture readnone %x1_2, i8* returned %y1_2)
146 define i8* @test1_2(i8* %x1_2, i8* %y1_2) {
147 call void @test1_1(i8* %x1_2, i8* %y1_2)
148 store i32* null, i32** @g
152 ; CHECK: define void @test2(i8* nocapture readnone %x2)
153 define void @test2(i8* %x2) {
154 call void @test2(i8* %x2)
155 store i32* null, i32** @g
159 ; CHECK: define void @test3(i8* nocapture readnone %x3, i8* nocapture readnone %y3, i8* nocapture readnone %z3)
160 define void @test3(i8* %x3, i8* %y3, i8* %z3) {
161 call void @test3(i8* %z3, i8* %y3, i8* %x3)
162 store i32* null, i32** @g
166 ; CHECK: define void @test4_1(i8* %x4_1)
167 define void @test4_1(i8* %x4_1) {
168 call i8* @test4_2(i8* %x4_1, i8* %x4_1, i8* %x4_1)
169 store i32* null, i32** @g
173 ; CHECK: define i8* @test4_2(i8* nocapture readnone %x4_2, i8* readnone returned %y4_2, i8* nocapture readnone %z4_2)
174 define i8* @test4_2(i8* %x4_2, i8* %y4_2, i8* %z4_2) {
175 call void @test4_1(i8* null)
176 store i32* null, i32** @g
180 declare i8* @test5_1(i8* %x5_1)
182 ; CHECK: define void @test5_2(i8* %x5_2)
183 define void @test5_2(i8* %x5_2) {
184 call i8* @test5_1(i8* %x5_2)
185 store i32* null, i32** @g
189 declare void @test6_1(i8* %x6_1, i8* nocapture %y6_1, ...)
191 ; CHECK: define void @test6_2(i8* %x6_2, i8* nocapture %y6_2, i8* %z6_2)
192 define void @test6_2(i8* %x6_2, i8* %y6_2, i8* %z6_2) {
193 call void (i8*, i8*, ...) @test6_1(i8* %x6_2, i8* %y6_2, i8* %z6_2)
194 store i32* null, i32** @g
198 ; CHECK: define void @test_cmpxchg(i32* nocapture %p)
199 define void @test_cmpxchg(i32* %p) {
200 cmpxchg i32* %p, i32 0, i32 1 acquire monotonic
204 ; CHECK: define void @test_cmpxchg_ptr(i32** nocapture %p, i32* %q)
205 define void @test_cmpxchg_ptr(i32** %p, i32* %q) {
206 cmpxchg i32** %p, i32* null, i32* %q acquire monotonic
210 ; CHECK: define void @test_atomicrmw(i32* nocapture %p)
211 define void @test_atomicrmw(i32* %p) {
212 atomicrmw add i32* %p, i32 1 seq_cst
216 ; CHECK: define void @test_volatile(i32* %x)
217 define void @test_volatile(i32* %x) {
219 %gep = getelementptr i32, i32* %x, i64 1
220 store volatile i32 0, i32* %gep, align 4
224 ; CHECK: nocaptureLaunder(i8* nocapture %p)
225 define void @nocaptureLaunder(i8* %p) {
227 %b = call i8* @llvm.launder.invariant.group.p0i8(i8* %p)
232 @g2 = global i8* null
233 ; CHECK: define void @captureLaunder(i8* %p)
234 define void @captureLaunder(i8* %p) {
235 %b = call i8* @llvm.launder.invariant.group.p0i8(i8* %p)
236 store i8* %b, i8** @g2
240 ; CHECK: @nocaptureStrip(i8* nocapture %p)
241 define void @nocaptureStrip(i8* %p) {
243 %b = call i8* @llvm.strip.invariant.group.p0i8(i8* %p)
248 @g3 = global i8* null
249 ; CHECK: define void @captureStrip(i8* %p)
250 define void @captureStrip(i8* %p) {
251 %b = call i8* @llvm.strip.invariant.group.p0i8(i8* %p)
252 store i8* %b, i8** @g3
256 ; CHECK: define i1 @captureICmp(i32* readnone %x)
257 define i1 @captureICmp(i32* %x) {
258 %1 = icmp eq i32* %x, null
262 ; CHECK: define i1 @captureICmpRev(i32* readnone %x)
263 define i1 @captureICmpRev(i32* %x) {
264 %1 = icmp eq i32* null, %x
268 ; CHECK: define i1 @nocaptureInboundsGEPICmp(i32* nocapture readnone %x)
269 define i1 @nocaptureInboundsGEPICmp(i32* %x) {
270 %1 = getelementptr inbounds i32, i32* %x, i32 5
271 %2 = bitcast i32* %1 to i8*
272 %3 = icmp eq i8* %2, null
276 ; CHECK: define i1 @nocaptureInboundsGEPICmpRev(i32* nocapture readnone %x)
277 define i1 @nocaptureInboundsGEPICmpRev(i32* %x) {
278 %1 = getelementptr inbounds i32, i32* %x, i32 5
279 %2 = bitcast i32* %1 to i8*
280 %3 = icmp eq i8* null, %2
284 ; CHECK: define i1 @nocaptureDereferenceableOrNullICmp(i32* nocapture readnone dereferenceable_or_null(4) %x)
285 define i1 @nocaptureDereferenceableOrNullICmp(i32* dereferenceable_or_null(4) %x) {
286 %1 = bitcast i32* %x to i8*
287 %2 = icmp eq i8* %1, null
291 ; CHECK: define i1 @captureDereferenceableOrNullICmp(i32* readnone dereferenceable_or_null(4) %x)
292 define i1 @captureDereferenceableOrNullICmp(i32* dereferenceable_or_null(4) %x) "null-pointer-is-valid"="true" {
293 %1 = bitcast i32* %x to i8*
294 %2 = icmp eq i8* %1, null
298 declare i8* @llvm.launder.invariant.group.p0i8(i8*)
299 declare i8* @llvm.strip.invariant.group.p0i8(i8*)