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) 5 define 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. 11 define void @c2(i32* %q) { 12 store i32* %q, i32** @g 13 ret void 14 } 15 16 ; CHECK: define void @c3(i32* %q) 17 define void @c3(i32* %q) { 18 call void @c2(i32* %q) 19 ret void 20 } 21 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 28 l0: 29 ret i1 0 ; escaping value not caught by def-use chaining. 30 l1: 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) 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]* @lookup_table, i32 0, i32 %bit 43 %val = load i1* %lookup 44 ret i1 %val 45 } 46 47 declare void @throw_if_bit_set(i8*, i8) readonly 48 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 53 ret0: 54 ret i1 0 55 ret1: 56 %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0 57 cleanup 58 ret i1 1 59 } 60 61 declare i32 @__gxx_personality_v0(...) 62 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]* @lookup_table, i32 0, i32 %bit 68 ret i1* %lookup 69 } 70 71 ; CHECK: define i1 @c7(i32* readnone %q, i32 %bitno) 72 define i1 @c7(i32* %q, i32 %bitno) { 73 %ptr = call i1* @lookup_bit(i32* %q, i32 %bitno) 74 %val = load i1* %ptr 75 ret i1 %val 76 } 77 78 79 ; CHECK: define i32 @nc1(i32* %q, i32* nocapture %p, i1 %b) 80 define i32 @nc1(i32* %q, i32* %p, i1 %b) { 81 e: 82 br label %l 83 l: 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 91 ret i32 %val 92 } 93 94 ; CHECK: define void @nc2(i32* nocapture %p, i32* %q) 95 define void @nc2(i32* %p, i32* %q) { 96 %1 = call i32 @nc1(i32* %q, i32* %p, i1 0) ; <i32> [#uses=0] 97 ret void 98 } 99 100 ; CHECK: define void @nc3(void ()* nocapture %p) 101 define void @nc3(void ()* %p) { 102 call void %p() 103 ret void 104 } 105 106 declare void @external(i8*) readonly nounwind 107 ; CHECK: define void @nc4(i8* nocapture readonly %p) 108 define void @nc4(i8* %p) { 109 call void @external(i8* %p) 110 ret void 111 } 112 113 ; CHECK: define void @nc5(void (i8*)* nocapture %f, i8* nocapture %p) 114 define void @nc5(void (i8*)* %f, i8* %p) { 115 call void %f(i8* %p) readonly nounwind 116 call void %f(i8* nocapture %p) 117 ret void 118 } 119 120 ; CHECK: define void @test1_1(i8* nocapture readnone %x1_1, i8* %y1_1) 121 ; It would be acceptable to add readnone to %y1_1 and %y1_2. 122 define void @test1_1(i8* %x1_1, i8* %y1_1) { 123 call i8* @test1_2(i8* %x1_1, i8* %y1_1) 124 store i32* null, i32** @g 125 ret void 126 } 127 128 ; CHECK: define i8* @test1_2(i8* nocapture readnone %x1_2, i8* %y1_2) 129 define i8* @test1_2(i8* %x1_2, i8* %y1_2) { 130 call void @test1_1(i8* %x1_2, i8* %y1_2) 131 store i32* null, i32** @g 132 ret i8* %y1_2 133 } 134 135 ; CHECK: define void @test2(i8* nocapture readnone %x2) 136 define void @test2(i8* %x2) { 137 call void @test2(i8* %x2) 138 store i32* null, i32** @g 139 ret void 140 } 141 142 ; CHECK: define void @test3(i8* nocapture readnone %x3, i8* nocapture readnone %y3, i8* nocapture readnone %z3) 143 define void @test3(i8* %x3, i8* %y3, i8* %z3) { 144 call void @test3(i8* %z3, i8* %y3, i8* %x3) 145 store i32* null, i32** @g 146 ret void 147 } 148 149 ; CHECK: define void @test4_1(i8* %x4_1) 150 define void @test4_1(i8* %x4_1) { 151 call i8* @test4_2(i8* %x4_1, i8* %x4_1, i8* %x4_1) 152 store i32* null, i32** @g 153 ret void 154 } 155 156 ; CHECK: define i8* @test4_2(i8* nocapture readnone %x4_2, i8* readnone %y4_2, i8* nocapture readnone %z4_2) 157 define i8* @test4_2(i8* %x4_2, i8* %y4_2, i8* %z4_2) { 158 call void @test4_1(i8* null) 159 store i32* null, i32** @g 160 ret i8* %y4_2 161 } 162 163 declare i8* @test5_1(i8* %x5_1) 164 165 ; CHECK: define void @test5_2(i8* %x5_2) 166 define void @test5_2(i8* %x5_2) { 167 call i8* @test5_1(i8* %x5_2) 168 store i32* null, i32** @g 169 ret void 170 } 171 172 declare void @test6_1(i8* %x6_1, i8* nocapture %y6_1, ...) 173 174 ; CHECK: define void @test6_2(i8* %x6_2, i8* nocapture %y6_2, i8* %z6_2) 175 define void @test6_2(i8* %x6_2, i8* %y6_2, i8* %z6_2) { 176 call void (i8*, i8*, ...)* @test6_1(i8* %x6_2, i8* %y6_2, i8* %z6_2) 177 store i32* null, i32** @g 178 ret void 179 } 180 181