Nick Lewycky | d4659ad | 2011-12-23 18:41:31 +0000 | [diff] [blame] | 1 | ; RUN: opt < %s -functionattrs -S | FileCheck %s |
Duncan Sands | 9e89ba3 | 2008-12-31 16:14:43 +0000 | [diff] [blame] | 2 | @g = global i32* null ; <i32**> [#uses=1] |
| 3 | |
Nick Lewycky | d4659ad | 2011-12-23 18:41:31 +0000 | [diff] [blame] | 4 | ; CHECK: define i32* @c1(i32* %q) |
Duncan Sands | 1010941 | 2008-12-31 20:21:34 +0000 | [diff] [blame] | 5 | define i32* @c1(i32* %q) { |
| 6 | ret i32* %q |
Duncan Sands | 9e89ba3 | 2008-12-31 16:14:43 +0000 | [diff] [blame] | 7 | } |
| 8 | |
Nick Lewycky | d4659ad | 2011-12-23 18:41:31 +0000 | [diff] [blame] | 9 | ; CHECK: define void @c2(i32* %q) |
Duncan Sands | 1010941 | 2008-12-31 20:21:34 +0000 | [diff] [blame] | 10 | define void @c2(i32* %q) { |
| 11 | store i32* %q, i32** @g |
Duncan Sands | 9e89ba3 | 2008-12-31 16:14:43 +0000 | [diff] [blame] | 12 | ret void |
| 13 | } |
| 14 | |
Nick Lewycky | d4659ad | 2011-12-23 18:41:31 +0000 | [diff] [blame] | 15 | ; CHECK: define void @c3(i32* %q) |
Duncan Sands | 1010941 | 2008-12-31 20:21:34 +0000 | [diff] [blame] | 16 | define void @c3(i32* %q) { |
| 17 | call void @c2(i32* %q) |
Duncan Sands | 9e89ba3 | 2008-12-31 16:14:43 +0000 | [diff] [blame] | 18 | ret void |
| 19 | } |
| 20 | |
Nick Lewycky | d4659ad | 2011-12-23 18:41:31 +0000 | [diff] [blame] | 21 | ; CHECK: define i1 @c4(i32* %q, i32 %bitno) |
Duncan Sands | 29ab02b | 2009-01-02 00:55:51 +0000 | [diff] [blame] | 22 | define 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 |
| 27 | l0: |
| 28 | ret i1 0 ; escaping value not caught by def-use chaining. |
| 29 | l1: |
| 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 | |
Nick Lewycky | d4659ad | 2011-12-23 18:41:31 +0000 | [diff] [blame] | 35 | ; CHECK: define i1 @c5(i32* %q, i32 %bitno) |
Duncan Sands | 29ab02b | 2009-01-02 00:55:51 +0000 | [diff] [blame] | 36 | define 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 | |
Mike Stump | fe095f3 | 2009-05-04 18:40:41 +0000 | [diff] [blame] | 46 | declare void @throw_if_bit_set(i8*, i8) readonly |
Nick Lewycky | d4659ad | 2011-12-23 18:41:31 +0000 | [diff] [blame] | 47 | |
| 48 | ; CHECK: define i1 @c6(i8* %q, i8 %bit) |
Mike Stump | fe095f3 | 2009-05-04 18:40:41 +0000 | [diff] [blame] | 49 | define i1 @c6(i8* %q, i8 %bit) { |
| 50 | invoke void @throw_if_bit_set(i8* %q, i8 %bit) |
| 51 | to label %ret0 unwind label %ret1 |
| 52 | ret0: |
| 53 | ret i1 0 |
| 54 | ret1: |
Bill Wendling | aeaa9a8 | 2011-09-01 00:58:03 +0000 | [diff] [blame] | 55 | %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0 |
| 56 | cleanup |
Mike Stump | fe095f3 | 2009-05-04 18:40:41 +0000 | [diff] [blame] | 57 | ret i1 1 |
| 58 | } |
| 59 | |
Bill Wendling | aeaa9a8 | 2011-09-01 00:58:03 +0000 | [diff] [blame] | 60 | declare i32 @__gxx_personality_v0(...) |
| 61 | |
Duncan Sands | 1978426 | 2009-05-07 18:08:34 +0000 | [diff] [blame] | 62 | define 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 | |
Nick Lewycky | d4659ad | 2011-12-23 18:41:31 +0000 | [diff] [blame] | 70 | ; CHECK: define i1 @c7(i32* %q, i32 %bitno) |
Duncan Sands | 1978426 | 2009-05-07 18:08:34 +0000 | [diff] [blame] | 71 | define 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 | |
Nick Lewycky | d4659ad | 2011-12-23 18:41:31 +0000 | [diff] [blame] | 78 | ; CHECK: define i32 @nc1(i32* %q, i32* nocapture %p, i1 %b) |
Duncan Sands | 1010941 | 2008-12-31 20:21:34 +0000 | [diff] [blame] | 79 | define i32 @nc1(i32* %q, i32* %p, i1 %b) { |
| 80 | e: |
| 81 | br label %l |
| 82 | l: |
| 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] |
Duncan Sands | 9e89ba3 | 2008-12-31 16:14:43 +0000 | [diff] [blame] | 88 | store i32 0, i32* %tmp |
Duncan Sands | 1010941 | 2008-12-31 20:21:34 +0000 | [diff] [blame] | 89 | store i32* %y, i32** @g |
Duncan Sands | 9e89ba3 | 2008-12-31 16:14:43 +0000 | [diff] [blame] | 90 | ret i32 %val |
| 91 | } |
| 92 | |
Nick Lewycky | d4659ad | 2011-12-23 18:41:31 +0000 | [diff] [blame] | 93 | ; CHECK: define void @nc2(i32* nocapture %p, i32* %q) |
Duncan Sands | 1010941 | 2008-12-31 20:21:34 +0000 | [diff] [blame] | 94 | define void @nc2(i32* %p, i32* %q) { |
| 95 | %1 = call i32 @nc1(i32* %q, i32* %p, i1 0) ; <i32> [#uses=0] |
Duncan Sands | 9e89ba3 | 2008-12-31 16:14:43 +0000 | [diff] [blame] | 96 | ret void |
| 97 | } |
| 98 | |
Nick Lewycky | d4659ad | 2011-12-23 18:41:31 +0000 | [diff] [blame] | 99 | ; CHECK: define void @nc3(void ()* nocapture %p) |
Duncan Sands | 1010941 | 2008-12-31 20:21:34 +0000 | [diff] [blame] | 100 | define void @nc3(void ()* %p) { |
| 101 | call void %p() |
Duncan Sands | 9e89ba3 | 2008-12-31 16:14:43 +0000 | [diff] [blame] | 102 | ret void |
| 103 | } |
Nick Lewycky | 6b05686 | 2009-01-02 03:46:56 +0000 | [diff] [blame] | 104 | |
Mike Stump | fe095f3 | 2009-05-04 18:40:41 +0000 | [diff] [blame] | 105 | declare void @external(i8*) readonly nounwind |
Nick Lewycky | d4659ad | 2011-12-23 18:41:31 +0000 | [diff] [blame] | 106 | ; CHECK: define void @nc4(i8* nocapture %p) |
Nick Lewycky | 6b05686 | 2009-01-02 03:46:56 +0000 | [diff] [blame] | 107 | define void @nc4(i8* %p) { |
| 108 | call void @external(i8* %p) |
| 109 | ret void |
| 110 | } |
| 111 | |
Nick Lewycky | d4659ad | 2011-12-23 18:41:31 +0000 | [diff] [blame] | 112 | ; CHECK: define void @nc5(void (i8*)* nocapture %f, i8* nocapture %p) |
Duncan Sands | 1978426 | 2009-05-07 18:08:34 +0000 | [diff] [blame] | 113 | define void @nc5(void (i8*)* %f, i8* %p) { |
| 114 | call void %f(i8* %p) readonly nounwind |
| 115 | call void %f(i8* nocapture %p) |
Nick Lewycky | 6b05686 | 2009-01-02 03:46:56 +0000 | [diff] [blame] | 116 | ret void |
| 117 | } |
Nick Lewycky | b48a189 | 2011-12-28 23:24:21 +0000 | [diff] [blame] | 118 | |
| 119 | ; CHECK: define void @test1_1(i8* nocapture %x1_1, i8* %y1_1) |
| 120 | define 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) |
| 127 | define 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) |
| 134 | define 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) |
| 141 | define 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) |
| 148 | define 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) |
| 155 | define 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 | |
| 161 | declare i8* @test5_1(i8* %x5_1) |
| 162 | |
| 163 | ; CHECK: define void @test5_2(i8* %x5_2) |
| 164 | define 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 | |
| 170 | declare 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) |
| 173 | define 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 | |