Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 1 | ; RUN: opt < %s -sroa -S | FileCheck %s |
Chandler Carruth | 43c8b46 | 2012-10-04 10:39:28 +0000 | [diff] [blame] | 2 | target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-n8:16:32:64" |
Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 3 | |
| 4 | define i32 @test1() { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame^] | 5 | ; CHECK-LABEL: @test1( |
Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 6 | entry: |
| 7 | %a = alloca [2 x i32] |
| 8 | ; CHECK-NOT: alloca |
| 9 | |
| 10 | %a0 = getelementptr [2 x i32]* %a, i64 0, i32 0 |
| 11 | %a1 = getelementptr [2 x i32]* %a, i64 0, i32 1 |
| 12 | store i32 0, i32* %a0 |
| 13 | store i32 1, i32* %a1 |
| 14 | %v0 = load i32* %a0 |
| 15 | %v1 = load i32* %a1 |
| 16 | ; CHECK-NOT: store |
| 17 | ; CHECK-NOT: load |
| 18 | |
| 19 | %cond = icmp sle i32 %v0, %v1 |
| 20 | br i1 %cond, label %then, label %exit |
| 21 | |
| 22 | then: |
| 23 | br label %exit |
| 24 | |
| 25 | exit: |
| 26 | %phi = phi i32* [ %a1, %then ], [ %a0, %entry ] |
| 27 | ; CHECK: phi i32 [ 1, %{{.*}} ], [ 0, %{{.*}} ] |
| 28 | |
| 29 | %result = load i32* %phi |
| 30 | ret i32 %result |
| 31 | } |
| 32 | |
| 33 | define i32 @test2() { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame^] | 34 | ; CHECK-LABEL: @test2( |
Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 35 | entry: |
| 36 | %a = alloca [2 x i32] |
| 37 | ; CHECK-NOT: alloca |
| 38 | |
| 39 | %a0 = getelementptr [2 x i32]* %a, i64 0, i32 0 |
| 40 | %a1 = getelementptr [2 x i32]* %a, i64 0, i32 1 |
| 41 | store i32 0, i32* %a0 |
| 42 | store i32 1, i32* %a1 |
| 43 | %v0 = load i32* %a0 |
| 44 | %v1 = load i32* %a1 |
| 45 | ; CHECK-NOT: store |
| 46 | ; CHECK-NOT: load |
| 47 | |
| 48 | %cond = icmp sle i32 %v0, %v1 |
| 49 | %select = select i1 %cond, i32* %a1, i32* %a0 |
| 50 | ; CHECK: select i1 %{{.*}}, i32 1, i32 0 |
| 51 | |
| 52 | %result = load i32* %select |
| 53 | ret i32 %result |
| 54 | } |
| 55 | |
| 56 | define i32 @test3(i32 %x) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame^] | 57 | ; CHECK-LABEL: @test3( |
Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 58 | entry: |
| 59 | %a = alloca [2 x i32] |
| 60 | ; CHECK-NOT: alloca |
| 61 | |
Chandler Carruth | 54e8f0b | 2012-10-01 01:49:22 +0000 | [diff] [blame] | 62 | ; Note that we build redundant GEPs here to ensure that having different GEPs |
| 63 | ; into the same alloca partation continues to work with PHI speculation. This |
| 64 | ; was the underlying cause of PR13926. |
Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 65 | %a0 = getelementptr [2 x i32]* %a, i64 0, i32 0 |
Chandler Carruth | 54e8f0b | 2012-10-01 01:49:22 +0000 | [diff] [blame] | 66 | %a0b = getelementptr [2 x i32]* %a, i64 0, i32 0 |
Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 67 | %a1 = getelementptr [2 x i32]* %a, i64 0, i32 1 |
Chandler Carruth | 54e8f0b | 2012-10-01 01:49:22 +0000 | [diff] [blame] | 68 | %a1b = getelementptr [2 x i32]* %a, i64 0, i32 1 |
Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 69 | store i32 0, i32* %a0 |
| 70 | store i32 1, i32* %a1 |
| 71 | ; CHECK-NOT: store |
| 72 | |
| 73 | switch i32 %x, label %bb0 [ i32 1, label %bb1 |
| 74 | i32 2, label %bb2 |
Chandler Carruth | 54e8f0b | 2012-10-01 01:49:22 +0000 | [diff] [blame] | 75 | i32 3, label %bb3 |
| 76 | i32 4, label %bb4 |
| 77 | i32 5, label %bb5 |
| 78 | i32 6, label %bb6 |
| 79 | i32 7, label %bb7 ] |
Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 80 | |
| 81 | bb0: |
| 82 | br label %exit |
| 83 | bb1: |
| 84 | br label %exit |
| 85 | bb2: |
| 86 | br label %exit |
| 87 | bb3: |
| 88 | br label %exit |
Chandler Carruth | 54e8f0b | 2012-10-01 01:49:22 +0000 | [diff] [blame] | 89 | bb4: |
| 90 | br label %exit |
| 91 | bb5: |
| 92 | br label %exit |
| 93 | bb6: |
| 94 | br label %exit |
| 95 | bb7: |
| 96 | br label %exit |
Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 97 | |
| 98 | exit: |
Chandler Carruth | 54e8f0b | 2012-10-01 01:49:22 +0000 | [diff] [blame] | 99 | %phi = phi i32* [ %a1, %bb0 ], [ %a0, %bb1 ], [ %a0, %bb2 ], [ %a1, %bb3 ], |
| 100 | [ %a1b, %bb4 ], [ %a0b, %bb5 ], [ %a0b, %bb6 ], [ %a1b, %bb7 ] |
| 101 | ; CHECK: phi i32 [ 1, %{{.*}} ], [ 0, %{{.*}} ], [ 0, %{{.*}} ], [ 1, %{{.*}} ], [ 1, %{{.*}} ], [ 0, %{{.*}} ], [ 0, %{{.*}} ], [ 1, %{{.*}} ] |
Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 102 | |
| 103 | %result = load i32* %phi |
| 104 | ret i32 %result |
| 105 | } |
| 106 | |
| 107 | define i32 @test4() { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame^] | 108 | ; CHECK-LABEL: @test4( |
Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 109 | entry: |
| 110 | %a = alloca [2 x i32] |
| 111 | ; CHECK-NOT: alloca |
| 112 | |
| 113 | %a0 = getelementptr [2 x i32]* %a, i64 0, i32 0 |
| 114 | %a1 = getelementptr [2 x i32]* %a, i64 0, i32 1 |
| 115 | store i32 0, i32* %a0 |
| 116 | store i32 1, i32* %a1 |
| 117 | %v0 = load i32* %a0 |
| 118 | %v1 = load i32* %a1 |
| 119 | ; CHECK-NOT: store |
| 120 | ; CHECK-NOT: load |
| 121 | |
| 122 | %cond = icmp sle i32 %v0, %v1 |
| 123 | %select = select i1 %cond, i32* %a0, i32* %a0 |
| 124 | ; CHECK-NOT: select |
| 125 | |
| 126 | %result = load i32* %select |
| 127 | ret i32 %result |
| 128 | ; CHECK: ret i32 0 |
| 129 | } |
| 130 | |
| 131 | define i32 @test5(i32* %b) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame^] | 132 | ; CHECK-LABEL: @test5( |
Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 133 | entry: |
| 134 | %a = alloca [2 x i32] |
| 135 | ; CHECK-NOT: alloca |
| 136 | |
| 137 | %a1 = getelementptr [2 x i32]* %a, i64 0, i32 1 |
| 138 | store i32 1, i32* %a1 |
| 139 | ; CHECK-NOT: store |
| 140 | |
| 141 | %select = select i1 true, i32* %a1, i32* %b |
| 142 | ; CHECK-NOT: select |
| 143 | |
| 144 | %result = load i32* %select |
| 145 | ; CHECK-NOT: load |
| 146 | |
| 147 | ret i32 %result |
| 148 | ; CHECK: ret i32 1 |
| 149 | } |
| 150 | |
Chandler Carruth | 225d4bd | 2012-09-21 23:36:40 +0000 | [diff] [blame] | 151 | declare void @f(i32*, i32*) |
Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 152 | |
| 153 | define i32 @test6(i32* %b) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame^] | 154 | ; CHECK-LABEL: @test6( |
Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 155 | entry: |
| 156 | %a = alloca [2 x i32] |
Chandler Carruth | 225d4bd | 2012-09-21 23:36:40 +0000 | [diff] [blame] | 157 | %c = alloca i32 |
| 158 | ; CHECK-NOT: alloca |
Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 159 | |
| 160 | %a1 = getelementptr [2 x i32]* %a, i64 0, i32 1 |
| 161 | store i32 1, i32* %a1 |
| 162 | |
| 163 | %select = select i1 true, i32* %a1, i32* %b |
| 164 | %select2 = select i1 false, i32* %a1, i32* %b |
Chandler Carruth | 225d4bd | 2012-09-21 23:36:40 +0000 | [diff] [blame] | 165 | %select3 = select i1 false, i32* %c, i32* %b |
| 166 | ; CHECK: %[[select2:.*]] = select i1 false, i32* undef, i32* %b |
| 167 | ; CHECK: %[[select3:.*]] = select i1 false, i32* undef, i32* %b |
Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 168 | |
| 169 | ; Note, this would potentially escape the alloca pointer except for the |
| 170 | ; constant folding of the select. |
Chandler Carruth | 225d4bd | 2012-09-21 23:36:40 +0000 | [diff] [blame] | 171 | call void @f(i32* %select2, i32* %select3) |
| 172 | ; CHECK: call void @f(i32* %[[select2]], i32* %[[select3]]) |
| 173 | |
Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 174 | |
| 175 | %result = load i32* %select |
| 176 | ; CHECK-NOT: load |
| 177 | |
Chandler Carruth | 225d4bd | 2012-09-21 23:36:40 +0000 | [diff] [blame] | 178 | %dead = load i32* %c |
| 179 | |
Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 180 | ret i32 %result |
| 181 | ; CHECK: ret i32 1 |
| 182 | } |
| 183 | |
| 184 | define i32 @test7() { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame^] | 185 | ; CHECK-LABEL: @test7( |
Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 186 | ; CHECK-NOT: alloca |
| 187 | |
| 188 | entry: |
| 189 | %X = alloca i32 |
| 190 | br i1 undef, label %good, label %bad |
| 191 | |
| 192 | good: |
| 193 | %Y1 = getelementptr i32* %X, i64 0 |
| 194 | store i32 0, i32* %Y1 |
| 195 | br label %exit |
| 196 | |
| 197 | bad: |
| 198 | %Y2 = getelementptr i32* %X, i64 1 |
| 199 | store i32 0, i32* %Y2 |
| 200 | br label %exit |
| 201 | |
| 202 | exit: |
| 203 | %P = phi i32* [ %Y1, %good ], [ %Y2, %bad ] |
| 204 | ; CHECK: %[[phi:.*]] = phi i32 [ 0, %good ], |
| 205 | %Z2 = load i32* %P |
| 206 | ret i32 %Z2 |
| 207 | ; CHECK: ret i32 %[[phi]] |
| 208 | } |
| 209 | |
| 210 | define i32 @test8(i32 %b, i32* %ptr) { |
| 211 | ; Ensure that we rewrite allocas to the used type when that use is hidden by |
| 212 | ; a PHI that can be speculated. |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame^] | 213 | ; CHECK-LABEL: @test8( |
Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 214 | ; CHECK-NOT: alloca |
| 215 | ; CHECK-NOT: load |
| 216 | ; CHECK: %[[value:.*]] = load i32* %ptr |
| 217 | ; CHECK-NOT: load |
| 218 | ; CHECK: %[[result:.*]] = phi i32 [ undef, %else ], [ %[[value]], %then ] |
| 219 | ; CHECK-NEXT: ret i32 %[[result]] |
| 220 | |
| 221 | entry: |
| 222 | %f = alloca float |
| 223 | %test = icmp ne i32 %b, 0 |
| 224 | br i1 %test, label %then, label %else |
| 225 | |
| 226 | then: |
| 227 | br label %exit |
| 228 | |
| 229 | else: |
| 230 | %bitcast = bitcast float* %f to i32* |
| 231 | br label %exit |
| 232 | |
| 233 | exit: |
| 234 | %phi = phi i32* [ %bitcast, %else ], [ %ptr, %then ] |
| 235 | %loaded = load i32* %phi, align 4 |
| 236 | ret i32 %loaded |
| 237 | } |
| 238 | |
| 239 | define i32 @test9(i32 %b, i32* %ptr) { |
| 240 | ; Same as @test8 but for a select rather than a PHI node. |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame^] | 241 | ; CHECK-LABEL: @test9( |
Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 242 | ; CHECK-NOT: alloca |
| 243 | ; CHECK-NOT: load |
| 244 | ; CHECK: %[[value:.*]] = load i32* %ptr |
| 245 | ; CHECK-NOT: load |
| 246 | ; CHECK: %[[result:.*]] = select i1 %{{.*}}, i32 undef, i32 %[[value]] |
| 247 | ; CHECK-NEXT: ret i32 %[[result]] |
| 248 | |
| 249 | entry: |
| 250 | %f = alloca float |
| 251 | store i32 0, i32* %ptr |
| 252 | %test = icmp ne i32 %b, 0 |
| 253 | %bitcast = bitcast float* %f to i32* |
| 254 | %select = select i1 %test, i32* %bitcast, i32* %ptr |
| 255 | %loaded = load i32* %select, align 4 |
| 256 | ret i32 %loaded |
| 257 | } |
| 258 | |
Chandler Carruth | 435c4e0 | 2012-10-15 08:40:30 +0000 | [diff] [blame] | 259 | define float @test10(i32 %b, float* %ptr) { |
Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 260 | ; Don't try to promote allocas which are not elligible for it even after |
| 261 | ; rewriting due to the necessity of inserting bitcasts when speculating a PHI |
| 262 | ; node. |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame^] | 263 | ; CHECK-LABEL: @test10( |
Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 264 | ; CHECK: %[[alloca:.*]] = alloca |
Chandler Carruth | 435c4e0 | 2012-10-15 08:40:30 +0000 | [diff] [blame] | 265 | ; CHECK: %[[argvalue:.*]] = load float* %ptr |
| 266 | ; CHECK: %[[cast:.*]] = bitcast double* %[[alloca]] to float* |
| 267 | ; CHECK: %[[allocavalue:.*]] = load float* %[[cast]] |
| 268 | ; CHECK: %[[result:.*]] = phi float [ %[[allocavalue]], %else ], [ %[[argvalue]], %then ] |
| 269 | ; CHECK-NEXT: ret float %[[result]] |
Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 270 | |
| 271 | entry: |
| 272 | %f = alloca double |
| 273 | store double 0.0, double* %f |
| 274 | %test = icmp ne i32 %b, 0 |
| 275 | br i1 %test, label %then, label %else |
| 276 | |
| 277 | then: |
| 278 | br label %exit |
| 279 | |
| 280 | else: |
Chandler Carruth | 435c4e0 | 2012-10-15 08:40:30 +0000 | [diff] [blame] | 281 | %bitcast = bitcast double* %f to float* |
Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 282 | br label %exit |
| 283 | |
| 284 | exit: |
Chandler Carruth | 435c4e0 | 2012-10-15 08:40:30 +0000 | [diff] [blame] | 285 | %phi = phi float* [ %bitcast, %else ], [ %ptr, %then ] |
| 286 | %loaded = load float* %phi, align 4 |
| 287 | ret float %loaded |
Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 288 | } |
| 289 | |
Chandler Carruth | 435c4e0 | 2012-10-15 08:40:30 +0000 | [diff] [blame] | 290 | define float @test11(i32 %b, float* %ptr) { |
Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 291 | ; Same as @test10 but for a select rather than a PHI node. |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame^] | 292 | ; CHECK-LABEL: @test11( |
Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 293 | ; CHECK: %[[alloca:.*]] = alloca |
Chandler Carruth | 435c4e0 | 2012-10-15 08:40:30 +0000 | [diff] [blame] | 294 | ; CHECK: %[[cast:.*]] = bitcast double* %[[alloca]] to float* |
| 295 | ; CHECK: %[[allocavalue:.*]] = load float* %[[cast]] |
| 296 | ; CHECK: %[[argvalue:.*]] = load float* %ptr |
| 297 | ; CHECK: %[[result:.*]] = select i1 %{{.*}}, float %[[allocavalue]], float %[[argvalue]] |
| 298 | ; CHECK-NEXT: ret float %[[result]] |
Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 299 | |
| 300 | entry: |
| 301 | %f = alloca double |
| 302 | store double 0.0, double* %f |
Chandler Carruth | 435c4e0 | 2012-10-15 08:40:30 +0000 | [diff] [blame] | 303 | store float 0.0, float* %ptr |
Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 304 | %test = icmp ne i32 %b, 0 |
Chandler Carruth | 435c4e0 | 2012-10-15 08:40:30 +0000 | [diff] [blame] | 305 | %bitcast = bitcast double* %f to float* |
| 306 | %select = select i1 %test, float* %bitcast, float* %ptr |
| 307 | %loaded = load float* %select, align 4 |
| 308 | ret float %loaded |
Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | define i32 @test12(i32 %x, i32* %p) { |
| 312 | ; Ensure we don't crash or fail to nuke dead selects of allocas if no load is |
| 313 | ; never found. |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame^] | 314 | ; CHECK-LABEL: @test12( |
Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 315 | ; CHECK-NOT: alloca |
| 316 | ; CHECK-NOT: select |
| 317 | ; CHECK: ret i32 %x |
| 318 | |
| 319 | entry: |
| 320 | %a = alloca i32 |
| 321 | store i32 %x, i32* %a |
| 322 | %dead = select i1 undef, i32* %a, i32* %p |
| 323 | %load = load i32* %a |
| 324 | ret i32 %load |
| 325 | } |
| 326 | |
| 327 | define i32 @test13(i32 %x, i32* %p) { |
| 328 | ; Ensure we don't crash or fail to nuke dead phis of allocas if no load is ever |
| 329 | ; found. |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame^] | 330 | ; CHECK-LABEL: @test13( |
Chandler Carruth | 1b398ae | 2012-09-14 09:22:59 +0000 | [diff] [blame] | 331 | ; CHECK-NOT: alloca |
| 332 | ; CHECK-NOT: phi |
| 333 | ; CHECK: ret i32 %x |
| 334 | |
| 335 | entry: |
| 336 | %a = alloca i32 |
| 337 | store i32 %x, i32* %a |
| 338 | br label %loop |
| 339 | |
| 340 | loop: |
| 341 | %phi = phi i32* [ %p, %entry ], [ %a, %loop ] |
| 342 | br i1 undef, label %loop, label %exit |
| 343 | |
| 344 | exit: |
| 345 | %load = load i32* %a |
| 346 | ret i32 %load |
| 347 | } |
Chandler Carruth | 8b907e8 | 2012-09-25 10:03:40 +0000 | [diff] [blame] | 348 | |
| 349 | define i32 @PR13905() { |
| 350 | ; Check a pattern where we have a chain of dead phi nodes to ensure they are |
| 351 | ; deleted and promotion can proceed. |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame^] | 352 | ; CHECK-LABEL: @PR13905( |
Chandler Carruth | 8b907e8 | 2012-09-25 10:03:40 +0000 | [diff] [blame] | 353 | ; CHECK-NOT: alloca i32 |
| 354 | ; CHECK: ret i32 undef |
| 355 | |
| 356 | entry: |
| 357 | %h = alloca i32 |
| 358 | store i32 0, i32* %h |
| 359 | br i1 undef, label %loop1, label %exit |
| 360 | |
| 361 | loop1: |
| 362 | %phi1 = phi i32* [ null, %entry ], [ %h, %loop1 ], [ %h, %loop2 ] |
| 363 | br i1 undef, label %loop1, label %loop2 |
| 364 | |
| 365 | loop2: |
| 366 | br i1 undef, label %loop1, label %exit |
| 367 | |
| 368 | exit: |
| 369 | %phi2 = phi i32* [ %phi1, %loop2 ], [ null, %entry ] |
| 370 | ret i32 undef |
| 371 | } |
| 372 | |
| 373 | define i32 @PR13906() { |
| 374 | ; Another pattern which can lead to crashes due to failing to clear out dead |
| 375 | ; PHI nodes or select nodes. This triggers subtly differently from the above |
| 376 | ; cases because the PHI node is (recursively) alive, but the select is dead. |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame^] | 377 | ; CHECK-LABEL: @PR13906( |
Chandler Carruth | 8b907e8 | 2012-09-25 10:03:40 +0000 | [diff] [blame] | 378 | ; CHECK-NOT: alloca |
| 379 | |
| 380 | entry: |
| 381 | %c = alloca i32 |
| 382 | store i32 0, i32* %c |
| 383 | br label %for.cond |
| 384 | |
| 385 | for.cond: |
| 386 | %d.0 = phi i32* [ undef, %entry ], [ %c, %if.then ], [ %d.0, %for.cond ] |
| 387 | br i1 undef, label %if.then, label %for.cond |
| 388 | |
| 389 | if.then: |
| 390 | %tmpcast.d.0 = select i1 undef, i32* %c, i32* %d.0 |
| 391 | br label %for.cond |
| 392 | } |
Chandler Carruth | 3e994a2 | 2012-11-20 10:02:19 +0000 | [diff] [blame] | 393 | |
| 394 | define i64 @PR14132(i1 %flag) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame^] | 395 | ; CHECK-LABEL: @PR14132( |
Chandler Carruth | 3e994a2 | 2012-11-20 10:02:19 +0000 | [diff] [blame] | 396 | ; Here we form a PHI-node by promoting the pointer alloca first, and then in |
| 397 | ; order to promote the other two allocas, we speculate the load of the |
| 398 | ; now-phi-node-pointer. In doing so we end up loading a 64-bit value from an i8 |
Chandler Carruth | a1c54bb | 2013-03-14 11:32:24 +0000 | [diff] [blame] | 399 | ; alloca. While this is a bit dubious, we were asserting on trying to |
| 400 | ; rewrite it. The trick is that the code using the value may carefully take |
| 401 | ; steps to only use the not-undef bits, and so we need to at least loosely |
| 402 | ; support this.. |
Chandler Carruth | 3e994a2 | 2012-11-20 10:02:19 +0000 | [diff] [blame] | 403 | entry: |
| 404 | %a = alloca i64 |
| 405 | %b = alloca i8 |
| 406 | %ptr = alloca i64* |
| 407 | ; CHECK-NOT: alloca |
| 408 | |
| 409 | %ptr.cast = bitcast i64** %ptr to i8** |
| 410 | store i64 0, i64* %a |
| 411 | store i8 1, i8* %b |
| 412 | store i64* %a, i64** %ptr |
| 413 | br i1 %flag, label %if.then, label %if.end |
| 414 | |
| 415 | if.then: |
| 416 | store i8* %b, i8** %ptr.cast |
| 417 | br label %if.end |
Chandler Carruth | a1c54bb | 2013-03-14 11:32:24 +0000 | [diff] [blame] | 418 | ; CHECK-NOT: store |
| 419 | ; CHECK: %[[ext:.*]] = zext i8 1 to i64 |
Chandler Carruth | 3e994a2 | 2012-11-20 10:02:19 +0000 | [diff] [blame] | 420 | |
| 421 | if.end: |
| 422 | %tmp = load i64** %ptr |
| 423 | %result = load i64* %tmp |
Chandler Carruth | 3e994a2 | 2012-11-20 10:02:19 +0000 | [diff] [blame] | 424 | ; CHECK-NOT: load |
Chandler Carruth | a1c54bb | 2013-03-14 11:32:24 +0000 | [diff] [blame] | 425 | ; CHECK: %[[result:.*]] = phi i64 [ %[[ext]], %if.then ], [ 0, %entry ] |
Chandler Carruth | 3e994a2 | 2012-11-20 10:02:19 +0000 | [diff] [blame] | 426 | |
| 427 | ret i64 %result |
| 428 | ; CHECK-NEXT: ret i64 %[[result]] |
| 429 | } |