1; RUN: opt < %s -sroa -S | FileCheck %s 2target 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" 3 4define i32 @test1() { 5; CHECK-LABEL: @test1( 6entry: 7 %a = alloca [2 x i32] 8; CHECK-NOT: alloca 9 10 %a0 = getelementptr [2 x i32], [2 x i32]* %a, i64 0, i32 0 11 %a1 = getelementptr [2 x i32], [2 x i32]* %a, i64 0, i32 1 12 store i32 0, i32* %a0 13 store i32 1, i32* %a1 14 %v0 = load i32, i32* %a0 15 %v1 = load i32, 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 22then: 23 br label %exit 24 25exit: 26 %phi = phi i32* [ %a1, %then ], [ %a0, %entry ] 27; CHECK: phi i32 [ 1, %{{.*}} ], [ 0, %{{.*}} ] 28 29 %result = load i32, i32* %phi 30 ret i32 %result 31} 32 33define i32 @test2() { 34; CHECK-LABEL: @test2( 35entry: 36 %a = alloca [2 x i32] 37; CHECK-NOT: alloca 38 39 %a0 = getelementptr [2 x i32], [2 x i32]* %a, i64 0, i32 0 40 %a1 = getelementptr [2 x i32], [2 x i32]* %a, i64 0, i32 1 41 store i32 0, i32* %a0 42 store i32 1, i32* %a1 43 %v0 = load i32, i32* %a0 44 %v1 = load i32, 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, i32* %select 53 ret i32 %result 54} 55 56; If bitcast isn't considered a safe phi/select use, the alloca 57; remains as an array. 58; FIXME: Why isn't this identical to test2? 59 60; CHECK-LABEL: @test2_bitcast( 61; CHECK: alloca i32 62; CHECK-NEXT: alloca i32 63 64; CHECK: %select = select i1 %cond, i32* %a.sroa.3, i32* %a.sroa.0 65; CHECK-NEXT: %select.bc = bitcast i32* %select to float* 66; CHECK-NEXT: %result = load float, float* %select.bc, align 4 67define float @test2_bitcast() { 68entry: 69 %a = alloca [2 x i32] 70 %a0 = getelementptr [2 x i32], [2 x i32]* %a, i64 0, i32 0 71 %a1 = getelementptr [2 x i32], [2 x i32]* %a, i64 0, i32 1 72 store i32 0, i32* %a0 73 store i32 1, i32* %a1 74 %v0 = load i32, i32* %a0 75 %v1 = load i32, i32* %a1 76 %cond = icmp sle i32 %v0, %v1 77 %select = select i1 %cond, i32* %a1, i32* %a0 78 %select.bc = bitcast i32* %select to float* 79 %result = load float, float* %select.bc 80 ret float %result 81} 82 83; CHECK-LABEL: @test2_addrspacecast( 84; CHECK: alloca i32 85; CHECK-NEXT: alloca i32 86 87; CHECK: %select = select i1 %cond, i32* %a.sroa.3, i32* %a.sroa.0 88; CHECK-NEXT: %select.asc = addrspacecast i32* %select to i32 addrspace(1)* 89; CHECK-NEXT: load i32, i32 addrspace(1)* %select.asc, align 4 90define i32 @test2_addrspacecast() { 91entry: 92 %a = alloca [2 x i32] 93 %a0 = getelementptr [2 x i32], [2 x i32]* %a, i64 0, i32 0 94 %a1 = getelementptr [2 x i32], [2 x i32]* %a, i64 0, i32 1 95 store i32 0, i32* %a0 96 store i32 1, i32* %a1 97 %v0 = load i32, i32* %a0 98 %v1 = load i32, i32* %a1 99 %cond = icmp sle i32 %v0, %v1 100 %select = select i1 %cond, i32* %a1, i32* %a0 101 %select.asc = addrspacecast i32* %select to i32 addrspace(1)* 102 %result = load i32, i32 addrspace(1)* %select.asc 103 ret i32 %result 104} 105 106define i32 @test3(i32 %x) { 107; CHECK-LABEL: @test3( 108entry: 109 %a = alloca [2 x i32] 110; CHECK-NOT: alloca 111 112 ; Note that we build redundant GEPs here to ensure that having different GEPs 113 ; into the same alloca partation continues to work with PHI speculation. This 114 ; was the underlying cause of PR13926. 115 %a0 = getelementptr [2 x i32], [2 x i32]* %a, i64 0, i32 0 116 %a0b = getelementptr [2 x i32], [2 x i32]* %a, i64 0, i32 0 117 %a1 = getelementptr [2 x i32], [2 x i32]* %a, i64 0, i32 1 118 %a1b = getelementptr [2 x i32], [2 x i32]* %a, i64 0, i32 1 119 store i32 0, i32* %a0 120 store i32 1, i32* %a1 121; CHECK-NOT: store 122 123 switch i32 %x, label %bb0 [ i32 1, label %bb1 124 i32 2, label %bb2 125 i32 3, label %bb3 126 i32 4, label %bb4 127 i32 5, label %bb5 128 i32 6, label %bb6 129 i32 7, label %bb7 ] 130 131bb0: 132 br label %exit 133bb1: 134 br label %exit 135bb2: 136 br label %exit 137bb3: 138 br label %exit 139bb4: 140 br label %exit 141bb5: 142 br label %exit 143bb6: 144 br label %exit 145bb7: 146 br label %exit 147 148exit: 149 %phi = phi i32* [ %a1, %bb0 ], [ %a0, %bb1 ], [ %a0, %bb2 ], [ %a1, %bb3 ], 150 [ %a1b, %bb4 ], [ %a0b, %bb5 ], [ %a0b, %bb6 ], [ %a1b, %bb7 ] 151; CHECK: phi i32 [ 1, %{{.*}} ], [ 0, %{{.*}} ], [ 0, %{{.*}} ], [ 1, %{{.*}} ], [ 1, %{{.*}} ], [ 0, %{{.*}} ], [ 0, %{{.*}} ], [ 1, %{{.*}} ] 152 153 %result = load i32, i32* %phi 154 ret i32 %result 155} 156 157define i32 @test4() { 158; CHECK-LABEL: @test4( 159entry: 160 %a = alloca [2 x i32] 161; CHECK-NOT: alloca 162 163 %a0 = getelementptr [2 x i32], [2 x i32]* %a, i64 0, i32 0 164 %a1 = getelementptr [2 x i32], [2 x i32]* %a, i64 0, i32 1 165 store i32 0, i32* %a0 166 store i32 1, i32* %a1 167 %v0 = load i32, i32* %a0 168 %v1 = load i32, i32* %a1 169; CHECK-NOT: store 170; CHECK-NOT: load 171 172 %cond = icmp sle i32 %v0, %v1 173 %select = select i1 %cond, i32* %a0, i32* %a0 174; CHECK-NOT: select 175 176 %result = load i32, i32* %select 177 ret i32 %result 178; CHECK: ret i32 0 179} 180 181define i32 @test5(i32* %b) { 182; CHECK-LABEL: @test5( 183entry: 184 %a = alloca [2 x i32] 185; CHECK-NOT: alloca 186 187 %a1 = getelementptr [2 x i32], [2 x i32]* %a, i64 0, i32 1 188 store i32 1, i32* %a1 189; CHECK-NOT: store 190 191 %select = select i1 true, i32* %a1, i32* %b 192; CHECK-NOT: select 193 194 %result = load i32, i32* %select 195; CHECK-NOT: load 196 197 ret i32 %result 198; CHECK: ret i32 1 199} 200 201declare void @f(i32*, i32*) 202 203define i32 @test6(i32* %b) { 204; CHECK-LABEL: @test6( 205entry: 206 %a = alloca [2 x i32] 207 %c = alloca i32 208; CHECK-NOT: alloca 209 210 %a1 = getelementptr [2 x i32], [2 x i32]* %a, i64 0, i32 1 211 store i32 1, i32* %a1 212 213 %select = select i1 true, i32* %a1, i32* %b 214 %select2 = select i1 false, i32* %a1, i32* %b 215 %select3 = select i1 false, i32* %c, i32* %b 216; CHECK: %[[select2:.*]] = select i1 false, i32* undef, i32* %b 217; CHECK: %[[select3:.*]] = select i1 false, i32* undef, i32* %b 218 219 ; Note, this would potentially escape the alloca pointer except for the 220 ; constant folding of the select. 221 call void @f(i32* %select2, i32* %select3) 222; CHECK: call void @f(i32* %[[select2]], i32* %[[select3]]) 223 224 225 %result = load i32, i32* %select 226; CHECK-NOT: load 227 228 %dead = load i32, i32* %c 229 230 ret i32 %result 231; CHECK: ret i32 1 232} 233 234define i32 @test7() { 235; CHECK-LABEL: @test7( 236; CHECK-NOT: alloca 237 238entry: 239 %X = alloca i32 240 br i1 undef, label %good, label %bad 241 242good: 243 %Y1 = getelementptr i32, i32* %X, i64 0 244 store i32 0, i32* %Y1 245 br label %exit 246 247bad: 248 %Y2 = getelementptr i32, i32* %X, i64 1 249 store i32 0, i32* %Y2 250 br label %exit 251 252exit: 253 %P = phi i32* [ %Y1, %good ], [ %Y2, %bad ] 254; CHECK: %[[phi:.*]] = phi i32 [ 0, %good ], 255 %Z2 = load i32, i32* %P 256 ret i32 %Z2 257; CHECK: ret i32 %[[phi]] 258} 259 260define i32 @test8(i32 %b, i32* %ptr) { 261; Ensure that we rewrite allocas to the used type when that use is hidden by 262; a PHI that can be speculated. 263; CHECK-LABEL: @test8( 264; CHECK-NOT: alloca 265; CHECK-NOT: load 266; CHECK: %[[value:.*]] = load i32, i32* %ptr 267; CHECK-NOT: load 268; CHECK: %[[result:.*]] = phi i32 [ undef, %else ], [ %[[value]], %then ] 269; CHECK-NEXT: ret i32 %[[result]] 270 271entry: 272 %f = alloca float 273 %test = icmp ne i32 %b, 0 274 br i1 %test, label %then, label %else 275 276then: 277 br label %exit 278 279else: 280 %bitcast = bitcast float* %f to i32* 281 br label %exit 282 283exit: 284 %phi = phi i32* [ %bitcast, %else ], [ %ptr, %then ] 285 %loaded = load i32, i32* %phi, align 4 286 ret i32 %loaded 287} 288 289define i32 @test9(i32 %b, i32* %ptr) { 290; Same as @test8 but for a select rather than a PHI node. 291; CHECK-LABEL: @test9( 292; CHECK-NOT: alloca 293; CHECK-NOT: load 294; CHECK: %[[value:.*]] = load i32, i32* %ptr 295; CHECK-NOT: load 296; CHECK: %[[result:.*]] = select i1 %{{.*}}, i32 undef, i32 %[[value]] 297; CHECK-NEXT: ret i32 %[[result]] 298 299entry: 300 %f = alloca float 301 store i32 0, i32* %ptr 302 %test = icmp ne i32 %b, 0 303 %bitcast = bitcast float* %f to i32* 304 %select = select i1 %test, i32* %bitcast, i32* %ptr 305 %loaded = load i32, i32* %select, align 4 306 ret i32 %loaded 307} 308 309define float @test10(i32 %b, float* %ptr) { 310; Don't try to promote allocas which are not elligible for it even after 311; rewriting due to the necessity of inserting bitcasts when speculating a PHI 312; node. 313; CHECK-LABEL: @test10( 314; CHECK: %[[alloca:.*]] = alloca 315; CHECK: %[[argvalue:.*]] = load float, float* %ptr 316; CHECK: %[[cast:.*]] = bitcast double* %[[alloca]] to float* 317; CHECK: %[[allocavalue:.*]] = load float, float* %[[cast]] 318; CHECK: %[[result:.*]] = phi float [ %[[allocavalue]], %else ], [ %[[argvalue]], %then ] 319; CHECK-NEXT: ret float %[[result]] 320 321entry: 322 %f = alloca double 323 store double 0.0, double* %f 324 %test = icmp ne i32 %b, 0 325 br i1 %test, label %then, label %else 326 327then: 328 br label %exit 329 330else: 331 %bitcast = bitcast double* %f to float* 332 br label %exit 333 334exit: 335 %phi = phi float* [ %bitcast, %else ], [ %ptr, %then ] 336 %loaded = load float, float* %phi, align 4 337 ret float %loaded 338} 339 340define float @test11(i32 %b, float* %ptr) { 341; Same as @test10 but for a select rather than a PHI node. 342; CHECK-LABEL: @test11( 343; CHECK: %[[alloca:.*]] = alloca 344; CHECK: %[[cast:.*]] = bitcast double* %[[alloca]] to float* 345; CHECK: %[[allocavalue:.*]] = load float, float* %[[cast]] 346; CHECK: %[[argvalue:.*]] = load float, float* %ptr 347; CHECK: %[[result:.*]] = select i1 %{{.*}}, float %[[allocavalue]], float %[[argvalue]] 348; CHECK-NEXT: ret float %[[result]] 349 350entry: 351 %f = alloca double 352 store double 0.0, double* %f 353 store float 0.0, float* %ptr 354 %test = icmp ne i32 %b, 0 355 %bitcast = bitcast double* %f to float* 356 %select = select i1 %test, float* %bitcast, float* %ptr 357 %loaded = load float, float* %select, align 4 358 ret float %loaded 359} 360 361define i32 @test12(i32 %x, i32* %p) { 362; Ensure we don't crash or fail to nuke dead selects of allocas if no load is 363; never found. 364; CHECK-LABEL: @test12( 365; CHECK-NOT: alloca 366; CHECK-NOT: select 367; CHECK: ret i32 %x 368 369entry: 370 %a = alloca i32 371 store i32 %x, i32* %a 372 %dead = select i1 undef, i32* %a, i32* %p 373 %load = load i32, i32* %a 374 ret i32 %load 375} 376 377define i32 @test13(i32 %x, i32* %p) { 378; Ensure we don't crash or fail to nuke dead phis of allocas if no load is ever 379; found. 380; CHECK-LABEL: @test13( 381; CHECK-NOT: alloca 382; CHECK-NOT: phi 383; CHECK: ret i32 %x 384 385entry: 386 %a = alloca i32 387 store i32 %x, i32* %a 388 br label %loop 389 390loop: 391 %phi = phi i32* [ %p, %entry ], [ %a, %loop ] 392 br i1 undef, label %loop, label %exit 393 394exit: 395 %load = load i32, i32* %a 396 ret i32 %load 397} 398 399define i32 @test14(i1 %b1, i1 %b2, i32* %ptr) { 400; Check for problems when there are both selects and phis and one is 401; speculatable toward promotion but the other is not. That should block all of 402; the speculation. 403; CHECK-LABEL: @test14( 404; CHECK: alloca 405; CHECK: alloca 406; CHECK: select 407; CHECK: phi 408; CHECK: phi 409; CHECK: select 410; CHECK: ret i32 411 412entry: 413 %f = alloca i32 414 %g = alloca i32 415 store i32 0, i32* %f 416 store i32 0, i32* %g 417 %f.select = select i1 %b1, i32* %f, i32* %ptr 418 br i1 %b2, label %then, label %else 419 420then: 421 br label %exit 422 423else: 424 br label %exit 425 426exit: 427 %f.phi = phi i32* [ %f, %then ], [ %f.select, %else ] 428 %g.phi = phi i32* [ %g, %then ], [ %ptr, %else ] 429 %f.loaded = load i32, i32* %f.phi 430 %g.select = select i1 %b1, i32* %g, i32* %g.phi 431 %g.loaded = load i32, i32* %g.select 432 %result = add i32 %f.loaded, %g.loaded 433 ret i32 %result 434} 435 436define i32 @PR13905() { 437; Check a pattern where we have a chain of dead phi nodes to ensure they are 438; deleted and promotion can proceed. 439; CHECK-LABEL: @PR13905( 440; CHECK-NOT: alloca i32 441; CHECK: ret i32 undef 442 443entry: 444 %h = alloca i32 445 store i32 0, i32* %h 446 br i1 undef, label %loop1, label %exit 447 448loop1: 449 %phi1 = phi i32* [ null, %entry ], [ %h, %loop1 ], [ %h, %loop2 ] 450 br i1 undef, label %loop1, label %loop2 451 452loop2: 453 br i1 undef, label %loop1, label %exit 454 455exit: 456 %phi2 = phi i32* [ %phi1, %loop2 ], [ null, %entry ] 457 ret i32 undef 458} 459 460define i32 @PR13906() { 461; Another pattern which can lead to crashes due to failing to clear out dead 462; PHI nodes or select nodes. This triggers subtly differently from the above 463; cases because the PHI node is (recursively) alive, but the select is dead. 464; CHECK-LABEL: @PR13906( 465; CHECK-NOT: alloca 466 467entry: 468 %c = alloca i32 469 store i32 0, i32* %c 470 br label %for.cond 471 472for.cond: 473 %d.0 = phi i32* [ undef, %entry ], [ %c, %if.then ], [ %d.0, %for.cond ] 474 br i1 undef, label %if.then, label %for.cond 475 476if.then: 477 %tmpcast.d.0 = select i1 undef, i32* %c, i32* %d.0 478 br label %for.cond 479} 480 481define i64 @PR14132(i1 %flag) { 482; CHECK-LABEL: @PR14132( 483; Here we form a PHI-node by promoting the pointer alloca first, and then in 484; order to promote the other two allocas, we speculate the load of the 485; now-phi-node-pointer. In doing so we end up loading a 64-bit value from an i8 486; alloca. While this is a bit dubious, we were asserting on trying to 487; rewrite it. The trick is that the code using the value may carefully take 488; steps to only use the not-undef bits, and so we need to at least loosely 489; support this.. 490entry: 491 %a = alloca i64, align 8 492 %b = alloca i8, align 8 493 %ptr = alloca i64*, align 8 494; CHECK-NOT: alloca 495 496 %ptr.cast = bitcast i64** %ptr to i8** 497 store i64 0, i64* %a, align 8 498 store i8 1, i8* %b, align 8 499 store i64* %a, i64** %ptr, align 8 500 br i1 %flag, label %if.then, label %if.end 501 502if.then: 503 store i8* %b, i8** %ptr.cast, align 8 504 br label %if.end 505; CHECK-NOT: store 506; CHECK: %[[ext:.*]] = zext i8 1 to i64 507 508if.end: 509 %tmp = load i64*, i64** %ptr, align 8 510 %result = load i64, i64* %tmp, align 8 511; CHECK-NOT: load 512; CHECK: %[[result:.*]] = phi i64 [ %[[ext]], %if.then ], [ 0, %entry ] 513 514 ret i64 %result 515; CHECK-NEXT: ret i64 %[[result]] 516} 517 518define float @PR16687(i64 %x, i1 %flag) { 519; CHECK-LABEL: @PR16687( 520; Check that even when we try to speculate the same phi twice (in two slices) 521; on an otherwise promotable construct, we don't get ahead of ourselves and try 522; to promote one of the slices prior to speculating it. 523 524entry: 525 %a = alloca i64, align 8 526 store i64 %x, i64* %a 527 br i1 %flag, label %then, label %else 528; CHECK-NOT: alloca 529; CHECK-NOT: store 530; CHECK: %[[lo:.*]] = trunc i64 %x to i32 531; CHECK: %[[shift:.*]] = lshr i64 %x, 32 532; CHECK: %[[hi:.*]] = trunc i64 %[[shift]] to i32 533 534then: 535 %a.f = bitcast i64* %a to float* 536 br label %end 537; CHECK: %[[lo_cast:.*]] = bitcast i32 %[[lo]] to float 538 539else: 540 %a.raw = bitcast i64* %a to i8* 541 %a.raw.4 = getelementptr i8, i8* %a.raw, i64 4 542 %a.raw.4.f = bitcast i8* %a.raw.4 to float* 543 br label %end 544; CHECK: %[[hi_cast:.*]] = bitcast i32 %[[hi]] to float 545 546end: 547 %a.phi.f = phi float* [ %a.f, %then ], [ %a.raw.4.f, %else ] 548 %f = load float, float* %a.phi.f 549 ret float %f 550; CHECK: %[[phi:.*]] = phi float [ %[[lo_cast]], %then ], [ %[[hi_cast]], %else ] 551; CHECK-NOT: load 552; CHECK: ret float %[[phi]] 553} 554 555; Verifies we fixed PR20425. We should be able to promote all alloca's to 556; registers in this test. 557; 558; %0 = slice 559; %1 = slice 560; %2 = phi(%0, %1) // == slice 561define float @simplify_phi_nodes_that_equal_slice(i1 %cond, float* %temp) { 562; CHECK-LABEL: @simplify_phi_nodes_that_equal_slice( 563entry: 564 %arr = alloca [4 x float], align 4 565; CHECK-NOT: alloca 566 br i1 %cond, label %then, label %else 567 568then: 569 %0 = getelementptr inbounds [4 x float], [4 x float]* %arr, i64 0, i64 3 570 store float 1.000000e+00, float* %0, align 4 571 br label %merge 572 573else: 574 %1 = getelementptr inbounds [4 x float], [4 x float]* %arr, i64 0, i64 3 575 store float 2.000000e+00, float* %1, align 4 576 br label %merge 577 578merge: 579 %2 = phi float* [ %0, %then ], [ %1, %else ] 580 store float 0.000000e+00, float* %temp, align 4 581 %3 = load float, float* %2, align 4 582 ret float %3 583} 584 585; A slightly complicated example for PR20425. 586; 587; %0 = slice 588; %1 = phi(%0) // == slice 589; %2 = slice 590; %3 = phi(%1, %2) // == slice 591define float @simplify_phi_nodes_that_equal_slice_2(i1 %cond, float* %temp) { 592; CHECK-LABEL: @simplify_phi_nodes_that_equal_slice_2( 593entry: 594 %arr = alloca [4 x float], align 4 595; CHECK-NOT: alloca 596 br i1 %cond, label %then, label %else 597 598then: 599 %0 = getelementptr inbounds [4 x float], [4 x float]* %arr, i64 0, i64 3 600 store float 1.000000e+00, float* %0, align 4 601 br label %then2 602 603then2: 604 %1 = phi float* [ %0, %then ] 605 store float 2.000000e+00, float* %1, align 4 606 br label %merge 607 608else: 609 %2 = getelementptr inbounds [4 x float], [4 x float]* %arr, i64 0, i64 3 610 store float 3.000000e+00, float* %2, align 4 611 br label %merge 612 613merge: 614 %3 = phi float* [ %1, %then2 ], [ %2, %else ] 615 store float 0.000000e+00, float* %temp, align 4 616 %4 = load float, float* %3, align 4 617 ret float %4 618} 619 620%struct.S = type { i32 } 621 622; Verifies we fixed PR20822. We have a foldable PHI feeding a speculatable PHI 623; which requires the rewriting of the speculated PHI to handle insertion 624; when the incoming pointer is itself from a PHI node. We would previously 625; insert a bitcast instruction *before* a PHI, producing an invalid module; 626; make sure we insert *after* the first non-PHI instruction. 627define void @PR20822() { 628; CHECK-LABEL: @PR20822( 629entry: 630 %f = alloca %struct.S, align 4 631; CHECK: %[[alloca:.*]] = alloca 632 br i1 undef, label %if.end, label %for.cond 633 634for.cond: ; preds = %for.cond, %entry 635 br label %if.end 636 637if.end: ; preds = %for.cond, %entry 638 %f2 = phi %struct.S* [ %f, %entry ], [ %f, %for.cond ] 639; CHECK: phi i32 640; CHECK: %[[cast:.*]] = bitcast i32* %[[alloca]] to %struct.S* 641 phi i32 [ undef, %entry ], [ undef, %for.cond ] 642 br i1 undef, label %if.then5, label %if.then2 643 644if.then2: ; preds = %if.end 645 br label %if.then5 646 647if.then5: ; preds = %if.then2, %if.end 648 %f1 = phi %struct.S* [ undef, %if.then2 ], [ %f2, %if.end ] 649; CHECK: phi {{.*}} %[[cast]] 650 store %struct.S undef, %struct.S* %f1, align 4 651 ret void 652} 653 654define i32 @phi_align(i32* %z) { 655; CHECK-LABEL: @phi_align( 656entry: 657 %a = alloca [8 x i8], align 8 658; CHECK: alloca [7 x i8] 659 660 %a0x = getelementptr [8 x i8], [8 x i8]* %a, i64 0, i32 1 661 %a0 = bitcast i8* %a0x to i32* 662 %a1x = getelementptr [8 x i8], [8 x i8]* %a, i64 0, i32 4 663 %a1 = bitcast i8* %a1x to i32* 664; CHECK: store i32 0, {{.*}}, align 1 665 store i32 0, i32* %a0, align 1 666; CHECK: store i32 1, {{.*}}, align 1 667 store i32 1, i32* %a1, align 4 668; CHECK: load {{.*}}, align 1 669 %v0 = load i32, i32* %a0, align 1 670; CHECK: load {{.*}}, align 1 671 %v1 = load i32, i32* %a1, align 4 672 %cond = icmp sle i32 %v0, %v1 673 br i1 %cond, label %then, label %exit 674 675then: 676 br label %exit 677 678exit: 679; CHECK: %phi = phi i32* [ {{.*}}, %then ], [ %z, %entry ] 680; CHECK-NEXT: %result = load i32, i32* %phi, align 1 681 %phi = phi i32* [ %a1, %then ], [ %z, %entry ] 682 %result = load i32, i32* %phi, align 4 683 ret i32 %result 684} 685 686; Don't speculate a load based on an earlier volatile operation. 687define i8 @volatile_select(i8* %p, i1 %b) { 688; CHECK-LABEL: @volatile_select( 689; CHECK: select i1 %b, i8* %p, i8* %p2 690 %p2 = alloca i8 691 store i8 0, i8* %p2 692 store volatile i8 0, i8* %p 693 %px = select i1 %b, i8* %p, i8* %p2 694 %v2 = load i8, i8* %px 695 ret i8 %v2 696} 697