arm64-regbankselect.mir 25.6 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956
# RUN: llc -O0 -run-pass=regbankselect %s -o - -verify-machineinstrs | FileCheck %s --check-prefix=CHECK --check-prefix=FAST
# RUN: llc -O0 -run-pass=regbankselect %s -regbankselect-greedy -o - -verify-machineinstrs | FileCheck %s --check-prefix=CHECK --check-prefix=GREEDY

--- |
  ; ModuleID = 'generic-virtual-registers-type-error.mir'
  target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
  target triple = "aarch64--"
  define void @defaultMapping() {
  entry:
    ret void
  }
  define void @defaultMappingVector() {
  entry:
    ret void
  }
  define void @defaultMapping1Repair() {
  entry:
    ret void
  }
  define void @defaultMapping2Repairs() {
  entry:
    ret void
  }
  define void @defaultMappingDefRepair() {
  entry:
    ret void
  }
  define void @phiPropagation(i32* %src, i32* %dst, i1 %cond) {
  entry:
    %srcVal = load i32, i32* %src
    br i1 %cond, label %end, label %then
  then:
    %res = add i32 %srcVal, 36
    br label %end
  end:
    %toStore = phi i32 [ %srcVal, %entry ], [ %res, %then ]
    store i32 %toStore, i32* %dst
    ret void
  }
  define void @defaultMappingUseRepairPhysReg() {
  entry:
    ret void
  }
  define void @defaultMappingDefRepairPhysReg() {
  entry:
    ret void
  }
  define void @greedyMappingOr() {
  entry:
    ret void
  }
  define void @greedyMappingOrWithConstraints() {
  entry:
    ret void
  }

  define void @ignoreTargetSpecificInst() { ret void }

  define void @regBankSelected_property() { ret void }

  define void @bitcast_s32_gpr() { ret void }
  define void @bitcast_s32_fpr() { ret void }
  define void @bitcast_s32_gpr_fpr() { ret void }
  define void @bitcast_s32_fpr_gpr() { ret void }
  define void @bitcast_s64_gpr() { ret void }
  define void @bitcast_s64_fpr() { ret void }
  define void @bitcast_s64_gpr_fpr() { ret void }
  define void @bitcast_s64_fpr_gpr() { ret void }
  define void @bitcast_s128() { ret void }
  define void @copy_s128() { ret void }
  define void @copy_s128_from_load() { ret void }
  define void @copy_fp16() { ret void }

  define i64 @greedyWithChainOfComputation(i64 %arg1, <2 x i32>* %addr) {
    %varg1 = bitcast i64 %arg1 to <2 x i32>
    %varg2 = load <2 x i32>, <2 x i32>* %addr
    %vres = or <2 x i32> %varg1, %varg2
    %res = bitcast <2 x i32> %vres to i64
    ret i64 %res
  }

  define i64 @floatingPointLoad(i64 %arg1, double* %addr) {
    %varg1 = bitcast i64 %arg1 to double
    %varg2 = load double, double* %addr
    %vres = fadd double %varg1, %varg2
    %res = bitcast double %vres to i64
    ret i64 %res
  }

  define void @floatingPointStore(i64 %arg1, double* %addr) {
    %varg1 = bitcast i64 %arg1 to double
    %vres = fadd double %varg1, %varg1
    store double %vres, double* %addr
    ret void
  }

  define void @fp16Ext32() { ret void }
  define void @fp16Ext64() { ret void }
  define void @fp32Ext64() { ret void }

  define half @passFp16(half %p) {
  entry:
    ret half %p
  }

  define half @passFp16ViaAllocas(half %p) {
  entry:
    %p.addr = alloca half, align 2
    store half %p, half* %p.addr, align 2
    %0 = load half, half* %p.addr, align 2
    ret half %0
  }
...

---
# Check that we assign a relevant register bank for %0.
# Based on the type i32, this should be gpr.
name:            defaultMapping
legalized:       true
registers:
  - { id: 0, class: _ }
  - { id: 1, class: _ }
body: |
  bb.0.entry:
    liveins: $x0
    ; CHECK-LABEL: name: defaultMapping
    ; CHECK:      %1:gpr(s32) = G_ADD %0
    %0(s32) = COPY $w0
    %1(s32) = G_ADD %0, %0
...

---
# Check that we assign a relevant register bank for %0.
# Based on the type <2 x i32>, this should be fpr.
# FPR is used for both floating point and vector registers.
name:            defaultMappingVector
legalized:       true
registers:
  - { id: 0, class: _ }
  - { id: 1, class: _ }
body: |
  bb.0.entry:
    liveins: $d0
    ; CHECK-LABEL: name: defaultMappingVector
    ; CHECK:      %0:fpr(<2 x s32>) = COPY $d0
    ; CHECK:      %1:fpr(<2 x s32>) = G_ADD %0
    %0(<2 x s32>) = COPY $d0
    %1(<2 x s32>) = G_ADD %0, %0
...

---
# Check that we repair the assignment for %0.
# Indeed based on the source of the copy it should live
# in FPR, but at the use, it should be GPR.
name:            defaultMapping1Repair
legalized:       true
registers:
  - { id: 0, class: _ }
  - { id: 1, class: _ }
  - { id: 2, class: _ }
body: |
  bb.0.entry:
    liveins: $s0, $x0
    ; CHECK-LABEL: name: defaultMapping1Repair
    ; CHECK:           %0:fpr(s32) = COPY $s0
    ; CHECK-NEXT:      %1:gpr(s32) = COPY $w0
    ; CHECK-NEXT:      %3:gpr(s32) = COPY %0
    ; CHECK-NEXT:      %2:gpr(s32) = G_ADD %3, %1
    %0(s32) = COPY $s0
    %1(s32) = COPY $w0
    %2(s32) = G_ADD %0, %1
...

# Check that we repair the assignment for %0 differently for both uses.
name:            defaultMapping2Repairs
legalized:       true
registers:
  - { id: 0, class: _ }
  - { id: 1, class: _ }
body: |
  bb.0.entry:
    liveins: $s0, $x0
    ; CHECK-LABEL: name: defaultMapping2Repairs
    ; CHECK:           %0:fpr(s32) = COPY $s0
    ; CHECK-NEXT:      %2:gpr(s32) = COPY %0
    ; CHECK-NEXT:      %3:gpr(s32) = COPY %0
    ; CHECK-NEXT:      %1:gpr(s32) = G_ADD %2, %3
    %0(s32) = COPY $s0
    %1(s32) = G_ADD %0, %0
...

---
# Check that we repair the definition of %1.
# %1 is forced to be into FPR, but its definition actually
# requires that it lives in GPR. Make sure regbankselect
# fixes that.
name:            defaultMappingDefRepair
legalized:       true
registers:
  - { id: 0, class: _ }
  - { id: 1, class: fpr }
body: |
  bb.0.entry:
    liveins: $w0
    ; CHECK-LABEL: name: defaultMappingDefRepair
    ; CHECK:           %0:gpr(s32) = COPY $w0
    ; CHECK-NEXT:      %2:gpr(s32) = G_ADD %0, %0
    ; CHECK-NEXT:      %1:fpr(s32) = COPY %2
    %0(s32) = COPY $w0
    %1(s32) = G_ADD %0, %0
...

---
# Check that we are able to propagate register banks from phis.
name:            phiPropagation
legalized:       true
tracksRegLiveness:   true
# CHECK:      registers:
# CHECK-NEXT:   - { id: 0, class: gpr32, preferred-register: '' }
# CHECK-NEXT:   - { id: 1, class: gpr64sp, preferred-register: '' }
# CHECK-NEXT:   - { id: 2, class: gpr32, preferred-register: '' }
# CHECK-NEXT:   - { id: 3, class: gpr, preferred-register: '' }
# CHECK-NEXT:   - { id: 4, class: gpr, preferred-register: '' }
registers:
  - { id: 0, class: gpr32 }
  - { id: 1, class: gpr64sp }
  - { id: 2, class: gpr32 }
  - { id: 3, class: _ }
  - { id: 4, class: _ }
  - { id: 5, class: _ }
body: |
  bb.0.entry:
    successors: %bb.2.end, %bb.1.then
    liveins: $x0, $x1, $w2

    %0 = LDRWui killed $x0, 0 :: (load 4 from %ir.src)
    %5(s32) = COPY %0
    %1(p0) = COPY $x1
    %2 = COPY $w2
    TBNZW killed %2, 0, %bb.2.end

  bb.1.then:
    successors: %bb.2.end
    %3(s32) = G_ADD %5, %5

  bb.2.end:
    %4(s32) = PHI %0, %bb.0.entry, %3, %bb.1.then
    G_STORE killed %4, killed %1 :: (store 4 into %ir.dst)
    RET_ReallyLR
...

---
# Make sure we can repair physical register uses as well.
name:            defaultMappingUseRepairPhysReg
legalized:       true
registers:
  - { id: 0, class: _ }
  - { id: 1, class: _ }
  - { id: 2, class: _ }
body: |
  bb.0.entry:
    liveins: $w0, $s0
    ; CHECK-LABEL: name: defaultMappingUseRepairPhysReg
    ; CHECK:           %0:gpr(s32) = COPY $w0
    ; CHECK-NEXT:      %1:fpr(s32) = COPY $s0
    ; CHECK-NEXT:      %3:gpr(s32) = COPY %1
    ; CHECK-NEXT:      %2:gpr(s32) = G_ADD %0, %3
    %0(s32) = COPY $w0
    %1(s32) = COPY $s0
    %2(s32) = G_ADD %0, %1
...

---
# Make sure we can repair physical register defs.
name:            defaultMappingDefRepairPhysReg
legalized:       true
registers:
  - { id: 0, class: _ }
  - { id: 1, class: _ }
body: |
  bb.0.entry:
    liveins: $w0
    ; CHECK-LABEL: name: defaultMappingDefRepairPhysReg
    ; CHECK:           %0:gpr(s32) = COPY $w0
    ; CHECK-NEXT:      %1:gpr(s32) = G_ADD %0, %0
    ; CHECK-NEXT:      $s0 = COPY %1
    %0(s32) = COPY $w0
    %1(s32) = G_ADD %0, %0
    $s0 = COPY %1
...

---
# Check that the greedy mode is able to switch the
# G_OR instruction from fpr to gpr.
name:            greedyMappingOr
legalized:       true
registers:
  - { id: 0, class: _ }
  - { id: 1, class: _ }
  - { id: 2, class: _ }
body: |
  bb.0.entry:
    liveins: $x0, $x1
    ; CHECK: %0:gpr(<2 x s32>) = COPY $x0
    ; CHECK-NEXT: %1:gpr(<2 x s32>) = COPY $x1

    ; Fast mode tries to reuse the source of the copy for the destination.
    ; Now, the default mapping says that %0 and %1 need to be in FPR.
    ; The repairing code insert two copies to materialize that.
    ; FAST-NEXT: %3:fpr(<2 x s32>) = COPY %0
    ; FAST-NEXT: %4:fpr(<2 x s32>) = COPY %1
    ; The mapping of G_OR is on FPR.
    ; FAST-NEXT: %2:fpr(<2 x s32>) = G_OR %3, %4

    ; Greedy mode remapped the instruction on the GPR bank.
    ; GREEDY-NEXT: %2:gpr(<2 x s32>) = G_OR %0, %1
    %0(<2 x s32>) = COPY $x0
    %1(<2 x s32>) = COPY $x1
    %2(<2 x s32>) = G_OR %0, %1
...

---
# Check that the greedy mode is able to switch the
# G_OR instruction from fpr to gpr, while still honoring
# %2 constraint.
name:            greedyMappingOrWithConstraints
legalized:       true
registers:
  - { id: 0, class: _ }
  - { id: 1, class: _ }
  - { id: 2, class: fpr }
body: |
  bb.0.entry:
    liveins: $x0, $x1
    ; CHECK-LABEL: name: greedyMappingOrWithConstraints

    ; CHECK: %0:gpr(<2 x s32>) = COPY $x0
    ; CHECK-NEXT: %1:gpr(<2 x s32>) = COPY $x1

    ; Fast mode tries to reuse the source of the copy for the destination.
    ; Now, the default mapping says that %0 and %1 need to be in FPR.
    ; The repairing code insert two copies to materialize that.
    ; FAST-NEXT: %3:fpr(<2 x s32>) = COPY %0
    ; FAST-NEXT: %4:fpr(<2 x s32>) = COPY %1
    ; The mapping of G_OR is on FPR.
    ; FAST-NEXT: %2:fpr(<2 x s32>) = G_OR %3, %4

    ; Greedy mode remapped the instruction on the GPR bank.
    ; GREEDY-NEXT: %3:gpr(<2 x s32>) = G_OR %0, %1
    ; We need to keep %2 into FPR because we do not know anything about it.
    ; GREEDY-NEXT: %2:fpr(<2 x s32>) = COPY %3
    %0(<2 x s32>) = COPY $x0
    %1(<2 x s32>) = COPY $x1
    %2(<2 x s32>) = G_OR %0, %1
...

---
# CHECK-LABEL: name: ignoreTargetSpecificInst
name:            ignoreTargetSpecificInst
legalized:       true
# CHECK:      registers:
# CHECK-NEXT:  - { id: 0, class: gpr64, preferred-register: '' }
# CHECK-NEXT:  - { id: 1, class: gpr64, preferred-register: '' }
registers:
  - { id: 0, class: gpr64 }
  - { id: 1, class: gpr64 }
body: |
  bb.0:
    liveins: $x0

    ; CHECK: %0:gpr64 = COPY $x0
    ; CHECK-NEXT: %1:gpr64 = ADDXrr %0, %0
    ; CHECK-NEXT: $x0 = COPY %1
    ; CHECK-NEXT: RET_ReallyLR implicit $x0

    %0 = COPY $x0
    %1 = ADDXrr %0, %0
    $x0 = COPY %1
    RET_ReallyLR implicit $x0
...

---
# Check that we set the "regBankSelected" property.
# CHECK-LABEL: name: regBankSelected_property
# CHECK: legalized: true
# CHECK: regBankSelected: true
name:            regBankSelected_property
legalized:       true
regBankSelected: false
body:             |
  bb.0:
...

---
# CHECK-LABEL: name: bitcast_s32_gpr
name:            bitcast_s32_gpr
legalized:       true

# CHECK:      registers:
# CHECK-NEXT:  - { id: 0, class: gpr, preferred-register: '' }
# CHECK-NEXT:  - { id: 1, class: gpr, preferred-register: '' }
registers:
  - { id: 0, class: _ }
  - { id: 1, class: _ }

# CHECK:  body:
# CHECK:    %0:gpr(s32) = COPY $w0
# CHECK:    %1:gpr(s32) = G_BITCAST %0
body:             |
  bb.0:
    liveins: $w0

    %0(s32) = COPY $w0
    %1(s32) = G_BITCAST %0
...

---
# CHECK-LABEL: name: bitcast_s32_fpr
name:            bitcast_s32_fpr
legalized:       true

# CHECK:      registers:
# CHECK-NEXT:  - { id: 0, class: fpr, preferred-register: '' }
# CHECK-NEXT:  - { id: 1, class: fpr, preferred-register: '' }
registers:
  - { id: 0, class: _ }
  - { id: 1, class: _ }

# CHECK:  body:
# CHECK:    %0:fpr(<2 x s16>) = COPY $s0
# CHECK:    %1:fpr(<2 x s16>) = G_BITCAST %0
body:             |
  bb.0:
    liveins: $s0

    %0(<2 x s16>) = COPY $s0
    %1(<2 x s16>) = G_BITCAST %0
...

---
# CHECK-LABEL: name: bitcast_s32_gpr_fpr
name:            bitcast_s32_gpr_fpr
legalized:       true

# CHECK:      registers:
# CHECK-NEXT:  - { id: 0, class: gpr, preferred-register: '' }
# FAST-NEXT:  - { id: 1, class: fpr, preferred-register: '' }
# GREEDY-NEXT:  - { id: 1, class: gpr, preferred-register: '' }
registers:
  - { id: 0, class: _ }
  - { id: 1, class: _ }

# CHECK:  body:
# CHECK:    %0:gpr(s32) = COPY $w0
# FAST:     %1:fpr(<2 x s16>) = G_BITCAST %0
# GREEDY:   %1:gpr(<2 x s16>) = G_BITCAST %0
body:             |
  bb.0:
    liveins: $w0

    %0(s32) = COPY $w0
    %1(<2 x s16>) = G_BITCAST %0
...

---
# CHECK-LABEL: name: bitcast_s32_fpr_gpr
name:            bitcast_s32_fpr_gpr
legalized:       true
registers:
  - { id: 0, class: _ }
  - { id: 1, class: _ }
# CHECK:  body:
# CHECK:    %0:fpr(<2 x s16>) = COPY $s0
# FAST:     %1:gpr(s32) = G_BITCAST %0
# GREEDY:   %1:fpr(s32) = G_BITCAST %0
body:             |
  bb.0:
    liveins: $s0

    %0(<2 x s16>) = COPY $s0
    %1(s32) = G_BITCAST %0
...

---
# CHECK-LABEL: name: bitcast_s64_gpr
name:            bitcast_s64_gpr
legalized:       true
registers:
  - { id: 0, class: _ }
  - { id: 1, class: _ }
# CHECK:  body:
# CHECK:    %0:gpr(s64) = COPY $x0
# CHECK:    %1:gpr(s64) = G_BITCAST %0
body:             |
  bb.0:
    liveins: $x0

    %0(s64) = COPY $x0
    %1(s64) = G_BITCAST %0
...

---
# CHECK-LABEL: name: bitcast_s64_fpr
name:            bitcast_s64_fpr
legalized:       true
registers:
  - { id: 0, class: _ }
  - { id: 1, class: _ }
# CHECK:  body:
# CHECK:    %0:fpr(<2 x s32>) = COPY $d0
# CHECK:    %1:fpr(<2 x s32>) = G_BITCAST %0
body:             |
  bb.0:
    liveins: $d0

    %0(<2 x s32>) = COPY $d0
    %1(<2 x s32>) = G_BITCAST %0
...

---
# CHECK-LABEL: name: bitcast_s64_gpr_fpr
name:            bitcast_s64_gpr_fpr
legalized:       true
registers:
  - { id: 0, class: _ }
  - { id: 1, class: _ }
# CHECK:  body:
# CHECK:    %0:gpr(s64) = COPY $x0
# FAST:     %1:fpr(<2 x s32>) = G_BITCAST %0
# GREEDY:   %1:gpr(<2 x s32>) = G_BITCAST %0
body:             |
  bb.0:
    liveins: $x0

    %0(s64) = COPY $x0
    %1(<2 x s32>) = G_BITCAST %0
...

---
# CHECK-LABEL: name: bitcast_s64_fpr_gpr
name:            bitcast_s64_fpr_gpr
legalized:       true
registers:
  - { id: 0, class: _ }
  - { id: 1, class: _ }
# CHECK:  body:
# CHECK:    %0:fpr(<2 x s32>) = COPY $d0
# FAST:     %1:gpr(s64) = G_BITCAST %0
# GREEDY:   %1:fpr(s64) = G_BITCAST %0
body:             |
  bb.0:
    liveins: $d0

    %0(<2 x s32>) = COPY $d0
    %1(s64) = G_BITCAST %0
...

---
# CHECK-LABEL: name: bitcast_s128
name:            bitcast_s128
legalized: true
tracksRegLiveness: true
registers:
  - { id: 0, class: _}
  - { id: 1, class: _}
  - { id: 2, class: _}
  - { id: 3, class: _}
# CHECK: %3:fpr(s128) = G_MERGE_VALUES
# CHECK: %2:fpr(<2 x s64>) = G_BITCAST %3(s128)
body:             |
  bb.1:
    liveins: $x0, $x1
    %0(s64) = COPY $x0
    %1(s64) = COPY $x1
    %3(s128) = G_MERGE_VALUES %0(s64), %1(s64)
    %2(<2 x s64>) = G_BITCAST %3(s128)
    $q0 = COPY %2(<2 x s64>)
    RET_ReallyLR implicit $q0

...

---
# CHECK-LABEL: name: copy_s128
# This test checks that we issue the proper mapping
# for copy of size > 64.
# The mapping should be the same as G_BITCAST.
name:            copy_s128
legalized: true
tracksRegLiveness: true
registers:
  - { id: 0, class: _}
  - { id: 1, class: _}
  - { id: 2, class: _}
  - { id: 3, class: _}
  - { id: 4, class: _}
# CHECK: %3:fpr(s128) = G_MERGE_VALUES
# CHECK: %4:fpr(s128) = COPY %3(s128)
# CHECK-NEXT: %2:fpr(<2 x s64>) = G_BITCAST %4(s128)
body:             |
  bb.1:
    liveins: $x0, $x1
    %0(s64) = COPY $x0
    %1(s64) = COPY $x1
    %3(s128) = G_MERGE_VALUES %0(s64), %1(s64)
    %4(s128) = COPY %3(s128)
    %2(<2 x s64>) = G_BITCAST %4(s128)
    $q0 = COPY %2(<2 x s64>)
    RET_ReallyLR implicit $q0

...

---
# CHECK-LABEL: name: copy_s128_from_load
# This test checks that we issue the proper mapping
# for copy of size > 64 when the input is neither
# a physcal register nor a generic register.
# This used to crash when we moved to the statically
# computed mapping, because we were assuming non-physregs
# were generic registers and thus have a type, whereas
# it is not necessarily the case.
name:            copy_s128_from_load
legalized: true
tracksRegLiveness: true
registers:
  - { id: 0, class: fpr128}
  - { id: 1, class: _}
# CHECK: registers:
# CHECK:  - { id: 0, class: fpr128, preferred-register: '' }
# CHECK:  - { id: 1, class: fpr, preferred-register: '' }
# CHECK: %1:fpr(s128) = COPY %0
body:             |
  bb.1:
    liveins: $x0
    %0 = LDRQui killed $x0, 0
    %1(s128) = COPY %0
    $q0 = COPY %1(s128)
    RET_ReallyLR implicit $q0

...

---
# CHECK-LABEL: name: copy_fp16
# This test checks that we issue the proper mapping
# for copy of size == 16 when the destination is a fpr
# physical register and the source a gpr.
# We used to crash because we thought that mapping couldn't
# exist in a copy.
name:            copy_fp16
legalized: true
tracksRegLiveness: true
registers:
  - { id: 0, class: _}
  - { id: 1, class: _}
# CHECK: registers:
# CHECK:  - { id: 0, class: gpr, preferred-register: '' }
# CHECK:  - { id: 1, class: gpr, preferred-register: '' }
# CHECK: %0:gpr(s32) = COPY $w0
# CHECK-NEXT: %1:gpr(s16) = G_TRUNC %0(s32)
body:             |
  bb.1:
    liveins: $w0
    %0(s32) = COPY $w0
    %1(s16) = G_TRUNC %0(s32)
    $h0 = COPY %1(s16)
    RET_ReallyLR implicit $h0

...


---
# Make sure the greedy mode is able to take advantage of the
# alternative mappings of G_LOAD to coalesce the whole chain
# of computation on GPR.
# CHECK-LABEL: name: greedyWithChainOfComputation
name:            greedyWithChainOfComputation
legalized:       true
registers:
  - { id: 0, class: _ }
  - { id: 1, class: _ }
  - { id: 2, class: _ }
  - { id: 3, class: _ }
  - { id: 4, class: _ }
  - { id: 5, class: _ }
# No repairing should be necessary for both modes.
# CHECK:         %0:gpr(s64) = COPY $x0
# CHECK-NEXT:    %1:gpr(p0) = COPY $x1
# FAST-NEXT:     %2:fpr(<2 x s32>) = G_BITCAST %0(s64)
# FAST-NEXT:     %3:fpr(<2 x s32>) = G_LOAD %1(p0) :: (load 8 from %ir.addr)
# FAST-NEXT:     %4:fpr(<2 x s32>) = G_OR %2, %3
# GREEDY-NEXT:   %2:gpr(<2 x s32>) = G_BITCAST %0(s64)
# GREEDY-NEXT:   %3:gpr(<2 x s32>) = G_LOAD %1(p0) :: (load 8 from %ir.addr)
# GREEDY-NEXT:   %4:gpr(<2 x s32>) = G_OR %2, %3
# CHECK-NEXT:    %5:gpr(s64) = G_BITCAST %4(<2 x s32>)
# CHECK-NEXT:    $x0 = COPY %5(s64)
# CHECK-NEXT:    RET_ReallyLR implicit $x0
body:             |
  bb.0:
    liveins: $x0, $x1

    %0(s64) = COPY $x0
    %1(p0) = COPY $x1
    %2(<2 x s32>) = G_BITCAST %0(s64)
    %3(<2 x s32>) = G_LOAD %1(p0) :: (load 8 from %ir.addr)
    %4(<2 x s32>) = G_OR %2, %3
    %5(s64) = G_BITCAST %4(<2 x s32>)
    $x0 = COPY %5(s64)
    RET_ReallyLR implicit $x0

...

---
# Make sure we map what looks like floating point
# loads to floating point register bank.
# CHECK-LABEL: name: floatingPointLoad
name:            floatingPointLoad
legalized:       true

# CHECK: registers:
# CHECK-NEXT:  - { id: 0, class: gpr, preferred-register: '' }
# CHECK-NEXT:  - { id: 1, class: gpr, preferred-register: '' }
# CHECK-NEXT:   - { id: 2, class: fpr, preferred-register: '' }
# CHECK-NEXT:   - { id: 3, class: fpr, preferred-register: '' }
# CHECK-NEXT:   - { id: 4, class: fpr, preferred-register: '' }
registers:
  - { id: 0, class: _ }
  - { id: 1, class: _ }
  - { id: 2, class: _ }
  - { id: 3, class: _ }

# No repairing should be necessary for both modes.
# CHECK:         %0:gpr(s64) = COPY $x0
# CHECK-NEXT:    %1:gpr(p0) = COPY $x1
# CHECK-NEXT:    %2:fpr(s64) = G_LOAD %1(p0) :: (load 8 from %ir.addr)
# %0 has been mapped to GPR, we need to repair to match FPR.
# CHECK-NEXT:    %4:fpr(s64) = COPY %0
# CHECK-NEXT:    %3:fpr(s64) = G_FADD %4, %2
# CHECK-NEXT:    $x0 = COPY %3(s64)
# CHECK-NEXT:    RET_ReallyLR implicit $x0

body:             |
  bb.0:
    liveins: $x0, $x1

    %0(s64) = COPY $x0
    %1(p0) = COPY $x1
    %2(s64) = G_LOAD %1(p0) :: (load 8 from %ir.addr)
    %3(s64) = G_FADD %0, %2
    $x0 = COPY %3(s64)
    RET_ReallyLR implicit $x0

...

---
# Make sure we map what looks like floating point
# stores to floating point register bank.
# CHECK-LABEL: name: floatingPointStore
name:            floatingPointStore
legalized:       true

# CHECK: registers:
# CHECK-NEXT:  - { id: 0, class: gpr, preferred-register: '' }
# CHECK-NEXT:  - { id: 1, class: gpr, preferred-register: '' }
# CHECK-NEXT:   - { id: 2, class: fpr, preferred-register: '' }
# CHECK-NEXT:   - { id: 3, class: fpr, preferred-register: '' }
# CHECK-NEXT:   - { id: 4, class: fpr, preferred-register: '' }
registers:
  - { id: 0, class: _ }
  - { id: 1, class: _ }
  - { id: 2, class: _ }

# CHECK:         %0:gpr(s64) = COPY $x0
# CHECK-NEXT:    %1:gpr(p0) = COPY $x1
# %0 has been mapped to GPR, we need to repair to match FPR.
# CHECK-NEXT:    %3:fpr(s64) = COPY %0
# CHECK-NEXT:    %4:fpr(s64) = COPY %0
# CHECK-NEXT:    %2:fpr(s64) = G_FADD %3, %4
# CHECK-NEXT:    G_STORE %2(s64), %1(p0) :: (store 8 into %ir.addr)
# CHECK-NEXT:    RET_ReallyLR

body:             |
  bb.0:
    liveins: $x0, $x1

    %0(s64) = COPY $x0
    %1(p0) = COPY $x1
    %2(s64) = G_FADD %0, %0
    G_STORE %2(s64), %1(p0) :: (store 8 into %ir.addr)
    RET_ReallyLR

...

---
# Make sure we map FPEXT on FPR register bank.
# CHECK-LABEL: name: fp16Ext32
name:            fp16Ext32
alignment:       4
legalized:       true
# CHECK: registers:
# CHECK-NEXT:  - { id: 0, class: gpr, preferred-register: '' }
# CHECK-NEXT:  - { id: 1, class: gpr, preferred-register: '' }
# CHECK-NEXT:   - { id: 2, class: fpr, preferred-register: '' }
# CHECK-NEXT:   - { id: 3, class: fpr, preferred-register: '' }
registers:
  - { id: 0, class: _ }
  - { id: 1, class: _ }
  - { id: 2, class: _ }
# CHECK:         %1:gpr(s32) = COPY $w0
# CHECK-NEXT:    %0:gpr(s16) = G_TRUNC %1
# %0 has been mapped to GPR, we need to repair to match FPR.
# CHECK-NEXT:    %3:fpr(s16) = COPY %0
# CHECK-NEXT:    %2:fpr(s32) = G_FPEXT %3
# CHECK-NEXT:    $s0 = COPY %2
# CHECK-NEXT:    RET_ReallyLR

body:             |
  bb.1:
    liveins: $w0

    %1(s32) = COPY $w0
    %0(s16) = G_TRUNC %1(s32)
    %2(s32) = G_FPEXT %0(s16)
    $s0 = COPY %2(s32)
    RET_ReallyLR implicit $s0

...

---
# Make sure we map FPEXT on FPR register bank.
# CHECK-LABEL: name: fp16Ext64
name:            fp16Ext64
alignment:       4
legalized:       true
# CHECK: registers:
# CHECK-NEXT:  - { id: 0, class: gpr, preferred-register: '' }
# CHECK-NEXT:  - { id: 1, class: gpr, preferred-register: '' }
# CHECK-NEXT:   - { id: 2, class: fpr, preferred-register: '' }
# CHECK-NEXT:   - { id: 3, class: fpr, preferred-register: '' }
registers:
  - { id: 0, class: _ }
  - { id: 1, class: _ }
  - { id: 2, class: _ }
# CHECK:         %1:gpr(s32) = COPY $w0
# CHECK-NEXT:    %0:gpr(s16) = G_TRUNC %1
# %0 has been mapped to GPR, we need to repair to match FPR.
# CHECK-NEXT:    %3:fpr(s16) = COPY %0
# CHECK-NEXT:    %2:fpr(s64) = G_FPEXT %3
# CHECK-NEXT:    $d0 = COPY %2
# CHECK-NEXT:    RET_ReallyLR

body:             |
  bb.1:
    liveins: $w0

    %1(s32) = COPY $w0
    %0(s16) = G_TRUNC %1(s32)
    %2(s64) = G_FPEXT %0(s16)
    $d0 = COPY %2(s64)
    RET_ReallyLR implicit $d0

...

---
# Make sure we map FPEXT on FPR register bank.
# CHECK-LABEL: name: fp32Ext64
name:            fp32Ext64
alignment:       4
legalized:       true
# CHECK: registers:
# CHECK-NEXT:  - { id: 0, class: gpr, preferred-register: '' }
# CHECK-NEXT:  - { id: 1, class: fpr, preferred-register: '' }
# CHECK-NEXT:   - { id: 2, class: fpr, preferred-register: '' }
registers:
  - { id: 0, class: _ }
  - { id: 1, class: _ }
# CHECK:         %0:gpr(s32) = COPY $w0
# %0 has been mapped to GPR, we need to repair to match FPR.
# CHECK-NEXT:    %2:fpr(s32) = COPY %0
# CHECK-NEXT:    %1:fpr(s64) = G_FPEXT %2
# CHECK-NEXT:    $d0 = COPY %1
# CHECK-NEXT:    RET_ReallyLR
body:             |
  bb.1:
    liveins: $w0

    %0(s32) = COPY $w0
    %1(s64) = G_FPEXT %0(s32)
    $d0 = COPY %1(s64)
    RET_ReallyLR implicit $d0

...

---
# Make sure we map FP16 ABI on FPR register bank.
# CHECK-LABEL: name: passFp16
# CHECK: registers:
# CHECK:  - { id: 0, class: fpr, preferred-register: '' }
# CHECK:  %0:fpr(s16) = COPY $h0
# CHECK-NEXT: $h0 = COPY %0(s16)
name:            passFp16
alignment:       4
legalized:       true
registers:
  - { id: 0, class: _ }
body:             |
  bb.1.entry:
    liveins: $h0

    %0(s16) = COPY $h0
    $h0 = COPY %0(s16)
    RET_ReallyLR implicit $h0

...
---
# Make sure we properly detect fp types through copies.
# In that example, the copy comes from an ABI lowering of a fp type.
# CHECK-LABEL: name: passFp16ViaAllocas
# CHECK: registers:
# CHECK:  - { id: 0, class: fpr, preferred-register: '' }
# CHECK:  - { id: 1, class: gpr, preferred-register: '' }
# CHECK:  - { id: 2, class: fpr, preferred-register: '' }
#
# CHECK:  %0:fpr(s16) = COPY $h0
# CHECK-NEXT: %1:gpr(p0) = G_FRAME_INDEX %stack.0.p.addr
# If we didn't look through the copy for %0, the default mapping
# would have been on GPR and we would have to insert a copy to move
# the value away from FPR (h0).
# CHECK-NEXT: G_STORE %0(s16), %1(p0) :: (store 2 into %ir.p.addr)
# If we didn't look through the copy for %2, the default mapping
# would have been on GPR and we would have to insert a copy to move
# the value to FPR (h0).
# CHECK-NEXT: %2:fpr(s16) = G_LOAD %1(p0) :: (load 2 from %ir.p.addr)
# CHECK-NEXT: $h0 = COPY %2(s16)
name:            passFp16ViaAllocas
alignment:       4
legalized:       true
tracksRegLiveness: true
registers:
  - { id: 0, class: _ }
  - { id: 1, class: _ }
  - { id: 2, class: _ }
frameInfo:
  maxAlignment:    2
stack:
  - { id: 0, name: p.addr, size: 2, alignment: 2, stack-id: default }
body:             |
  bb.1.entry:
    liveins: $h0

    %0(s16) = COPY $h0
    %1(p0) = G_FRAME_INDEX %stack.0.p.addr
    G_STORE %0(s16), %1(p0) :: (store 2 into %ir.p.addr)
    %2(s16) = G_LOAD %1(p0) :: (load 2 from %ir.p.addr)
    $h0 = COPY %2(s16)
    RET_ReallyLR implicit $h0

...