1; RUN: opt < %s -functionattrs -S | FileCheck %s 2@g = global i32* null ; <i32**> [#uses=1] 3 4; CHECK: define i32* @c1(i32* readnone %q) 5define i32* @c1(i32* %q) { 6 ret i32* %q 7} 8 9; CHECK: define void @c2(i32* %q) 10; It would also be acceptable to mark %q as readnone. Update @c3 too. 11define void @c2(i32* %q) { 12 store i32* %q, i32** @g 13 ret void 14} 15 16; CHECK: define void @c3(i32* %q) 17define void @c3(i32* %q) { 18 call void @c2(i32* %q) 19 ret void 20} 21 22; CHECK: define i1 @c4(i32* %q, i32 %bitno) 23define 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 28l0: 29 ret i1 0 ; escaping value not caught by def-use chaining. 30l1: 31 ret i1 1 ; escaping value not caught by def-use chaining. 32} 33 34@lookup_table = global [2 x i1] [ i1 0, i1 1 ] 35 36; CHECK: define i1 @c5(i32* %q, i32 %bitno) 37define 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, i1* %lookup 44 ret i1 %val 45} 46 47declare void @throw_if_bit_set(i8*, i8) readonly 48 49; CHECK: define i1 @c6(i8* readonly %q, i8 %bit) 50define i1 @c6(i8* %q, i8 %bit) personality i32 (...)* @__gxx_personality_v0 { 51 invoke void @throw_if_bit_set(i8* %q, i8 %bit) 52 to label %ret0 unwind label %ret1 53ret0: 54 ret i1 0 55ret1: 56 %exn = landingpad {i8*, i32} 57 cleanup 58 ret i1 1 59} 60 61declare i32 @__gxx_personality_v0(...) 62 63define 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 68 ret i1* %lookup 69} 70 71; CHECK: define i1 @c7(i32* readonly %q, i32 %bitno) 72define i1 @c7(i32* %q, i32 %bitno) { 73 %ptr = call i1* @lookup_bit(i32* %q, i32 %bitno) 74 %val = load i1, i1* %ptr 75 ret i1 %val 76} 77 78 79; CHECK: define i32 @nc1(i32* %q, i32* nocapture %p, i1 %b) 80define i32 @nc1(i32* %q, i32* %p, i1 %b) { 81e: 82 br label %l 83l: 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, i32* %tmp2 ; <i32> [#uses=1] 89 store i32 0, i32* %tmp 90 store i32* %y, i32** @g 91 ret i32 %val 92} 93 94; CHECK: define i32 @nc1_addrspace(i32* %q, i32 addrspace(1)* nocapture %p, i1 %b) 95define i32 @nc1_addrspace(i32* %q, i32 addrspace(1)* %p, i1 %b) { 96e: 97 br label %l 98l: 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, i32* %tmp2 ; <i32> [#uses=1] 104 store i32 0, i32* %tmp 105 store i32* %y, i32** @g 106 ret i32 %val 107} 108 109; CHECK: define void @nc2(i32* nocapture %p, i32* %q) 110define void @nc2(i32* %p, i32* %q) { 111 %1 = call i32 @nc1(i32* %q, i32* %p, i1 0) ; <i32> [#uses=0] 112 ret void 113} 114 115; CHECK: define void @nc3(void ()* nocapture %p) 116define void @nc3(void ()* %p) { 117 call void %p() 118 ret void 119} 120 121declare void @external(i8*) readonly nounwind 122; CHECK: define void @nc4(i8* nocapture readonly %p) 123define void @nc4(i8* %p) { 124 call void @external(i8* %p) 125 ret void 126} 127 128; CHECK: define void @nc5(void (i8*)* nocapture %f, i8* nocapture %p) 129define void @nc5(void (i8*)* %f, i8* %p) { 130 call void %f(i8* %p) readonly nounwind 131 call void %f(i8* nocapture %p) 132 ret void 133} 134 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. 137define 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 140 ret void 141} 142 143; CHECK: define i8* @test1_2(i8* nocapture readnone %x1_2, i8* %y1_2) 144define 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 147 ret i8* %y1_2 148} 149 150; CHECK: define void @test2(i8* nocapture readnone %x2) 151define void @test2(i8* %x2) { 152 call void @test2(i8* %x2) 153 store i32* null, i32** @g 154 ret void 155} 156 157; CHECK: define void @test3(i8* nocapture readnone %x3, i8* nocapture readnone %y3, i8* nocapture readnone %z3) 158define void @test3(i8* %x3, i8* %y3, i8* %z3) { 159 call void @test3(i8* %z3, i8* %y3, i8* %x3) 160 store i32* null, i32** @g 161 ret void 162} 163 164; CHECK: define void @test4_1(i8* %x4_1) 165define 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 168 ret void 169} 170 171; CHECK: define i8* @test4_2(i8* nocapture readnone %x4_2, i8* readnone %y4_2, i8* nocapture readnone %z4_2) 172define 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 175 ret i8* %y4_2 176} 177 178declare i8* @test5_1(i8* %x5_1) 179 180; CHECK: define void @test5_2(i8* %x5_2) 181define void @test5_2(i8* %x5_2) { 182 call i8* @test5_1(i8* %x5_2) 183 store i32* null, i32** @g 184 ret void 185} 186 187declare void @test6_1(i8* %x6_1, i8* nocapture %y6_1, ...) 188 189; CHECK: define void @test6_2(i8* %x6_2, i8* nocapture %y6_2, i8* %z6_2) 190define 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 193 ret void 194} 195 196; CHECK: define void @test_cmpxchg(i32* nocapture %p) 197define void @test_cmpxchg(i32* %p) { 198 cmpxchg i32* %p, i32 0, i32 1 acquire monotonic 199 ret void 200} 201 202; CHECK: define void @test_cmpxchg_ptr(i32** nocapture %p, i32* %q) 203define void @test_cmpxchg_ptr(i32** %p, i32* %q) { 204 cmpxchg i32** %p, i32* null, i32* %q acquire monotonic 205 ret void 206} 207 208; CHECK: define void @test_atomicrmw(i32* nocapture %p) 209define void @test_atomicrmw(i32* %p) { 210 atomicrmw add i32* %p, i32 1 seq_cst 211 ret void 212} 213 214; CHECK: define void @test_volatile(i32* %x) 215define void @test_volatile(i32* %x) { 216entry: 217 %gep = getelementptr i32, i32* %x, i64 1 218 store volatile i32 0, i32* %gep, align 4 219 ret void 220} 221