1; RUN: opt < %s -functionattrs -S | FileCheck %s 2@g = global i32* null ; <i32**> [#uses=1] 3 4; CHECK: define i32* @c1(i32* %q) 5define i32* @c1(i32* %q) { 6 ret i32* %q 7} 8 9; CHECK: define void @c2(i32* %q) 10define void @c2(i32* %q) { 11 store i32* %q, i32** @g 12 ret void 13} 14 15; CHECK: define void @c3(i32* %q) 16define void @c3(i32* %q) { 17 call void @c2(i32* %q) 18 ret void 19} 20 21; CHECK: define i1 @c4(i32* %q, i32 %bitno) 22define i1 @c4(i32* %q, i32 %bitno) { 23 %tmp = ptrtoint i32* %q to i32 24 %tmp2 = lshr i32 %tmp, %bitno 25 %bit = trunc i32 %tmp2 to i1 26 br i1 %bit, label %l1, label %l0 27l0: 28 ret i1 0 ; escaping value not caught by def-use chaining. 29l1: 30 ret i1 1 ; escaping value not caught by def-use chaining. 31} 32 33@lookup_table = global [2 x i1] [ i1 0, i1 1 ] 34 35; CHECK: define i1 @c5(i32* %q, i32 %bitno) 36define i1 @c5(i32* %q, i32 %bitno) { 37 %tmp = ptrtoint i32* %q to i32 38 %tmp2 = lshr i32 %tmp, %bitno 39 %bit = and i32 %tmp2, 1 40 ; subtle escape mechanism follows 41 %lookup = getelementptr [2 x i1]* @lookup_table, i32 0, i32 %bit 42 %val = load i1* %lookup 43 ret i1 %val 44} 45 46declare void @throw_if_bit_set(i8*, i8) readonly 47 48; CHECK: define i1 @c6(i8* %q, i8 %bit) 49define i1 @c6(i8* %q, i8 %bit) { 50 invoke void @throw_if_bit_set(i8* %q, i8 %bit) 51 to label %ret0 unwind label %ret1 52ret0: 53 ret i1 0 54ret1: 55 %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0 56 cleanup 57 ret i1 1 58} 59 60declare i32 @__gxx_personality_v0(...) 61 62define i1* @lookup_bit(i32* %q, i32 %bitno) readnone nounwind { 63 %tmp = ptrtoint i32* %q to i32 64 %tmp2 = lshr i32 %tmp, %bitno 65 %bit = and i32 %tmp2, 1 66 %lookup = getelementptr [2 x i1]* @lookup_table, i32 0, i32 %bit 67 ret i1* %lookup 68} 69 70; CHECK: define i1 @c7(i32* %q, i32 %bitno) 71define i1 @c7(i32* %q, i32 %bitno) { 72 %ptr = call i1* @lookup_bit(i32* %q, i32 %bitno) 73 %val = load i1* %ptr 74 ret i1 %val 75} 76 77 78; CHECK: define i32 @nc1(i32* %q, i32* nocapture %p, i1 %b) 79define i32 @nc1(i32* %q, i32* %p, i1 %b) { 80e: 81 br label %l 82l: 83 %x = phi i32* [ %p, %e ] 84 %y = phi i32* [ %q, %e ] 85 %tmp = bitcast i32* %x to i32* ; <i32*> [#uses=2] 86 %tmp2 = select i1 %b, i32* %tmp, i32* %y 87 %val = load i32* %tmp2 ; <i32> [#uses=1] 88 store i32 0, i32* %tmp 89 store i32* %y, i32** @g 90 ret i32 %val 91} 92 93; CHECK: define void @nc2(i32* nocapture %p, i32* %q) 94define void @nc2(i32* %p, i32* %q) { 95 %1 = call i32 @nc1(i32* %q, i32* %p, i1 0) ; <i32> [#uses=0] 96 ret void 97} 98 99; CHECK: define void @nc3(void ()* nocapture %p) 100define void @nc3(void ()* %p) { 101 call void %p() 102 ret void 103} 104 105declare void @external(i8*) readonly nounwind 106; CHECK: define void @nc4(i8* nocapture %p) 107define void @nc4(i8* %p) { 108 call void @external(i8* %p) 109 ret void 110} 111 112; CHECK: define void @nc5(void (i8*)* nocapture %f, i8* nocapture %p) 113define void @nc5(void (i8*)* %f, i8* %p) { 114 call void %f(i8* %p) readonly nounwind 115 call void %f(i8* nocapture %p) 116 ret void 117} 118 119; CHECK: define void @test1_1(i8* nocapture %x1_1, i8* %y1_1) 120define void @test1_1(i8* %x1_1, i8* %y1_1) { 121 call i8* @test1_2(i8* %x1_1, i8* %y1_1) 122 store i32* null, i32** @g 123 ret void 124} 125 126; CHECK: define i8* @test1_2(i8* nocapture %x1_2, i8* %y1_2) 127define i8* @test1_2(i8* %x1_2, i8* %y1_2) { 128 call void @test1_1(i8* %x1_2, i8* %y1_2) 129 store i32* null, i32** @g 130 ret i8* %y1_2 131} 132 133; CHECK: define void @test2(i8* nocapture %x2) 134define void @test2(i8* %x2) { 135 call void @test2(i8* %x2) 136 store i32* null, i32** @g 137 ret void 138} 139 140; CHECK: define void @test3(i8* nocapture %x3, i8* nocapture %y3, i8* nocapture %z3) 141define void @test3(i8* %x3, i8* %y3, i8* %z3) { 142 call void @test3(i8* %z3, i8* %y3, i8* %x3) 143 store i32* null, i32** @g 144 ret void 145} 146 147; CHECK: define void @test4_1(i8* %x4_1) 148define void @test4_1(i8* %x4_1) { 149 call i8* @test4_2(i8* %x4_1, i8* %x4_1, i8* %x4_1) 150 store i32* null, i32** @g 151 ret void 152} 153 154; CHECK: define i8* @test4_2(i8* nocapture %x4_2, i8* %y4_2, i8* nocapture %z4_2) 155define i8* @test4_2(i8* %x4_2, i8* %y4_2, i8* %z4_2) { 156 call void @test4_1(i8* null) 157 store i32* null, i32** @g 158 ret i8* %y4_2 159} 160 161declare i8* @test5_1(i8* %x5_1) 162 163; CHECK: define void @test5_2(i8* %x5_2) 164define void @test5_2(i8* %x5_2) { 165 call i8* @test5_1(i8* %x5_2) 166 store i32* null, i32** @g 167 ret void 168} 169 170declare void @test6_1(i8* %x6_1, i8* nocapture %y6_1, ...) 171 172; CHECK: define void @test6_2(i8* %x6_2, i8* nocapture %y6_2, i8* %z6_2) 173define void @test6_2(i8* %x6_2, i8* %y6_2, i8* %z6_2) { 174 call void (i8*, i8*, ...)* @test6_1(i8* %x6_2, i8* %y6_2, i8* %z6_2) 175 store i32* null, i32** @g 176 ret void 177} 178 179