1 ; RUN: opt < %s -functionattrs -S | FileCheck %s
2 @g = global i32* null ; <i32**> [#uses=1]
4 ; CHECK: define i32* @c1(i32* readnone %q)
5 define i32* @c1(i32* %q) {
9 ; CHECK: define void @c2(i32* %q)
10 ; It would also be acceptable to mark %q as readnone. Update @c3 too.
11 define void @c2(i32* %q) {
12 store i32* %q, i32** @g
16 ; CHECK: define void @c3(i32* %q)
17 define void @c3(i32* %q) {
18 call void @c2(i32* %q)
22 ; CHECK: define i1 @c4(i32* %q, i32 %bitno)
23 define i1 @c4(i32* %q, i32 %bitno) {
24 %tmp = ptrtoint i32* %q to i32
25 %tmp2 = lshr i32 %tmp, %bitno
26 %bit = trunc i32 %tmp2 to i1
27 br i1 %bit, label %l1, label %l0
29 ret i1 0 ; escaping value not caught by def-use chaining.
31 ret i1 1 ; escaping value not caught by def-use chaining.
34 @lookup_table = global [2 x i1] [ i1 0, i1 1 ]
36 ; CHECK: define i1 @c5(i32* %q, i32 %bitno)
37 define i1 @c5(i32* %q, i32 %bitno) {
38 %tmp = ptrtoint i32* %q to i32
39 %tmp2 = lshr i32 %tmp, %bitno
40 %bit = and i32 %tmp2, 1
41 ; subtle escape mechanism follows
42 %lookup = getelementptr [2 x i1], [2 x i1]* @lookup_table, i32 0, i32 %bit
43 %val = load i1* %lookup
47 declare void @throw_if_bit_set(i8*, i8) readonly
49 ; CHECK: define i1 @c6(i8* readonly %q, i8 %bit)
50 define i1 @c6(i8* %q, i8 %bit) {
51 invoke void @throw_if_bit_set(i8* %q, i8 %bit)
52 to label %ret0 unwind label %ret1
56 %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
61 declare i32 @__gxx_personality_v0(...)
63 define i1* @lookup_bit(i32* %q, i32 %bitno) readnone nounwind {
64 %tmp = ptrtoint i32* %q to i32
65 %tmp2 = lshr i32 %tmp, %bitno
66 %bit = and i32 %tmp2, 1
67 %lookup = getelementptr [2 x i1], [2 x i1]* @lookup_table, i32 0, i32 %bit
71 ; CHECK: define i1 @c7(i32* readonly %q, i32 %bitno)
72 define i1 @c7(i32* %q, i32 %bitno) {
73 %ptr = call i1* @lookup_bit(i32* %q, i32 %bitno)
79 ; CHECK: define i32 @nc1(i32* %q, i32* nocapture %p, i1 %b)
80 define i32 @nc1(i32* %q, i32* %p, i1 %b) {
84 %x = phi i32* [ %p, %e ]
85 %y = phi i32* [ %q, %e ]
86 %tmp = bitcast i32* %x to i32* ; <i32*> [#uses=2]
87 %tmp2 = select i1 %b, i32* %tmp, i32* %y
88 %val = load i32* %tmp2 ; <i32> [#uses=1]
89 store i32 0, i32* %tmp
90 store i32* %y, i32** @g
94 ; CHECK: define i32 @nc1_addrspace(i32* %q, i32 addrspace(1)* nocapture %p, i1 %b)
95 define i32 @nc1_addrspace(i32* %q, i32 addrspace(1)* %p, i1 %b) {
99 %x = phi i32 addrspace(1)* [ %p, %e ]
100 %y = phi i32* [ %q, %e ]
101 %tmp = addrspacecast i32 addrspace(1)* %x to i32* ; <i32*> [#uses=2]
102 %tmp2 = select i1 %b, i32* %tmp, i32* %y
103 %val = load i32* %tmp2 ; <i32> [#uses=1]
104 store i32 0, i32* %tmp
105 store i32* %y, i32** @g
109 ; CHECK: define void @nc2(i32* nocapture %p, i32* %q)
110 define void @nc2(i32* %p, i32* %q) {
111 %1 = call i32 @nc1(i32* %q, i32* %p, i1 0) ; <i32> [#uses=0]
115 ; CHECK: define void @nc3(void ()* nocapture %p)
116 define void @nc3(void ()* %p) {
121 declare void @external(i8*) readonly nounwind
122 ; CHECK: define void @nc4(i8* nocapture readonly %p)
123 define void @nc4(i8* %p) {
124 call void @external(i8* %p)
128 ; CHECK: define void @nc5(void (i8*)* nocapture %f, i8* nocapture %p)
129 define void @nc5(void (i8*)* %f, i8* %p) {
130 call void %f(i8* %p) readonly nounwind
131 call void %f(i8* nocapture %p)
135 ; CHECK: define void @test1_1(i8* nocapture readnone %x1_1, i8* %y1_1)
136 ; It would be acceptable to add readnone to %y1_1 and %y1_2.
137 define void @test1_1(i8* %x1_1, i8* %y1_1) {
138 call i8* @test1_2(i8* %x1_1, i8* %y1_1)
139 store i32* null, i32** @g
143 ; CHECK: define i8* @test1_2(i8* nocapture readnone %x1_2, i8* %y1_2)
144 define i8* @test1_2(i8* %x1_2, i8* %y1_2) {
145 call void @test1_1(i8* %x1_2, i8* %y1_2)
146 store i32* null, i32** @g
150 ; CHECK: define void @test2(i8* nocapture readnone %x2)
151 define void @test2(i8* %x2) {
152 call void @test2(i8* %x2)
153 store i32* null, i32** @g
157 ; CHECK: define void @test3(i8* nocapture readnone %x3, i8* nocapture readnone %y3, i8* nocapture readnone %z3)
158 define void @test3(i8* %x3, i8* %y3, i8* %z3) {
159 call void @test3(i8* %z3, i8* %y3, i8* %x3)
160 store i32* null, i32** @g
164 ; CHECK: define void @test4_1(i8* %x4_1)
165 define void @test4_1(i8* %x4_1) {
166 call i8* @test4_2(i8* %x4_1, i8* %x4_1, i8* %x4_1)
167 store i32* null, i32** @g
171 ; CHECK: define i8* @test4_2(i8* nocapture readnone %x4_2, i8* readnone %y4_2, i8* nocapture readnone %z4_2)
172 define i8* @test4_2(i8* %x4_2, i8* %y4_2, i8* %z4_2) {
173 call void @test4_1(i8* null)
174 store i32* null, i32** @g
178 declare i8* @test5_1(i8* %x5_1)
180 ; CHECK: define void @test5_2(i8* %x5_2)
181 define void @test5_2(i8* %x5_2) {
182 call i8* @test5_1(i8* %x5_2)
183 store i32* null, i32** @g
187 declare void @test6_1(i8* %x6_1, i8* nocapture %y6_1, ...)
189 ; CHECK: define void @test6_2(i8* %x6_2, i8* nocapture %y6_2, i8* %z6_2)
190 define void @test6_2(i8* %x6_2, i8* %y6_2, i8* %z6_2) {
191 call void (i8*, i8*, ...)* @test6_1(i8* %x6_2, i8* %y6_2, i8* %z6_2)
192 store i32* null, i32** @g