Nick Lewycky | 854c869 | 2011-12-23 18:41:31 +0000 | [diff] [blame] | 1 | ; RUN: opt < %s -functionattrs -S | FileCheck %s |
Duncan Sands | 44c8cd9 | 2008-12-31 16:14:43 +0000 | [diff] [blame] | 2 | @g = global i32* null ; <i32**> [#uses=1] |
| 3 | |
Nick Lewycky | c2ec072 | 2013-07-06 00:29:58 +0000 | [diff] [blame] | 4 | ; CHECK: define i32* @c1(i32* readnone %q) |
Duncan Sands | 1638480 | 2008-12-31 20:21:34 +0000 | [diff] [blame] | 5 | define i32* @c1(i32* %q) { |
| 6 | ret i32* %q |
Duncan Sands | 44c8cd9 | 2008-12-31 16:14:43 +0000 | [diff] [blame] | 7 | } |
| 8 | |
Nick Lewycky | 854c869 | 2011-12-23 18:41:31 +0000 | [diff] [blame] | 9 | ; CHECK: define void @c2(i32* %q) |
Nick Lewycky | c2ec072 | 2013-07-06 00:29:58 +0000 | [diff] [blame] | 10 | ; It would also be acceptable to mark %q as readnone. Update @c3 too. |
Duncan Sands | 1638480 | 2008-12-31 20:21:34 +0000 | [diff] [blame] | 11 | define void @c2(i32* %q) { |
| 12 | store i32* %q, i32** @g |
Duncan Sands | 44c8cd9 | 2008-12-31 16:14:43 +0000 | [diff] [blame] | 13 | ret void |
| 14 | } |
| 15 | |
Nick Lewycky | 854c869 | 2011-12-23 18:41:31 +0000 | [diff] [blame] | 16 | ; CHECK: define void @c3(i32* %q) |
Duncan Sands | 1638480 | 2008-12-31 20:21:34 +0000 | [diff] [blame] | 17 | define void @c3(i32* %q) { |
| 18 | call void @c2(i32* %q) |
Duncan Sands | 44c8cd9 | 2008-12-31 16:14:43 +0000 | [diff] [blame] | 19 | ret void |
| 20 | } |
| 21 | |
Nick Lewycky | 854c869 | 2011-12-23 18:41:31 +0000 | [diff] [blame] | 22 | ; CHECK: define i1 @c4(i32* %q, i32 %bitno) |
Duncan Sands | 8c03a12 | 2009-01-02 00:55:51 +0000 | [diff] [blame] | 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 | |
Nick Lewycky | 854c869 | 2011-12-23 18:41:31 +0000 | [diff] [blame] | 36 | ; CHECK: define i1 @c5(i32* %q, i32 %bitno) |
Duncan Sands | 8c03a12 | 2009-01-02 00:55:51 +0000 | [diff] [blame] | 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 | |
Duncan Sands | 50c7033 | 2009-05-04 16:50:29 +0000 | [diff] [blame] | 47 | declare void @throw_if_bit_set(i8*, i8) readonly |
Nick Lewycky | 854c869 | 2011-12-23 18:41:31 +0000 | [diff] [blame] | 48 | |
Nick Lewycky | c2ec072 | 2013-07-06 00:29:58 +0000 | [diff] [blame] | 49 | ; CHECK: define i1 @c6(i8* readonly %q, i8 %bit) |
Duncan Sands | 50c7033 | 2009-05-04 16:50:29 +0000 | [diff] [blame] | 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: |
Bill Wendling | e88632d | 2011-09-01 00:58:03 +0000 | [diff] [blame] | 56 | %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0 |
| 57 | cleanup |
Duncan Sands | 50c7033 | 2009-05-04 16:50:29 +0000 | [diff] [blame] | 58 | ret i1 1 |
| 59 | } |
| 60 | |
Bill Wendling | e88632d | 2011-09-01 00:58:03 +0000 | [diff] [blame] | 61 | declare i32 @__gxx_personality_v0(...) |
| 62 | |
Duncan Sands | 7a8cfaf | 2009-05-07 18:08:34 +0000 | [diff] [blame] | 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 | |
Nick Lewycky | c2ec072 | 2013-07-06 00:29:58 +0000 | [diff] [blame] | 71 | ; CHECK: define i1 @c7(i32* readnone %q, i32 %bitno) |
Duncan Sands | 7a8cfaf | 2009-05-07 18:08:34 +0000 | [diff] [blame] | 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 | |
Nick Lewycky | 854c869 | 2011-12-23 18:41:31 +0000 | [diff] [blame] | 79 | ; CHECK: define i32 @nc1(i32* %q, i32* nocapture %p, i1 %b) |
Duncan Sands | 1638480 | 2008-12-31 20:21:34 +0000 | [diff] [blame] | 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] |
Duncan Sands | 44c8cd9 | 2008-12-31 16:14:43 +0000 | [diff] [blame] | 89 | store i32 0, i32* %tmp |
Duncan Sands | 1638480 | 2008-12-31 20:21:34 +0000 | [diff] [blame] | 90 | store i32* %y, i32** @g |
Duncan Sands | 44c8cd9 | 2008-12-31 16:14:43 +0000 | [diff] [blame] | 91 | ret i32 %val |
| 92 | } |
| 93 | |
Matt Arsenault | e55a2c2 | 2014-01-14 19:11:52 +0000 | [diff] [blame^] | 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) { |
| 96 | e: |
| 97 | br label %l |
| 98 | l: |
| 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 |
| 106 | ret i32 %val |
| 107 | } |
| 108 | |
Nick Lewycky | 854c869 | 2011-12-23 18:41:31 +0000 | [diff] [blame] | 109 | ; CHECK: define void @nc2(i32* nocapture %p, i32* %q) |
Duncan Sands | 1638480 | 2008-12-31 20:21:34 +0000 | [diff] [blame] | 110 | define void @nc2(i32* %p, i32* %q) { |
| 111 | %1 = call i32 @nc1(i32* %q, i32* %p, i1 0) ; <i32> [#uses=0] |
Duncan Sands | 44c8cd9 | 2008-12-31 16:14:43 +0000 | [diff] [blame] | 112 | ret void |
| 113 | } |
| 114 | |
Nick Lewycky | 854c869 | 2011-12-23 18:41:31 +0000 | [diff] [blame] | 115 | ; CHECK: define void @nc3(void ()* nocapture %p) |
Duncan Sands | 1638480 | 2008-12-31 20:21:34 +0000 | [diff] [blame] | 116 | define void @nc3(void ()* %p) { |
| 117 | call void %p() |
Duncan Sands | 44c8cd9 | 2008-12-31 16:14:43 +0000 | [diff] [blame] | 118 | ret void |
| 119 | } |
Nick Lewycky | 7e82055 | 2009-01-02 03:46:56 +0000 | [diff] [blame] | 120 | |
Duncan Sands | 50c7033 | 2009-05-04 16:50:29 +0000 | [diff] [blame] | 121 | declare void @external(i8*) readonly nounwind |
Nick Lewycky | c2ec072 | 2013-07-06 00:29:58 +0000 | [diff] [blame] | 122 | ; CHECK: define void @nc4(i8* nocapture readonly %p) |
Nick Lewycky | 7e82055 | 2009-01-02 03:46:56 +0000 | [diff] [blame] | 123 | define void @nc4(i8* %p) { |
| 124 | call void @external(i8* %p) |
| 125 | ret void |
| 126 | } |
| 127 | |
Nick Lewycky | 854c869 | 2011-12-23 18:41:31 +0000 | [diff] [blame] | 128 | ; CHECK: define void @nc5(void (i8*)* nocapture %f, i8* nocapture %p) |
Duncan Sands | 7a8cfaf | 2009-05-07 18:08:34 +0000 | [diff] [blame] | 129 | define void @nc5(void (i8*)* %f, i8* %p) { |
| 130 | call void %f(i8* %p) readonly nounwind |
| 131 | call void %f(i8* nocapture %p) |
Nick Lewycky | 7e82055 | 2009-01-02 03:46:56 +0000 | [diff] [blame] | 132 | ret void |
| 133 | } |
Nick Lewycky | 4c378a4 | 2011-12-28 23:24:21 +0000 | [diff] [blame] | 134 | |
Nick Lewycky | c2ec072 | 2013-07-06 00:29:58 +0000 | [diff] [blame] | 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. |
Nick Lewycky | 4c378a4 | 2011-12-28 23:24:21 +0000 | [diff] [blame] | 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 |
| 140 | ret void |
| 141 | } |
| 142 | |
Nick Lewycky | c2ec072 | 2013-07-06 00:29:58 +0000 | [diff] [blame] | 143 | ; CHECK: define i8* @test1_2(i8* nocapture readnone %x1_2, i8* %y1_2) |
Nick Lewycky | 4c378a4 | 2011-12-28 23:24:21 +0000 | [diff] [blame] | 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 |
| 147 | ret i8* %y1_2 |
| 148 | } |
| 149 | |
Nick Lewycky | c2ec072 | 2013-07-06 00:29:58 +0000 | [diff] [blame] | 150 | ; CHECK: define void @test2(i8* nocapture readnone %x2) |
Nick Lewycky | 4c378a4 | 2011-12-28 23:24:21 +0000 | [diff] [blame] | 151 | define void @test2(i8* %x2) { |
| 152 | call void @test2(i8* %x2) |
| 153 | store i32* null, i32** @g |
| 154 | ret void |
| 155 | } |
| 156 | |
Nick Lewycky | c2ec072 | 2013-07-06 00:29:58 +0000 | [diff] [blame] | 157 | ; CHECK: define void @test3(i8* nocapture readnone %x3, i8* nocapture readnone %y3, i8* nocapture readnone %z3) |
Nick Lewycky | 4c378a4 | 2011-12-28 23:24:21 +0000 | [diff] [blame] | 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 |
| 161 | ret void |
| 162 | } |
| 163 | |
| 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 |
| 168 | ret void |
| 169 | } |
| 170 | |
Nick Lewycky | c2ec072 | 2013-07-06 00:29:58 +0000 | [diff] [blame] | 171 | ; CHECK: define i8* @test4_2(i8* nocapture readnone %x4_2, i8* readnone %y4_2, i8* nocapture readnone %z4_2) |
Nick Lewycky | 4c378a4 | 2011-12-28 23:24:21 +0000 | [diff] [blame] | 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 |
| 175 | ret i8* %y4_2 |
| 176 | } |
| 177 | |
| 178 | declare i8* @test5_1(i8* %x5_1) |
| 179 | |
| 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 |
| 184 | ret void |
| 185 | } |
| 186 | |
| 187 | declare 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) |
| 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 |
| 193 | ret void |
| 194 | } |
| 195 | |