1; RUN: opt < %s -simplifycfg -sink-common-insts -S | FileCheck -enable-var-scope %s 2 3define zeroext i1 @test1(i1 zeroext %flag, i32 %blksA, i32 %blksB, i32 %nblks) { 4entry: 5 br i1 %flag, label %if.then, label %if.else 6 7; CHECK-LABEL: test1 8; CHECK: add 9; CHECK: select 10; CHECK: icmp 11; CHECK-NOT: br 12if.then: 13 %cmp = icmp uge i32 %blksA, %nblks 14 %frombool1 = zext i1 %cmp to i8 15 br label %if.end 16 17if.else: 18 %add = add i32 %nblks, %blksB 19 %cmp2 = icmp ule i32 %add, %blksA 20 %frombool3 = zext i1 %cmp2 to i8 21 br label %if.end 22 23if.end: 24 %obeys.0 = phi i8 [ %frombool1, %if.then ], [ %frombool3, %if.else ] 25 %tobool4 = icmp ne i8 %obeys.0, 0 26 ret i1 %tobool4 27} 28 29define zeroext i1 @test2(i1 zeroext %flag, i32 %blksA, i32 %blksB, i32 %nblks) { 30entry: 31 br i1 %flag, label %if.then, label %if.else 32 33; CHECK-LABEL: test2 34; CHECK: add 35; CHECK: select 36; CHECK: icmp 37; CHECK-NOT: br 38if.then: 39 %cmp = icmp uge i32 %blksA, %nblks 40 %frombool1 = zext i1 %cmp to i8 41 br label %if.end 42 43if.else: 44 %add = add i32 %nblks, %blksB 45 %cmp2 = icmp uge i32 %blksA, %add 46 %frombool3 = zext i1 %cmp2 to i8 47 br label %if.end 48 49if.end: 50 %obeys.0 = phi i8 [ %frombool1, %if.then ], [ %frombool3, %if.else ] 51 %tobool4 = icmp ne i8 %obeys.0, 0 52 ret i1 %tobool4 53} 54 55declare i32 @foo(i32, i32) nounwind readnone 56 57define i32 @test3(i1 zeroext %flag, i32 %x, i32 %y) { 58entry: 59 br i1 %flag, label %if.then, label %if.else 60 61if.then: 62 %x0 = call i32 @foo(i32 %x, i32 0) nounwind readnone 63 %y0 = call i32 @foo(i32 %x, i32 1) nounwind readnone 64 br label %if.end 65 66if.else: 67 %x1 = call i32 @foo(i32 %y, i32 0) nounwind readnone 68 %y1 = call i32 @foo(i32 %y, i32 1) nounwind readnone 69 br label %if.end 70 71if.end: 72 %xx = phi i32 [ %x0, %if.then ], [ %x1, %if.else ] 73 %yy = phi i32 [ %y0, %if.then ], [ %y1, %if.else ] 74 %ret = add i32 %xx, %yy 75 ret i32 %ret 76} 77 78; CHECK-LABEL: test3 79; CHECK: select 80; CHECK: call 81; CHECK: call 82; CHECK: add 83; CHECK-NOT: br 84 85define i32 @test4(i1 zeroext %flag, i32 %x, i32* %y) { 86entry: 87 br i1 %flag, label %if.then, label %if.else 88 89if.then: 90 %a = add i32 %x, 5 91 store i32 %a, i32* %y 92 br label %if.end 93 94if.else: 95 %b = add i32 %x, 7 96 store i32 %b, i32* %y 97 br label %if.end 98 99if.end: 100 ret i32 1 101} 102 103; CHECK-LABEL: test4 104; CHECK: select 105; CHECK: store 106; CHECK-NOT: store 107 108define i32 @test5(i1 zeroext %flag, i32 %x, i32* %y) { 109entry: 110 br i1 %flag, label %if.then, label %if.else 111 112if.then: 113 %a = add i32 %x, 5 114 store volatile i32 %a, i32* %y 115 br label %if.end 116 117if.else: 118 %b = add i32 %x, 7 119 store i32 %b, i32* %y 120 br label %if.end 121 122if.end: 123 ret i32 1 124} 125 126; CHECK-LABEL: test5 127; CHECK: store volatile 128; CHECK: store 129 130define i32 @test6(i1 zeroext %flag, i32 %x, i32* %y) { 131entry: 132 br i1 %flag, label %if.then, label %if.else 133 134if.then: 135 %a = add i32 %x, 5 136 store volatile i32 %a, i32* %y 137 br label %if.end 138 139if.else: 140 %b = add i32 %x, 7 141 store volatile i32 %b, i32* %y 142 br label %if.end 143 144if.end: 145 ret i32 1 146} 147 148; CHECK-LABEL: test6 149; CHECK: select 150; CHECK: store volatile 151; CHECK-NOT: store 152 153define i32 @test7(i1 zeroext %flag, i32 %x, i32* %y) { 154entry: 155 br i1 %flag, label %if.then, label %if.else 156 157if.then: 158 %z = load volatile i32, i32* %y 159 %a = add i32 %z, 5 160 store volatile i32 %a, i32* %y 161 br label %if.end 162 163if.else: 164 %w = load volatile i32, i32* %y 165 %b = add i32 %w, 7 166 store volatile i32 %b, i32* %y 167 br label %if.end 168 169if.end: 170 ret i32 1 171} 172 173; CHECK-LABEL: test7 174; CHECK-DAG: select 175; CHECK-DAG: load volatile 176; CHECK: store volatile 177; CHECK-NOT: load 178; CHECK-NOT: store 179 180; %z and %w are in different blocks. We shouldn't sink the add because 181; there may be intervening memory instructions. 182define i32 @test8(i1 zeroext %flag, i32 %x, i32* %y) { 183entry: 184 %z = load volatile i32, i32* %y 185 br i1 %flag, label %if.then, label %if.else 186 187if.then: 188 %a = add i32 %z, 5 189 store volatile i32 %a, i32* %y 190 br label %if.end 191 192if.else: 193 %w = load volatile i32, i32* %y 194 %b = add i32 %w, 7 195 store volatile i32 %b, i32* %y 196 br label %if.end 197 198if.end: 199 ret i32 1 200} 201 202; CHECK-LABEL: test8 203; CHECK: add 204; CHECK: add 205 206; The extra store in %if.then means %z and %w are not equivalent. 207define i32 @test9(i1 zeroext %flag, i32 %x, i32* %y, i32* %p) { 208entry: 209 br i1 %flag, label %if.then, label %if.else 210 211if.then: 212 store i32 7, i32* %p 213 %z = load volatile i32, i32* %y 214 store i32 6, i32* %p 215 %a = add i32 %z, 5 216 store volatile i32 %a, i32* %y 217 br label %if.end 218 219if.else: 220 %w = load volatile i32, i32* %y 221 %b = add i32 %w, 7 222 store volatile i32 %b, i32* %y 223 br label %if.end 224 225if.end: 226 ret i32 1 227} 228 229; CHECK-LABEL: test9 230; CHECK: add 231; CHECK: add 232 233%struct.anon = type { i32, i32 } 234 235; The GEP indexes a struct type so cannot have a variable last index. 236define i32 @test10(i1 zeroext %flag, i32 %x, i32* %y, %struct.anon* %s) { 237entry: 238 br i1 %flag, label %if.then, label %if.else 239 240if.then: 241 %dummy = add i32 %x, 5 242 %gepa = getelementptr inbounds %struct.anon, %struct.anon* %s, i32 0, i32 0 243 store volatile i32 %x, i32* %gepa 244 br label %if.end 245 246if.else: 247 %dummy1 = add i32 %x, 6 248 %gepb = getelementptr inbounds %struct.anon, %struct.anon* %s, i32 0, i32 1 249 store volatile i32 %x, i32* %gepb 250 br label %if.end 251 252if.end: 253 ret i32 1 254} 255 256; CHECK-LABEL: test10 257; CHECK: getelementptr 258; CHECK: getelementptr 259; CHECK: phi 260; CHECK: store volatile 261 262; The shufflevector's mask operand cannot be merged in a PHI. 263define i32 @test11(i1 zeroext %flag, i32 %w, <2 x i32> %x, <2 x i32> %y) { 264entry: 265 br i1 %flag, label %if.then, label %if.else 266 267if.then: 268 %dummy = add i32 %w, 5 269 %sv1 = shufflevector <2 x i32> %x, <2 x i32> %y, <2 x i32> <i32 0, i32 1> 270 br label %if.end 271 272if.else: 273 %dummy1 = add i32 %w, 6 274 %sv2 = shufflevector <2 x i32> %x, <2 x i32> %y, <2 x i32> <i32 1, i32 0> 275 br label %if.end 276 277if.end: 278 %p = phi <2 x i32> [ %sv1, %if.then ], [ %sv2, %if.else ] 279 ret i32 1 280} 281 282; CHECK-LABEL: test11 283; CHECK: shufflevector 284; CHECK: shufflevector 285 286; We can't common an intrinsic! 287define i32 @test12(i1 zeroext %flag, i32 %w, i32 %x, i32 %y) { 288entry: 289 br i1 %flag, label %if.then, label %if.else 290 291if.then: 292 %dummy = add i32 %w, 5 293 %sv1 = call i32 @llvm.ctlz.i32(i32 %x) 294 br label %if.end 295 296if.else: 297 %dummy1 = add i32 %w, 6 298 %sv2 = call i32 @llvm.cttz.i32(i32 %x) 299 br label %if.end 300 301if.end: 302 %p = phi i32 [ %sv1, %if.then ], [ %sv2, %if.else ] 303 ret i32 1 304} 305 306declare i32 @llvm.ctlz.i32(i32 %x) readnone 307declare i32 @llvm.cttz.i32(i32 %x) readnone 308 309; CHECK-LABEL: test12 310; CHECK: call i32 @llvm.ctlz 311; CHECK: call i32 @llvm.cttz 312 313; The TBAA metadata should be properly combined. 314define i32 @test13(i1 zeroext %flag, i32 %x, i32* %y) { 315entry: 316 br i1 %flag, label %if.then, label %if.else 317 318if.then: 319 %z = load volatile i32, i32* %y 320 %a = add i32 %z, 5 321 store volatile i32 %a, i32* %y, !tbaa !3 322 br label %if.end 323 324if.else: 325 %w = load volatile i32, i32* %y 326 %b = add i32 %w, 7 327 store volatile i32 %b, i32* %y, !tbaa !4 328 br label %if.end 329 330if.end: 331 ret i32 1 332} 333 334!0 = !{ !"an example type tree" } 335!1 = !{ !"int", !0 } 336!2 = !{ !"float", !0 } 337!3 = !{ !"const float", !2, i64 0 } 338!4 = !{ !"special float", !2, i64 1 } 339 340; CHECK-LABEL: test13 341; CHECK-DAG: select 342; CHECK-DAG: load volatile 343; CHECK: store volatile {{.*}}, !tbaa ![[$TBAA:[0-9]]] 344; CHECK-NOT: load 345; CHECK-NOT: store 346 347; The call should be commoned. 348define i32 @test13a(i1 zeroext %flag, i32 %w, i32 %x, i32 %y) { 349entry: 350 br i1 %flag, label %if.then, label %if.else 351 352if.then: 353 %sv1 = call i32 @bar(i32 %x) 354 br label %if.end 355 356if.else: 357 %sv2 = call i32 @bar(i32 %y) 358 br label %if.end 359 360if.end: 361 %p = phi i32 [ %sv1, %if.then ], [ %sv2, %if.else ] 362 ret i32 1 363} 364declare i32 @bar(i32) 365 366; CHECK-LABEL: test13a 367; CHECK: %[[x:.*]] = select i1 %flag 368; CHECK: call i32 @bar(i32 %[[x]]) 369 370; The load should be commoned. 371define i32 @test14(i1 zeroext %flag, i32 %w, i32 %x, i32 %y, %struct.anon* %s) { 372entry: 373 br i1 %flag, label %if.then, label %if.else 374 375if.then: 376 %dummy = add i32 %x, 1 377 %gepa = getelementptr inbounds %struct.anon, %struct.anon* %s, i32 0, i32 1 378 %sv1 = load i32, i32* %gepa 379 %cmp1 = icmp eq i32 %sv1, 56 380 br label %if.end 381 382if.else: 383 %dummy2 = add i32 %x, 4 384 %gepb = getelementptr inbounds %struct.anon, %struct.anon* %s, i32 0, i32 1 385 %sv2 = load i32, i32* %gepb 386 %cmp2 = icmp eq i32 %sv2, 57 387 call void @llvm.dbg.value(metadata i32 0, metadata !9, metadata !DIExpression()), !dbg !11 388 br label %if.end 389 390if.end: 391 %p = phi i1 [ %cmp1, %if.then ], [ %cmp2, %if.else ] 392 ret i32 1 393} 394 395declare void @llvm.dbg.value(metadata, metadata, metadata) 396!llvm.module.flags = !{!5, !6} 397!llvm.dbg.cu = !{!7} 398 399!5 = !{i32 2, !"Dwarf Version", i32 4} 400!6 = !{i32 2, !"Debug Info Version", i32 3} 401!7 = distinct !DICompileUnit(language: DW_LANG_C99, file: !10) 402!8 = distinct !DISubprogram(name: "foo", unit: !7) 403!9 = !DILocalVariable(name: "b", line: 1, arg: 2, scope: !8) 404!10 = !DIFile(filename: "a.c", directory: "a/b") 405!11 = !DILocation(line: 1, column: 14, scope: !8) 406 407; CHECK-LABEL: test14 408; CHECK: getelementptr 409; CHECK: load 410; CHECK-NOT: load 411 412; The load should be commoned. 413define i32 @test15(i1 zeroext %flag, i32 %w, i32 %x, i32 %y, %struct.anon* %s) { 414entry: 415 br i1 %flag, label %if.then, label %if.else 416 417if.then: 418 %dummy = add i32 %x, 1 419 %gepa = getelementptr inbounds %struct.anon, %struct.anon* %s, i32 0, i32 0 420 %sv1 = load i32, i32* %gepa 421 %ext1 = zext i32 %sv1 to i64 422 %cmp1 = icmp eq i64 %ext1, 56 423 br label %if.end 424 425if.else: 426 %dummy2 = add i32 %x, 4 427 %gepb = getelementptr inbounds %struct.anon, %struct.anon* %s, i32 0, i32 1 428 %sv2 = load i32, i32* %gepb 429 %ext2 = zext i32 %sv2 to i64 430 %cmp2 = icmp eq i64 %ext2, 57 431 br label %if.end 432 433if.end: 434 %p = phi i1 [ %cmp1, %if.then ], [ %cmp2, %if.else ] 435 ret i32 1 436} 437 438; CHECK-LABEL: test15 439; CHECK: getelementptr 440; CHECK: load 441; CHECK-NOT: load 442 443define zeroext i1 @test_crash(i1 zeroext %flag, i32* %i4, i32* %m, i32* %n) { 444entry: 445 br i1 %flag, label %if.then, label %if.else 446 447if.then: 448 %tmp1 = load i32, i32* %i4 449 %tmp2 = add i32 %tmp1, -1 450 store i32 %tmp2, i32* %i4 451 br label %if.end 452 453if.else: 454 %tmp3 = load i32, i32* %m 455 %tmp4 = load i32, i32* %n 456 %tmp5 = add i32 %tmp3, %tmp4 457 store i32 %tmp5, i32* %i4 458 br label %if.end 459 460if.end: 461 ret i1 true 462} 463 464; CHECK-LABEL: test_crash 465; No checks for test_crash - just ensure it doesn't crash! 466 467define zeroext i1 @test16(i1 zeroext %flag, i1 zeroext %flag2, i32 %blksA, i32 %blksB, i32 %nblks) { 468 469entry: 470 br i1 %flag, label %if.then, label %if.else 471 472if.then: 473 %cmp = icmp uge i32 %blksA, %nblks 474 %frombool1 = zext i1 %cmp to i8 475 br label %if.end 476 477if.else: 478 br i1 %flag2, label %if.then2, label %if.end 479 480if.then2: 481 %add = add i32 %nblks, %blksB 482 %cmp2 = icmp ule i32 %add, %blksA 483 %frombool3 = zext i1 %cmp2 to i8 484 br label %if.end 485 486if.end: 487 %obeys.0 = phi i8 [ %frombool1, %if.then ], [ %frombool3, %if.then2 ], [ 0, %if.else ] 488 %tobool4 = icmp ne i8 %obeys.0, 0 489 ret i1 %tobool4 490} 491 492; CHECK-LABEL: test16 493; CHECK: zext 494; CHECK: zext 495 496define zeroext i1 @test16a(i1 zeroext %flag, i1 zeroext %flag2, i32 %blksA, i32 %blksB, i32 %nblks, i8* %p) { 497 498entry: 499 br i1 %flag, label %if.then, label %if.else 500 501if.then: 502 %cmp = icmp uge i32 %blksA, %nblks 503 %frombool1 = zext i1 %cmp to i8 504 store i8 %frombool1, i8* %p 505 br label %if.end 506 507if.else: 508 br i1 %flag2, label %if.then2, label %if.end 509 510if.then2: 511 %add = add i32 %nblks, %blksB 512 %cmp2 = icmp ule i32 %add, %blksA 513 %frombool3 = zext i1 %cmp2 to i8 514 store i8 %frombool3, i8* %p 515 br label %if.end 516 517if.end: 518 ret i1 true 519} 520 521; CHECK-LABEL: test16a 522; CHECK: zext 523; CHECK-NOT: zext 524 525define zeroext i1 @test17(i32 %flag, i32 %blksA, i32 %blksB, i32 %nblks) { 526entry: 527 switch i32 %flag, label %if.end [ 528 i32 0, label %if.then 529 i32 1, label %if.then2 530 ] 531 532if.then: 533 %cmp = icmp uge i32 %blksA, %nblks 534 %frombool1 = call i8 @i1toi8(i1 %cmp) 535 br label %if.end 536 537if.then2: 538 %add = add i32 %nblks, %blksB 539 %cmp2 = icmp ule i32 %add, %blksA 540 %frombool3 = call i8 @i1toi8(i1 %cmp2) 541 br label %if.end 542 543if.end: 544 %obeys.0 = phi i8 [ %frombool1, %if.then ], [ %frombool3, %if.then2 ], [ 0, %entry ] 545 %tobool4 = icmp ne i8 %obeys.0, 0 546 ret i1 %tobool4 547} 548declare i8 @i1toi8(i1) 549 550; CHECK-LABEL: test17 551; CHECK: if.then: 552; CHECK-NEXT: icmp uge 553; CHECK-NEXT: br label %[[x:.*]] 554 555; CHECK: if.then2: 556; CHECK-NEXT: add 557; CHECK-NEXT: icmp ule 558; CHECK-NEXT: br label %[[x]] 559 560; CHECK: [[x]]: 561; CHECK-NEXT: %[[y:.*]] = phi i1 [ %cmp 562; CHECK-NEXT: %[[z:.*]] = call i8 @i1toi8(i1 %[[y]]) 563; CHECK-NEXT: br label %if.end 564 565; CHECK: if.end: 566; CHECK-NEXT: phi i8 567; CHECK-DAG: [ %[[z]], %[[x]] ] 568; CHECK-DAG: [ 0, %entry ] 569 570define zeroext i1 @test18(i32 %flag, i32 %blksA, i32 %blksB, i32 %nblks) { 571entry: 572 switch i32 %flag, label %if.then3 [ 573 i32 0, label %if.then 574 i32 1, label %if.then2 575 ] 576 577if.then: 578 %cmp = icmp uge i32 %blksA, %nblks 579 %frombool1 = zext i1 %cmp to i8 580 br label %if.end 581 582if.then2: 583 %add = add i32 %nblks, %blksB 584 %cmp2 = icmp ule i32 %add, %blksA 585 %frombool3 = zext i1 %cmp2 to i8 586 br label %if.end 587 588if.then3: 589 %add2 = add i32 %nblks, %blksA 590 %cmp3 = icmp ule i32 %add2, %blksA 591 %frombool4 = zext i1 %cmp3 to i8 592 br label %if.end 593 594if.end: 595 %obeys.0 = phi i8 [ %frombool1, %if.then ], [ %frombool3, %if.then2 ], [ %frombool4, %if.then3 ] 596 %tobool4 = icmp ne i8 %obeys.0, 0 597 ret i1 %tobool4 598} 599 600; CHECK-LABEL: test18 601; CHECK: if.end: 602; CHECK-NEXT: %[[x:.*]] = phi i1 603; CHECK-DAG: [ %cmp, %if.then ] 604; CHECK-DAG: [ %cmp2, %if.then2 ] 605; CHECK-DAG: [ %cmp3, %if.then3 ] 606; CHECK-NEXT: zext i1 %[[x]] to i8 607 608define i32 @test_pr30188(i1 zeroext %flag, i32 %x) { 609entry: 610 %y = alloca i32 611 %z = alloca i32 612 br i1 %flag, label %if.then, label %if.else 613 614if.then: 615 store i32 %x, i32* %y 616 br label %if.end 617 618if.else: 619 store i32 %x, i32* %z 620 br label %if.end 621 622if.end: 623 ret i32 1 624} 625 626; CHECK-LABEL: test_pr30188 627; CHECK-NOT: select 628; CHECK: store 629; CHECK: store 630 631define i32 @test_pr30188a(i1 zeroext %flag, i32 %x) { 632entry: 633 %y = alloca i32 634 %z = alloca i32 635 br i1 %flag, label %if.then, label %if.else 636 637if.then: 638 call void @g() 639 %one = load i32, i32* %y 640 %two = add i32 %one, 2 641 store i32 %two, i32* %y 642 br label %if.end 643 644if.else: 645 %three = load i32, i32* %z 646 %four = add i32 %three, 2 647 store i32 %four, i32* %y 648 br label %if.end 649 650if.end: 651 ret i32 1 652} 653 654; CHECK-LABEL: test_pr30188a 655; CHECK-NOT: select 656; CHECK: load 657; CHECK: load 658; CHECK: store 659 660; The phi is confusing - both add instructions are used by it, but 661; not on their respective unconditional arcs. It should not be 662; optimized. 663define void @test_pr30292(i1 %cond, i1 %cond2, i32 %a, i32 %b) { 664entry: 665 %add1 = add i32 %a, 1 666 br label %succ 667 668one: 669 br i1 %cond, label %two, label %succ 670 671two: 672 call void @g() 673 %add2 = add i32 %a, 1 674 br label %succ 675 676succ: 677 %p = phi i32 [ 0, %entry ], [ %add1, %one ], [ %add2, %two ] 678 br label %one 679} 680declare void @g() 681 682; CHECK-LABEL: test_pr30292 683; CHECK: phi i32 [ 0, %entry ], [ %add1, %succ ], [ %add2, %two ] 684 685define zeroext i1 @test_pr30244(i1 zeroext %flag, i1 zeroext %flag2, i32 %blksA, i32 %blksB, i32 %nblks) { 686 687entry: 688 %p = alloca i8 689 br i1 %flag, label %if.then, label %if.else 690 691if.then: 692 %cmp = icmp uge i32 %blksA, %nblks 693 %frombool1 = zext i1 %cmp to i8 694 store i8 %frombool1, i8* %p 695 br label %if.end 696 697if.else: 698 br i1 %flag2, label %if.then2, label %if.end 699 700if.then2: 701 %add = add i32 %nblks, %blksB 702 %cmp2 = icmp ule i32 %add, %blksA 703 %frombool3 = zext i1 %cmp2 to i8 704 store i8 %frombool3, i8* %p 705 br label %if.end 706 707if.end: 708 ret i1 true 709} 710 711; CHECK-LABEL: @test_pr30244 712; CHECK: store 713; CHECK: store 714 715define i32 @test_pr30373a(i1 zeroext %flag, i32 %x, i32 %y) { 716entry: 717 br i1 %flag, label %if.then, label %if.else 718 719if.then: 720 %x0 = call i32 @foo(i32 %x, i32 0) nounwind readnone 721 %y0 = call i32 @foo(i32 %x, i32 1) nounwind readnone 722 %z0 = lshr i32 %y0, 8 723 br label %if.end 724 725if.else: 726 %x1 = call i32 @foo(i32 %y, i32 0) nounwind readnone 727 %y1 = call i32 @foo(i32 %y, i32 1) nounwind readnone 728 %z1 = lshr exact i32 %y1, 8 729 br label %if.end 730 731if.end: 732 %xx = phi i32 [ %x0, %if.then ], [ %x1, %if.else ] 733 %yy = phi i32 [ %z0, %if.then ], [ %z1, %if.else ] 734 %ret = add i32 %xx, %yy 735 ret i32 %ret 736} 737 738; CHECK-LABEL: test_pr30373a 739; CHECK: lshr 740; CHECK-NOT: exact 741; CHECK: } 742 743define i32 @test_pr30373b(i1 zeroext %flag, i32 %x, i32 %y) { 744entry: 745 br i1 %flag, label %if.then, label %if.else 746 747if.then: 748 %x0 = call i32 @foo(i32 %x, i32 0) nounwind readnone 749 %y0 = call i32 @foo(i32 %x, i32 1) nounwind readnone 750 %z0 = lshr exact i32 %y0, 8 751 br label %if.end 752 753if.else: 754 %x1 = call i32 @foo(i32 %y, i32 0) nounwind readnone 755 %y1 = call i32 @foo(i32 %y, i32 1) nounwind readnone 756 %z1 = lshr i32 %y1, 8 757 br label %if.end 758 759if.end: 760 %xx = phi i32 [ %x0, %if.then ], [ %x1, %if.else ] 761 %yy = phi i32 [ %z0, %if.then ], [ %z1, %if.else ] 762 %ret = add i32 %xx, %yy 763 ret i32 %ret 764} 765 766; CHECK-LABEL: test_pr30373b 767; CHECK: lshr 768; CHECK-NOT: exact 769; CHECK: } 770 771; Check that simplifycfg doesn't sink and merge inline-asm instructions. 772 773define i32 @test_inline_asm1(i32 %c, i32 %r6) { 774entry: 775 %tobool = icmp eq i32 %c, 0 776 br i1 %tobool, label %if.else, label %if.then 777 778if.then: 779 %0 = call i32 asm "rorl $2, $0", "=&r,0,n,~{dirflag},~{fpsr},~{flags}"(i32 %r6, i32 8) 780 br label %if.end 781 782if.else: 783 %1 = call i32 asm "rorl $2, $0", "=&r,0,n,~{dirflag},~{fpsr},~{flags}"(i32 %r6, i32 6) 784 br label %if.end 785 786if.end: 787 %r6.addr.0 = phi i32 [ %0, %if.then ], [ %1, %if.else ] 788 ret i32 %r6.addr.0 789} 790 791; CHECK-LABEL: @test_inline_asm1( 792; CHECK: call i32 asm "rorl $2, $0", "=&r,0,n,~{dirflag},~{fpsr},~{flags}"(i32 %r6, i32 8) 793; CHECK: call i32 asm "rorl $2, $0", "=&r,0,n,~{dirflag},~{fpsr},~{flags}"(i32 %r6, i32 6) 794 795declare i32 @call_target() 796 797define void @test_operand_bundles(i1 %cond, i32* %ptr) { 798entry: 799 br i1 %cond, label %left, label %right 800 801left: 802 %val0 = call i32 @call_target() [ "deopt"(i32 10) ] 803 store i32 %val0, i32* %ptr 804 br label %merge 805 806right: 807 %val1 = call i32 @call_target() [ "deopt"(i32 20) ] 808 store i32 %val1, i32* %ptr 809 br label %merge 810 811merge: 812 ret void 813} 814 815; CHECK-LABEL: @test_operand_bundles( 816; CHECK: left: 817; CHECK-NEXT: %val0 = call i32 @call_target() [ "deopt"(i32 10) ] 818; CHECK: right: 819; CHECK-NEXT: %val1 = call i32 @call_target() [ "deopt"(i32 20) ] 820 821%T = type {i32, i32} 822 823define i32 @test_insertvalue(i1 zeroext %flag, %T %P) { 824entry: 825 br i1 %flag, label %if.then, label %if.else 826 827if.then: 828 %t1 = insertvalue %T %P, i32 0, 0 829 br label %if.end 830 831if.else: 832 %t2 = insertvalue %T %P, i32 1, 0 833 br label %if.end 834 835if.end: 836 %t = phi %T [%t1, %if.then], [%t2, %if.else] 837 ret i32 1 838} 839 840; CHECK-LABEL: @test_insertvalue 841; CHECK: select 842; CHECK: insertvalue 843; CHECK-NOT: insertvalue 844 845; CHECK: ![[$TBAA]] = !{![[TYPE:[0-9]]], ![[TYPE]], i64 0} 846; CHECK: ![[TYPE]] = !{!"float", ![[TEXT:[0-9]]]} 847; CHECK: ![[TEXT]] = !{!"an example type tree"} 848