llvm/llvm/test/CodeGen/AArch64/GlobalISel/legalize-phi.mir

# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
# RUN: llc -O0 -mtriple=aarch64-unknown-unknown -verify-machineinstrs -global-isel-abort=0 -run-pass=legalizer %s -o - | FileCheck %s
---
name:            legalize_phi
alignment:       4
exposesReturnsTwice: false
legalized:       false
regBankSelected: false
selected:        false
tracksRegLiveness: true
registers:
  - { id: 0, class: _, preferred-register: '' }
  - { id: 1, class: _, preferred-register: '' }
  - { id: 2, class: _, preferred-register: '' }
  - { id: 3, class: _, preferred-register: '' }
  - { id: 4, class: _, preferred-register: '' }
  - { id: 5, class: _, preferred-register: '' }
  - { id: 6, class: _, preferred-register: '' }
  - { id: 7, class: _, preferred-register: '' }
  - { id: 8, class: _, preferred-register: '' }
  - { id: 9, class: _, preferred-register: '' }
  - { id: 10, class: _, preferred-register: '' }
liveins:
body:             |
  ; CHECK-LABEL: name: legalize_phi
  ; CHECK: bb.0:
  ; CHECK-NEXT:   successors: %bb.1(0x40000000), %bb.2(0x40000000)
  ; CHECK-NEXT:   liveins: $w0
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[COPY:%[0-9]+]]:_(s32) = COPY $w0
  ; CHECK-NEXT:   [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
  ; CHECK-NEXT:   [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
  ; CHECK-NEXT:   [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 2
  ; CHECK-NEXT:   [[ICMP:%[0-9]+]]:_(s32) = G_ICMP intpred(ugt), [[COPY]](s32), [[C]]
  ; CHECK-NEXT:   G_BRCOND [[ICMP]](s32), %bb.1
  ; CHECK-NEXT:   G_BR %bb.2
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.1:
  ; CHECK-NEXT:   successors: %bb.3(0x80000000)
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[ADD:%[0-9]+]]:_(s32) = G_ADD [[COPY]], [[C1]]
  ; CHECK-NEXT:   [[TRUNC:%[0-9]+]]:_(s16) = G_TRUNC [[ADD]](s32)
  ; CHECK-NEXT:   G_BR %bb.3
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.2:
  ; CHECK-NEXT:   successors: %bb.3(0x80000000)
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[ADD1:%[0-9]+]]:_(s32) = G_ADD [[COPY]], [[C2]]
  ; CHECK-NEXT:   [[TRUNC1:%[0-9]+]]:_(s16) = G_TRUNC [[ADD1]](s32)
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.3:
  ; CHECK-NEXT:   [[PHI:%[0-9]+]]:_(s16) = G_PHI [[TRUNC]](s16), %bb.1, [[TRUNC1]](s16), %bb.2
  ; CHECK-NEXT:   [[ANYEXT:%[0-9]+]]:_(s32) = G_ANYEXT [[PHI]](s16)
  ; CHECK-NEXT:   [[C3:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
  ; CHECK-NEXT:   [[AND:%[0-9]+]]:_(s32) = G_AND [[ANYEXT]], [[C3]]
  ; CHECK-NEXT:   $w0 = COPY [[AND]](s32)
  ; CHECK-NEXT:   RET_ReallyLR implicit $w0
  bb.0:
   ; Test that we insert legalization artifacts(Truncs here) into the correct BBs
   ; while legalizing the G_PHI to s16.


    successors: %bb.1(0x40000000), %bb.2(0x40000000)
    liveins: $w0

    %0(s32) = COPY $w0
    %1(s32) = G_CONSTANT i32 0
    %3(s32) = G_CONSTANT i32 1
    %6(s32) = G_CONSTANT i32 2
    %2(s1) = G_ICMP intpred(ugt), %0(s32), %1
    G_BRCOND %2(s1), %bb.1
    G_BR %bb.2

  bb.1:
    successors: %bb.3(0x80000000)

    %4(s32) = G_ADD %0, %3
    %5(s1) = G_TRUNC %4(s32)
    G_BR %bb.3

  bb.2:
    successors: %bb.3(0x80000000)

    %7(s32) = G_ADD %0, %6
    %8(s1) = G_TRUNC %7(s32)

  bb.3:
    %9(s1) = G_PHI %5(s1), %bb.1, %8(s1), %bb.2
    %11:_(s1) = G_PHI %5(s1), %bb.1, %8(s1), %bb.2
    %10(s32) = G_ZEXT %9(s1)
    $w0 = COPY %10(s32)
    RET_ReallyLR implicit $w0

...
---
name:            legalize_phi_ptr
alignment:       4
exposesReturnsTwice: false
legalized:       false
regBankSelected: false
selected:        false
tracksRegLiveness: true
registers:
  - { id: 0, class: _, preferred-register: '' }
  - { id: 1, class: _, preferred-register: '' }
  - { id: 2, class: _, preferred-register: '' }
  - { id: 3, class: _, preferred-register: '' }
  - { id: 4, class: _, preferred-register: '' }
  - { id: 5, class: _, preferred-register: '' }
liveins:
body:             |
  ; CHECK-LABEL: name: legalize_phi_ptr
  ; CHECK: bb.0:
  ; CHECK-NEXT:   successors: %bb.1(0x40000000), %bb.2(0x40000000)
  ; CHECK-NEXT:   liveins: $w2, $x0, $x1
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[COPY:%[0-9]+]]:_(p0) = COPY $x0
  ; CHECK-NEXT:   [[COPY1:%[0-9]+]]:_(p0) = COPY $x1
  ; CHECK-NEXT:   [[COPY2:%[0-9]+]]:_(s32) = COPY $w2
  ; CHECK-NEXT:   [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
  ; CHECK-NEXT:   [[AND:%[0-9]+]]:_(s32) = G_AND [[COPY2]], [[C]]
  ; CHECK-NEXT:   G_BRCOND [[AND]](s32), %bb.1
  ; CHECK-NEXT:   G_BR %bb.2
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.1:
  ; CHECK-NEXT:   successors: %bb.2(0x80000000)
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.2:
  ; CHECK-NEXT:   [[PHI:%[0-9]+]]:_(p0) = G_PHI [[COPY]](p0), %bb.0, [[COPY1]](p0), %bb.1
  ; CHECK-NEXT:   $x0 = COPY [[PHI]](p0)
  ; CHECK-NEXT:   RET_ReallyLR implicit $x0
  bb.1:

    successors: %bb.2, %bb.3
    liveins: $w2, $x0, $x1

    %0(p0) = COPY $x0
    %1(p0) = COPY $x1
    %4(s32) = COPY $w2
    %2(s1) = G_TRUNC %4(s32)
    G_BRCOND %2(s1), %bb.2
    G_BR %bb.3

  bb.2:
    successors: %bb.3

  bb.3:
    %3(p0) = G_PHI %0(p0), %bb.1, %1(p0), %bb.2
    $x0 = COPY %3(p0)
    RET_ReallyLR implicit $x0

...
---
name:            legalize_phi_empty
alignment:       4
exposesReturnsTwice: false
legalized:       false
regBankSelected: false
selected:        false
tracksRegLiveness: true
registers:
  - { id: 0, class: _, preferred-register: '' }
  - { id: 1, class: _, preferred-register: '' }
  - { id: 2, class: _, preferred-register: '' }
  - { id: 3, class: _, preferred-register: '' }
  - { id: 4, class: _, preferred-register: '' }
  - { id: 5, class: _, preferred-register: '' }
  - { id: 6, class: _, preferred-register: '' }
  - { id: 7, class: _, preferred-register: '' }
  - { id: 8, class: _, preferred-register: '' }
  - { id: 9, class: _, preferred-register: '' }
  - { id: 10, class: _, preferred-register: '' }
liveins:
body:             |
  ; CHECK-LABEL: name: legalize_phi_empty
  ; CHECK: bb.0:
  ; CHECK-NEXT:   successors: %bb.1(0x40000000), %bb.2(0x40000000)
  ; CHECK-NEXT:   liveins: $w0
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[COPY:%[0-9]+]]:_(s32) = COPY $w0
  ; CHECK-NEXT:   [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
  ; CHECK-NEXT:   [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 3
  ; CHECK-NEXT:   [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
  ; CHECK-NEXT:   [[ICMP:%[0-9]+]]:_(s32) = G_ICMP intpred(ugt), [[COPY]](s32), [[C]]
  ; CHECK-NEXT:   [[ADD:%[0-9]+]]:_(s32) = G_ADD [[COPY]], [[C1]]
  ; CHECK-NEXT:   G_BRCOND [[ICMP]](s32), %bb.1
  ; CHECK-NEXT:   G_BR %bb.2
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.1:
  ; CHECK-NEXT:   successors: %bb.3(0x80000000)
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[ADD1:%[0-9]+]]:_(s32) = G_ADD [[COPY]], [[C2]]
  ; CHECK-NEXT:   [[TRUNC:%[0-9]+]]:_(s16) = G_TRUNC [[ADD1]](s32)
  ; CHECK-NEXT:   G_BR %bb.3
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.2:
  ; CHECK-NEXT:   successors: %bb.3(0x80000000)
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[TRUNC1:%[0-9]+]]:_(s16) = G_TRUNC [[ADD]](s32)
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.3:
  ; CHECK-NEXT:   [[PHI:%[0-9]+]]:_(s16) = G_PHI [[TRUNC]](s16), %bb.1, [[TRUNC1]](s16), %bb.2
  ; CHECK-NEXT:   [[ANYEXT:%[0-9]+]]:_(s32) = G_ANYEXT [[PHI]](s16)
  ; CHECK-NEXT:   [[C3:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
  ; CHECK-NEXT:   [[AND:%[0-9]+]]:_(s32) = G_AND [[ANYEXT]], [[C3]]
  ; CHECK-NEXT:   $w0 = COPY [[AND]](s32)
  ; CHECK-NEXT:   RET_ReallyLR implicit $w0
  bb.0:
    successors: %bb.1(0x40000000), %bb.2(0x40000000)
    liveins: $w0
   ; Test that we properly legalize a phi with a predecessor that's empty




    %0(s32) = COPY $w0
    %1(s32) = G_CONSTANT i32 0
    %3(s32) = G_CONSTANT i32 3
    %6(s32) = G_CONSTANT i32 1
    %2(s1) = G_ICMP intpred(ugt), %0(s32), %1
    %4(s32) = G_ADD %0, %3
    %5(s1) = G_TRUNC %4(s32)
    G_BRCOND %2(s1), %bb.1
    G_BR %bb.2

  bb.1:
    successors: %bb.3(0x80000000)

    %7(s32) = G_ADD %0, %6
    %8(s1) = G_TRUNC %7(s32)
    G_BR %bb.3

  bb.2:
    successors: %bb.3(0x80000000)


  bb.3:
    %9(s1) = G_PHI %8(s1), %bb.1, %5(s1), %bb.2
    %10(s32) = G_ZEXT %9(s1)
    $w0 = COPY %10(s32)
    RET_ReallyLR implicit $w0

...
---
name:            legalize_phi_loop
alignment:       4
exposesReturnsTwice: false
legalized:       false
regBankSelected: false
selected:        false
tracksRegLiveness: true
registers:
  - { id: 0, class: _, preferred-register: '' }
  - { id: 1, class: _, preferred-register: '' }
  - { id: 2, class: _, preferred-register: '' }
  - { id: 3, class: _, preferred-register: '' }
  - { id: 4, class: _, preferred-register: '' }
  - { id: 5, class: _, preferred-register: '' }
  - { id: 6, class: _, preferred-register: '' }
  - { id: 7, class: _, preferred-register: '' }
liveins:
body:             |
  ; CHECK-LABEL: name: legalize_phi_loop
  ; CHECK: bb.0:
  ; CHECK-NEXT:   successors: %bb.1(0x80000000)
  ; CHECK-NEXT:   liveins: $w0
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[COPY:%[0-9]+]]:_(s32) = COPY $w0
  ; CHECK-NEXT:   [[C:%[0-9]+]]:_(s16) = G_CONSTANT i16 0
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.1:
  ; CHECK-NEXT:   successors: %bb.1(0x40000000), %bb.2(0x40000000)
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[PHI:%[0-9]+]]:_(s16) = G_PHI [[C]](s16), %bb.0, %14(s16), %bb.1
  ; CHECK-NEXT:   [[ANYEXT:%[0-9]+]]:_(s32) = G_ANYEXT [[PHI]](s16)
  ; CHECK-NEXT:   [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
  ; CHECK-NEXT:   [[ADD:%[0-9]+]]:_(s32) = G_ADD [[ANYEXT]], [[C1]]
  ; CHECK-NEXT:   [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 255
  ; CHECK-NEXT:   [[AND:%[0-9]+]]:_(s32) = G_AND [[ADD]], [[C2]]
  ; CHECK-NEXT:   [[ICMP:%[0-9]+]]:_(s32) = G_ICMP intpred(ugt), [[AND]](s32), [[COPY]]
  ; CHECK-NEXT:   [[TRUNC:%[0-9]+]]:_(s16) = G_TRUNC [[ADD]](s32)
  ; CHECK-NEXT:   G_BRCOND [[ICMP]](s32), %bb.1
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.2:
  ; CHECK-NEXT:   [[C3:%[0-9]+]]:_(s32) = G_CONSTANT i32 255
  ; CHECK-NEXT:   [[AND1:%[0-9]+]]:_(s32) = G_AND [[ADD]], [[C3]]
  ; CHECK-NEXT:   $w0 = COPY [[AND1]](s32)
  ; CHECK-NEXT:   RET_ReallyLR implicit $w0
  bb.0:
    successors: %bb.1(0x80000000)
    liveins: $w0
   ; Test that we properly legalize a phi that uses a value from the same BB

    %0(s32) = COPY $w0
    %2(s8) = G_CONSTANT i8 1
    %7(s8) = G_CONSTANT i8 0

  bb.1:
    successors: %bb.1(0x40000000), %bb.3(0x40000000)

    %1(s8) = G_PHI %7(s8), %bb.0, %3(s8), %bb.1
    %3(s8) = G_ADD %1, %2
    %4(s32) = G_ZEXT %3(s8)
    %5(s1) = G_ICMP intpred(ugt), %4(s32), %0
    G_BRCOND %5(s1), %bb.1

  bb.3:
    %6(s32) = G_ZEXT %3(s8)
    $w0 = COPY %6(s32)
    RET_ReallyLR implicit $w0

...
---
name:            legalize_phi_cycle
alignment:       4
exposesReturnsTwice: false
legalized:       false
regBankSelected: false
selected:        false
tracksRegLiveness: true
registers:
  - { id: 0, class: _, preferred-register: '' }
  - { id: 1, class: _, preferred-register: '' }
  - { id: 2, class: _, preferred-register: '' }
  - { id: 3, class: _, preferred-register: '' }
  - { id: 4, class: _, preferred-register: '' }
liveins:
body:             |
  ; CHECK-LABEL: name: legalize_phi_cycle
  ; CHECK: bb.0:
  ; CHECK-NEXT:   successors: %bb.1(0x80000000)
  ; CHECK-NEXT:   liveins: $w0
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[COPY:%[0-9]+]]:_(s32) = COPY $w0
  ; CHECK-NEXT:   [[C:%[0-9]+]]:_(s16) = G_CONSTANT i16 0
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.1:
  ; CHECK-NEXT:   successors: %bb.1(0x40000000), %bb.2(0x40000000)
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[PHI:%[0-9]+]]:_(s16) = G_PHI [[C]](s16), %bb.0, [[PHI]](s16), %bb.1
  ; CHECK-NEXT:   [[ANYEXT:%[0-9]+]]:_(s32) = G_ANYEXT [[PHI]](s16)
  ; CHECK-NEXT:   [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 255
  ; CHECK-NEXT:   [[AND:%[0-9]+]]:_(s32) = G_AND [[ANYEXT]], [[C1]]
  ; CHECK-NEXT:   [[ICMP:%[0-9]+]]:_(s32) = G_ICMP intpred(ugt), [[AND]](s32), [[COPY]]
  ; CHECK-NEXT:   G_BRCOND [[ICMP]](s32), %bb.1
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.2:
  ; CHECK-NEXT:   $w0 = COPY [[AND]](s32)
  ; CHECK-NEXT:   RET_ReallyLR implicit $w0
  bb.0:
    successors: %bb.1(0x80000000)
    liveins: $w0
   ; Test that we properly legalize a phi that uses itself


    %0(s32) = COPY $w0
    %4(s8) = G_CONSTANT i8 0

  bb.1:
    successors: %bb.1(0x40000000), %bb.3(0x40000000)

    %1(s8) = G_PHI %4(s8), %bb.0, %1(s8), %bb.1
    %2(s32) = G_ZEXT %1(s8)
    %3(s1) = G_ICMP intpred(ugt), %2(s32), %0
    G_BRCOND %3(s1), %bb.1

  bb.3:
    $w0 = COPY %2(s32)
    RET_ReallyLR implicit $w0

...
---
name:            legalize_phi_same_bb
alignment:       4
exposesReturnsTwice: false
legalized:       false
regBankSelected: false
selected:        false
tracksRegLiveness: true
registers:
  - { id: 0, class: _, preferred-register: '' }
  - { id: 1, class: _, preferred-register: '' }
  - { id: 2, class: _, preferred-register: '' }
  - { id: 3, class: _, preferred-register: '' }
  - { id: 4, class: _, preferred-register: '' }
  - { id: 5, class: _, preferred-register: '' }
  - { id: 6, class: _, preferred-register: '' }
  - { id: 7, class: _, preferred-register: '' }
  - { id: 8, class: _, preferred-register: '' }
  - { id: 9, class: _, preferred-register: '' }
  - { id: 10, class: _, preferred-register: '' }
  - { id: 11, class: _, preferred-register: '' }
  - { id: 12, class: _, preferred-register: '' }
  - { id: 13, class: _, preferred-register: '' }
  - { id: 14, class: _, preferred-register: '' }
liveins:
body:             |
  ; CHECK-LABEL: name: legalize_phi_same_bb
  ; CHECK: bb.0:
  ; CHECK-NEXT:   successors: %bb.1(0x40000000), %bb.2(0x40000000)
  ; CHECK-NEXT:   liveins: $w0
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[COPY:%[0-9]+]]:_(s32) = COPY $w0
  ; CHECK-NEXT:   [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
  ; CHECK-NEXT:   [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 3
  ; CHECK-NEXT:   [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
  ; CHECK-NEXT:   [[ICMP:%[0-9]+]]:_(s32) = G_ICMP intpred(ugt), [[COPY]](s32), [[C]]
  ; CHECK-NEXT:   [[ADD:%[0-9]+]]:_(s32) = G_ADD [[COPY]], [[C1]]
  ; CHECK-NEXT:   G_BRCOND [[ICMP]](s32), %bb.1
  ; CHECK-NEXT:   G_BR %bb.2
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.1:
  ; CHECK-NEXT:   successors: %bb.3(0x80000000)
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[ADD1:%[0-9]+]]:_(s32) = G_ADD [[COPY]], [[C2]]
  ; CHECK-NEXT:   [[TRUNC:%[0-9]+]]:_(s16) = G_TRUNC [[ADD1]](s32)
  ; CHECK-NEXT:   [[TRUNC1:%[0-9]+]]:_(s16) = G_TRUNC [[ADD1]](s32)
  ; CHECK-NEXT:   G_BR %bb.3
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.2:
  ; CHECK-NEXT:   successors: %bb.3(0x80000000)
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[C3:%[0-9]+]]:_(s16) = G_CONSTANT i16 42
  ; CHECK-NEXT:   [[TRUNC2:%[0-9]+]]:_(s16) = G_TRUNC [[ADD]](s32)
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.3:
  ; CHECK-NEXT:   [[PHI:%[0-9]+]]:_(s16) = G_PHI [[TRUNC1]](s16), %bb.1, [[TRUNC2]](s16), %bb.2
  ; CHECK-NEXT:   [[PHI1:%[0-9]+]]:_(s16) = G_PHI [[TRUNC]](s16), %bb.1, [[C3]](s16), %bb.2
  ; CHECK-NEXT:   [[ANYEXT:%[0-9]+]]:_(s32) = G_ANYEXT [[PHI]](s16)
  ; CHECK-NEXT:   [[C4:%[0-9]+]]:_(s32) = G_CONSTANT i32 255
  ; CHECK-NEXT:   [[AND:%[0-9]+]]:_(s32) = G_AND [[ANYEXT]], [[C4]]
  ; CHECK-NEXT:   [[ANYEXT1:%[0-9]+]]:_(s32) = G_ANYEXT [[PHI1]](s16)
  ; CHECK-NEXT:   [[AND1:%[0-9]+]]:_(s32) = G_AND [[ANYEXT1]], [[C4]]
  ; CHECK-NEXT:   [[ADD2:%[0-9]+]]:_(s32) = G_ADD [[AND]], [[AND1]]
  ; CHECK-NEXT:   $w0 = COPY [[ADD2]](s32)
  ; CHECK-NEXT:   RET_ReallyLR implicit $w0
  bb.0:
    successors: %bb.1(0x40000000), %bb.2(0x40000000)
    liveins: $w0
   ; Make sure that we correctly insert the new legalized G_PHI at the
   ; correct location (ie make sure G_PHIs are the first insts in the BB).




    %0(s32) = COPY $w0
    %1(s32) = G_CONSTANT i32 0
    %3(s32) = G_CONSTANT i32 3
    %6(s32) = G_CONSTANT i32 1
    %14(s8) = G_CONSTANT i8 42
    %2(s1) = G_ICMP intpred(ugt), %0(s32), %1
    %4(s32) = G_ADD %0, %3
    %5(s8) = G_TRUNC %4(s32)
    G_BRCOND %2(s1), %bb.1
    G_BR %bb.2

  bb.1:
    successors: %bb.3(0x80000000)

    %7(s32) = G_ADD %0, %6
    %8(s8) = G_TRUNC %7(s32)
    G_BR %bb.3

  bb.2:
    successors: %bb.3(0x80000000)


  bb.3:
    %9(s8) = G_PHI %8(s8), %bb.1, %5(s8), %bb.2
    %10(s8) = G_PHI %8(s8), %bb.1, %14(s8), %bb.2
    %11(s32) = G_ZEXT %9(s8)
    %12(s32) = G_ZEXT %10(s8)
    %13(s32) = G_ADD %11, %12
    $w0 = COPY %13(s32)
    RET_ReallyLR implicit $w0

...
---
name:            legalize_phi_diff_bb
alignment:       4
exposesReturnsTwice: false
legalized:       false
regBankSelected: false
selected:        false
tracksRegLiveness: true
registers:
  - { id: 0, class: _, preferred-register: '' }
  - { id: 1, class: _, preferred-register: '' }
  - { id: 2, class: _, preferred-register: '' }
  - { id: 3, class: _, preferred-register: '' }
  - { id: 4, class: _, preferred-register: '' }
  - { id: 5, class: _, preferred-register: '' }
  - { id: 6, class: _, preferred-register: '' }
  - { id: 7, class: _, preferred-register: '' }
  - { id: 8, class: _, preferred-register: '' }
  - { id: 9, class: _, preferred-register: '' }
  - { id: 10, class: _, preferred-register: '' }
  - { id: 11, class: _, preferred-register: '' }
  - { id: 12, class: _, preferred-register: '' }
  - { id: 13, class: _, preferred-register: '' }
  - { id: 14, class: _, preferred-register: '' }
  - { id: 15, class: _, preferred-register: '' }
liveins:
body:             |
  ; CHECK-LABEL: name: legalize_phi_diff_bb
  ; CHECK: bb.0:
  ; CHECK-NEXT:   successors: %bb.1(0x40000000), %bb.2(0x40000000)
  ; CHECK-NEXT:   liveins: $w0, $w1
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[COPY:%[0-9]+]]:_(s32) = COPY $w0
  ; CHECK-NEXT:   [[COPY1:%[0-9]+]]:_(s32) = COPY $w1
  ; CHECK-NEXT:   [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
  ; CHECK-NEXT:   [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 3
  ; CHECK-NEXT:   [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
  ; CHECK-NEXT:   [[C3:%[0-9]+]]:_(s32) = G_CONSTANT i32 44
  ; CHECK-NEXT:   [[ICMP:%[0-9]+]]:_(s32) = G_ICMP intpred(ugt), [[COPY]](s32), [[C]]
  ; CHECK-NEXT:   [[ADD:%[0-9]+]]:_(s32) = G_ADD [[COPY]], [[C1]]
  ; CHECK-NEXT:   [[TRUNC:%[0-9]+]]:_(s16) = G_TRUNC [[ADD]](s32)
  ; CHECK-NEXT:   [[TRUNC1:%[0-9]+]]:_(s16) = G_TRUNC [[ADD]](s32)
  ; CHECK-NEXT:   G_BRCOND [[ICMP]](s32), %bb.1
  ; CHECK-NEXT:   G_BR %bb.2
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.1:
  ; CHECK-NEXT:   successors: %bb.2(0x40000000), %bb.1(0x40000000)
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[PHI:%[0-9]+]]:_(s16) = G_PHI [[TRUNC1]](s16), %bb.0, %22(s16), %bb.1
  ; CHECK-NEXT:   [[ANYEXT:%[0-9]+]]:_(s32) = G_ANYEXT [[PHI]](s16)
  ; CHECK-NEXT:   [[C4:%[0-9]+]]:_(s32) = G_CONSTANT i32 255
  ; CHECK-NEXT:   [[AND:%[0-9]+]]:_(s32) = G_AND [[ANYEXT]], [[C4]]
  ; CHECK-NEXT:   [[ADD1:%[0-9]+]]:_(s32) = G_ADD [[AND]], [[C2]]
  ; CHECK-NEXT:   [[ICMP1:%[0-9]+]]:_(s32) = G_ICMP intpred(ugt), [[ADD1]](s32), [[C3]]
  ; CHECK-NEXT:   [[C5:%[0-9]+]]:_(s16) = G_CONSTANT i16 43
  ; CHECK-NEXT:   G_BRCOND [[ICMP1]](s32), %bb.2
  ; CHECK-NEXT:   G_BR %bb.1
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.2:
  ; CHECK-NEXT:   [[PHI1:%[0-9]+]]:_(s16) = G_PHI [[PHI]](s16), %bb.1, [[TRUNC]](s16), %bb.0
  ; CHECK-NEXT:   [[ANYEXT1:%[0-9]+]]:_(s32) = G_ANYEXT [[PHI1]](s16)
  ; CHECK-NEXT:   [[C6:%[0-9]+]]:_(s32) = G_CONSTANT i32 255
  ; CHECK-NEXT:   [[AND1:%[0-9]+]]:_(s32) = G_AND [[ANYEXT1]], [[C6]]
  ; CHECK-NEXT:   $w0 = COPY [[AND1]](s32)
  ; CHECK-NEXT:   RET_ReallyLR implicit $w0
  bb.0:
    successors: %bb.1(0x40000000), %bb.3(0x40000000)
    liveins: $w0, $w1
   ; Make sure that we correctly legalize PHIs sharing common defs
   ; in different BBs.



    %0(s32) = COPY $w0
    %1(s32) = COPY $w1
    %2(s32) = G_CONSTANT i32 0
    %4(s32) = G_CONSTANT i32 3
    %9(s32) = G_CONSTANT i32 1
    %11(s32) = G_CONSTANT i32 44
    %15(s8) = G_CONSTANT i8 43
    %3(s1) = G_ICMP intpred(ugt), %0(s32), %2
    %5(s32) = G_ADD %0, %4
    %6(s8) = G_TRUNC %5(s32)
    G_BRCOND %3(s1), %bb.1
    G_BR %bb.3

  bb.1:
    successors: %bb.3(0x40000000), %bb.1(0x40000000)

    %7(s8) = G_PHI %6(s8), %bb.0, %15(s8), %bb.1
    %8(s32) = G_ZEXT %7(s8)
    %10(s32) = G_ADD %8, %9
    %12(s1) = G_ICMP intpred(ugt), %10(s32), %11
    G_BRCOND %12(s1), %bb.3
    G_BR %bb.1

  bb.3:
    %13(s8) = G_PHI %7(s8), %bb.1, %6(s8), %bb.0
    %14(s32) = G_ZEXT %13(s8)
    $w0 = COPY %14(s32)
    RET_ReallyLR implicit $w0

...
---
name:            legalize_phi_check_insertpt
alignment:       4
exposesReturnsTwice: false
legalized:       false
regBankSelected: false
selected:        false
tracksRegLiveness: true
body:             |
  ; CHECK-LABEL: name: legalize_phi_check_insertpt
  ; CHECK: bb.0:
  ; CHECK-NEXT:   successors: %bb.1(0x80000000)
  ; CHECK-NEXT:   liveins: $x0, $x1
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[COPY:%[0-9]+]]:_(s64) = COPY $x0
  ; CHECK-NEXT:   [[COPY1:%[0-9]+]]:_(p0) = COPY $x1
  ; CHECK-NEXT:   [[DEF:%[0-9]+]]:_(s64) = G_IMPLICIT_DEF
  ; CHECK-NEXT:   G_BR %bb.1
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.1:
  ; CHECK-NEXT:   [[PHI:%[0-9]+]]:_(s64) = G_PHI [[DEF]](s64), %bb.0
  ; CHECK-NEXT:   [[PHI1:%[0-9]+]]:_(s64) = G_PHI [[DEF]](s64), %bb.0
  ; CHECK-NEXT:   [[PHI2:%[0-9]+]]:_(s64) = G_PHI [[COPY]](s64), %bb.0
  ; CHECK-NEXT:   [[MV:%[0-9]+]]:_(s128) = G_MERGE_VALUES [[PHI]](s64), [[PHI1]](s64)
  ; CHECK-NEXT:   G_STORE [[MV]](s128), [[COPY1]](p0) :: (store (s128))
  ; CHECK-NEXT:   G_STORE [[PHI2]](s64), [[COPY1]](p0) :: (store (s64))
  ; CHECK-NEXT:   RET_ReallyLR
  ; Check that the G_MERGE here gets inserted after all the PHIs.
  bb.0:
    successors: %bb.1(0x40000000)
    liveins: $x0, $x1

    %0:_(s64) = COPY $x0
    %1:_(p0) = COPY $x1
    %2:_(s128) = G_IMPLICIT_DEF
    G_BR %bb.1

  bb.1:
    %3:_(s128) = G_PHI %2(s128), %bb.0
    %4:_(s64) = G_PHI %0(s64), %bb.0
    G_STORE %3(s128), %1(p0) :: (store (s128))
    G_STORE %4(s64), %1(p0) :: (store (s64))
    RET_ReallyLR

...
---
name:            legalize_phi_vector
tracksRegLiveness: true
body:             |
  ; CHECK-LABEL: name: legalize_phi_vector
  ; CHECK: bb.0:
  ; CHECK-NEXT:   successors: %bb.1(0x80000000)
  ; CHECK-NEXT:   liveins: $q0, $x1
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[COPY:%[0-9]+]]:_(<16 x s8>) = COPY $q0
  ; CHECK-NEXT:   G_BR %bb.1
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.1:
  ; CHECK-NEXT:   [[PHI:%[0-9]+]]:_(<16 x s8>) = G_PHI [[COPY]](<16 x s8>), %bb.0
  ; CHECK-NEXT:   $q0 = COPY [[PHI]](<16 x s8>)
  ; CHECK-NEXT:   RET_ReallyLR
  bb.0:
    successors: %bb.1
    liveins: $q0, $x1

    %0:_(<16 x s8>) = COPY $q0
    G_BR %bb.1

  bb.1:
    %3:_(<16 x s8>) = G_PHI %0(<16 x s8>), %bb.0
    $q0 = COPY %3(<16 x s8>)
    RET_ReallyLR
...
---
name:             s88
tracksRegLiveness: true
liveins:
body:             |
  ; CHECK-LABEL: name: s88
  ; CHECK: bb.0:
  ; CHECK-NEXT:   successors: %bb.1(0x40000000), %bb.2(0x40000000)
  ; CHECK-NEXT:   liveins: $x0
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[DEF:%[0-9]+]]:_(s32) = G_IMPLICIT_DEF
  ; CHECK-NEXT:   [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
  ; CHECK-NEXT:   [[AND:%[0-9]+]]:_(s32) = G_AND [[DEF]], [[C]]
  ; CHECK-NEXT:   G_BRCOND [[AND]](s32), %bb.1
  ; CHECK-NEXT:   G_BR %bb.2
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.1:
  ; CHECK-NEXT:   successors: %bb.3(0x80000000)
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[DEF1:%[0-9]+]]:_(s64) = G_IMPLICIT_DEF
  ; CHECK-NEXT:   G_BR %bb.3
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.2:
  ; CHECK-NEXT:   successors: %bb.3(0x80000000)
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[DEF2:%[0-9]+]]:_(s64) = G_IMPLICIT_DEF
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.3:
  ; CHECK-NEXT:   [[PHI:%[0-9]+]]:_(s64) = G_PHI [[DEF1]](s64), %bb.1, [[DEF2]](s64), %bb.2
  ; CHECK-NEXT:   $x0 = COPY [[PHI]](s64)
  ; CHECK-NEXT:   RET_ReallyLR implicit $x0
  bb.0:
    successors: %bb.1(0x40000000), %bb.2(0x40000000)
    liveins: $x0
    %cond:_(s1) = G_IMPLICIT_DEF
    G_BRCOND %cond(s1), %bb.1
    G_BR %bb.2
  bb.1:
    successors: %bb.3(0x80000000)
    %imp_1:_(s88) = G_IMPLICIT_DEF
    G_BR %bb.3
  bb.2:
    successors: %bb.3(0x80000000)
    %imp_2:_(s88) = G_IMPLICIT_DEF
  bb.3:
    %phi:_(s88) = G_PHI %imp_1:_(s88), %bb.1, %imp_2:_(s88), %bb.2
    %trunc:_(s64) = G_TRUNC %phi
    $x0 = COPY %trunc
    RET_ReallyLR implicit $x0
...
---
name:            v4s64
alignment:       4
tracksRegLiveness: true
body:             |
  ; CHECK-LABEL: name: v4s64
  ; CHECK: bb.0:
  ; CHECK-NEXT:   successors: %bb.1(0x50000000), %bb.2(0x30000000)
  ; CHECK-NEXT:   liveins: $x0, $x1
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   %ptr1:_(p0) = COPY $x1
  ; CHECK-NEXT:   %ptr2:_(p0) = COPY $x0
  ; CHECK-NEXT:   [[LOAD:%[0-9]+]]:_(<2 x s64>) = G_LOAD %ptr1(p0) :: (load (<2 x s64>), align 32)
  ; CHECK-NEXT:   [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 16
  ; CHECK-NEXT:   [[PTR_ADD:%[0-9]+]]:_(p0) = G_PTR_ADD %ptr1, [[C]](s64)
  ; CHECK-NEXT:   [[LOAD1:%[0-9]+]]:_(<2 x s64>) = G_LOAD [[PTR_ADD]](p0) :: (load (<2 x s64>) from unknown-address + 16)
  ; CHECK-NEXT:   [[DEF:%[0-9]+]]:_(s32) = G_IMPLICIT_DEF
  ; CHECK-NEXT:   [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
  ; CHECK-NEXT:   [[AND:%[0-9]+]]:_(s32) = G_AND [[DEF]], [[C1]]
  ; CHECK-NEXT:   G_BRCOND [[AND]](s32), %bb.2
  ; CHECK-NEXT:   G_BR %bb.1
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.1:
  ; CHECK-NEXT:   successors: %bb.2(0x80000000)
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[LOAD2:%[0-9]+]]:_(<2 x s64>) = G_LOAD %ptr2(p0) :: (load (<2 x s64>), align 32)
  ; CHECK-NEXT:   [[C2:%[0-9]+]]:_(s64) = G_CONSTANT i64 16
  ; CHECK-NEXT:   [[PTR_ADD1:%[0-9]+]]:_(p0) = G_PTR_ADD %ptr2, [[C2]](s64)
  ; CHECK-NEXT:   [[LOAD3:%[0-9]+]]:_(<2 x s64>) = G_LOAD [[PTR_ADD1]](p0) :: (load (<2 x s64>) from unknown-address + 16)
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.2:
  ; CHECK-NEXT:   [[PHI:%[0-9]+]]:_(<2 x s64>) = G_PHI [[LOAD2]](<2 x s64>), %bb.1, [[LOAD]](<2 x s64>), %bb.0
  ; CHECK-NEXT:   [[PHI1:%[0-9]+]]:_(<2 x s64>) = G_PHI [[LOAD3]](<2 x s64>), %bb.1, [[LOAD1]](<2 x s64>), %bb.0
  ; CHECK-NEXT:   $q0 = COPY [[PHI]](<2 x s64>)
  ; CHECK-NEXT:   $q1 = COPY [[PHI1]](<2 x s64>)
  ; CHECK-NEXT:   RET_ReallyLR implicit $q0, implicit $q1
  bb.0:
    successors: %bb.1(0x50000000), %bb.2(0x30000000)
    liveins: $x0, $x1

    %ptr1:_(p0) = COPY $x1
    %ptr2:_(p0) = COPY $x0
    %cond:_(s1) = G_IMPLICIT_DEF
    %val_1:_(<4 x s64>) = G_LOAD %ptr1(p0) :: (load (<4 x s64>))
    G_BRCOND %cond(s1), %bb.2
    G_BR %bb.1
  bb.1:
    %val_2:_(<4 x s64>) = G_LOAD %ptr2(p0) :: (load (<4 x s64>))
  bb.2:
    %phi:_(<4 x s64>) = G_PHI %val_2(<4 x s64>), %bb.1, %val_1(<4 x s64>), %bb.0
    %unmerge_1:_(<2 x s64>), %unmerge_2:_(<2 x s64>) = G_UNMERGE_VALUES %phi(<4 x s64>)
    $q0 = COPY %unmerge_1(<2 x s64>)
    $q1 = COPY %unmerge_2(<2 x s64>)
    RET_ReallyLR implicit $q0, implicit $q1
...
---
name:            v8s32
alignment:       4
tracksRegLiveness: true
body:             |
  ; CHECK-LABEL: name: v8s32
  ; CHECK: bb.0:
  ; CHECK-NEXT:   successors: %bb.1(0x50000000), %bb.2(0x30000000)
  ; CHECK-NEXT:   liveins: $x0, $x1
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[DEF:%[0-9]+]]:_(<4 x s32>) = G_IMPLICIT_DEF
  ; CHECK-NEXT:   [[DEF1:%[0-9]+]]:_(s32) = G_IMPLICIT_DEF
  ; CHECK-NEXT:   [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
  ; CHECK-NEXT:   [[AND:%[0-9]+]]:_(s32) = G_AND [[DEF1]], [[C]]
  ; CHECK-NEXT:   G_BRCOND [[AND]](s32), %bb.2
  ; CHECK-NEXT:   G_BR %bb.1
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.1:
  ; CHECK-NEXT:   successors: %bb.2(0x80000000)
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[DEF2:%[0-9]+]]:_(<4 x s32>) = G_IMPLICIT_DEF
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.2:
  ; CHECK-NEXT:   [[PHI:%[0-9]+]]:_(<4 x s32>) = G_PHI [[DEF2]](<4 x s32>), %bb.1, [[DEF]](<4 x s32>), %bb.0
  ; CHECK-NEXT:   %one:_(s64) = G_CONSTANT i64 1
  ; CHECK-NEXT:   %extract:_(s32) = G_EXTRACT_VECTOR_ELT [[PHI]](<4 x s32>), %one(s64)
  ; CHECK-NEXT:   $w0 = COPY %extract(s32)
  ; CHECK-NEXT:   RET_ReallyLR implicit $w0
  bb.0:
    successors: %bb.1(0x50000000), %bb.2(0x30000000)
    liveins: $x0, $x1
    %cond:_(s1) = G_IMPLICIT_DEF
    %val_1:_(<8 x s32>) = G_IMPLICIT_DEF
    G_BRCOND %cond(s1), %bb.2
    G_BR %bb.1
  bb.1:
    %val_2:_(<8 x s32>) = G_IMPLICIT_DEF
  bb.2:
    %phi:_(<8 x s32>) = G_PHI %val_2(<8 x s32>), %bb.1, %val_1(<8 x s32>), %bb.0
    %one:_(s64) = G_CONSTANT i64 1
    %extract:_(s32) = G_EXTRACT_VECTOR_ELT %phi(<8 x s32>), %one(s64)
    $w0 = COPY %extract
    RET_ReallyLR implicit $w0
...
---
name:            v16s16
alignment:       4
tracksRegLiveness: true
body:             |
  ; CHECK-LABEL: name: v16s16
  ; CHECK: bb.0:
  ; CHECK-NEXT:   successors: %bb.1(0x50000000), %bb.2(0x30000000)
  ; CHECK-NEXT:   liveins: $x0, $x1
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[DEF:%[0-9]+]]:_(<8 x s16>) = G_IMPLICIT_DEF
  ; CHECK-NEXT:   [[DEF1:%[0-9]+]]:_(s32) = G_IMPLICIT_DEF
  ; CHECK-NEXT:   [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
  ; CHECK-NEXT:   [[AND:%[0-9]+]]:_(s32) = G_AND [[DEF1]], [[C]]
  ; CHECK-NEXT:   G_BRCOND [[AND]](s32), %bb.2
  ; CHECK-NEXT:   G_BR %bb.1
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.1:
  ; CHECK-NEXT:   successors: %bb.2(0x80000000)
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[DEF2:%[0-9]+]]:_(<8 x s16>) = G_IMPLICIT_DEF
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.2:
  ; CHECK-NEXT:   [[PHI:%[0-9]+]]:_(<8 x s16>) = G_PHI [[DEF2]](<8 x s16>), %bb.1, [[DEF]](<8 x s16>), %bb.0
  ; CHECK-NEXT:   %one:_(s64) = G_CONSTANT i64 1
  ; CHECK-NEXT:   %extract:_(s16) = G_EXTRACT_VECTOR_ELT [[PHI]](<8 x s16>), %one(s64)
  ; CHECK-NEXT:   $h0 = COPY %extract(s16)
  ; CHECK-NEXT:   RET_ReallyLR implicit $h0
  bb.0:
    successors: %bb.1(0x50000000), %bb.2(0x30000000)
    liveins: $x0, $x1
    %cond:_(s1) = G_IMPLICIT_DEF
    %val_1:_(<16 x s16>) = G_IMPLICIT_DEF
    G_BRCOND %cond(s1), %bb.2
    G_BR %bb.1
  bb.1:
    %val_2:_(<16 x s16>) = G_IMPLICIT_DEF
  bb.2:
    %phi:_(<16 x s16>) = G_PHI %val_2(<16 x s16>), %bb.1, %val_1(<16 x s16>), %bb.0
    %one:_(s64) = G_CONSTANT i64 1
    %extract:_(s16) = G_EXTRACT_VECTOR_ELT %phi(<16 x s16>), %one(s64)
    $h0 = COPY %extract
    RET_ReallyLR implicit $h0
...
---
name:            v32s8
alignment:       4
tracksRegLiveness: true
body:             |
  ; CHECK-LABEL: name: v32s8
  ; CHECK: bb.0:
  ; CHECK-NEXT:   successors: %bb.1(0x50000000), %bb.2(0x30000000)
  ; CHECK-NEXT:   liveins: $x0, $x1
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[DEF:%[0-9]+]]:_(<16 x s8>) = G_IMPLICIT_DEF
  ; CHECK-NEXT:   [[DEF1:%[0-9]+]]:_(s32) = G_IMPLICIT_DEF
  ; CHECK-NEXT:   [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
  ; CHECK-NEXT:   [[AND:%[0-9]+]]:_(s32) = G_AND [[DEF1]], [[C]]
  ; CHECK-NEXT:   G_BRCOND [[AND]](s32), %bb.2
  ; CHECK-NEXT:   G_BR %bb.1
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.1:
  ; CHECK-NEXT:   successors: %bb.2(0x80000000)
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[DEF2:%[0-9]+]]:_(<16 x s8>) = G_IMPLICIT_DEF
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.2:
  ; CHECK-NEXT:   [[PHI:%[0-9]+]]:_(<16 x s8>) = G_PHI [[DEF2]](<16 x s8>), %bb.1, [[DEF]](<16 x s8>), %bb.0
  ; CHECK-NEXT:   %one:_(s64) = G_CONSTANT i64 1
  ; CHECK-NEXT:   %extract:_(s8) = G_EXTRACT_VECTOR_ELT [[PHI]](<16 x s8>), %one(s64)
  ; CHECK-NEXT:   $b0 = COPY %extract(s8)
  ; CHECK-NEXT:   RET_ReallyLR implicit $b0
  bb.0:
    successors: %bb.1(0x50000000), %bb.2(0x30000000)
    liveins: $x0, $x1
    %cond:_(s1) = G_IMPLICIT_DEF
    %val_1:_(<32 x s8>) = G_IMPLICIT_DEF
    G_BRCOND %cond(s1), %bb.2
    G_BR %bb.1
  bb.1:
    %val_2:_(<32 x s8>) = G_IMPLICIT_DEF
  bb.2:
    %phi:_(<32 x s8>) = G_PHI %val_2(<32 x s8>), %bb.1, %val_1(<32 x s8>), %bb.0
    %one:_(s64) = G_CONSTANT i64 1
    %extract:_(s8) = G_EXTRACT_VECTOR_ELT %phi(<32 x s8>), %one(s64)
    $b0 = COPY %extract
    RET_ReallyLR implicit $b0
...
---
name:            v4p0
alignment:       4
tracksRegLiveness: true
body:             |
  ; CHECK-LABEL: name: v4p0
  ; CHECK: bb.0:
  ; CHECK-NEXT:   successors: %bb.1(0x50000000), %bb.2(0x30000000)
  ; CHECK-NEXT:   liveins: $x0, $x1
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   %ptr1:_(p0) = COPY $x1
  ; CHECK-NEXT:   %ptr2:_(p0) = COPY $x0
  ; CHECK-NEXT:   [[LOAD:%[0-9]+]]:_(<2 x s64>) = G_LOAD %ptr1(p0) :: (load (<2 x s64>), align 32)
  ; CHECK-NEXT:   [[BITCAST:%[0-9]+]]:_(<2 x p0>) = G_BITCAST [[LOAD]](<2 x s64>)
  ; CHECK-NEXT:   [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 16
  ; CHECK-NEXT:   [[PTR_ADD:%[0-9]+]]:_(p0) = G_PTR_ADD %ptr1, [[C]](s64)
  ; CHECK-NEXT:   [[LOAD1:%[0-9]+]]:_(<2 x s64>) = G_LOAD [[PTR_ADD]](p0) :: (load (<2 x s64>) from unknown-address + 16)
  ; CHECK-NEXT:   [[BITCAST1:%[0-9]+]]:_(<2 x p0>) = G_BITCAST [[LOAD1]](<2 x s64>)
  ; CHECK-NEXT:   [[DEF:%[0-9]+]]:_(s32) = G_IMPLICIT_DEF
  ; CHECK-NEXT:   [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
  ; CHECK-NEXT:   [[AND:%[0-9]+]]:_(s32) = G_AND [[DEF]], [[C1]]
  ; CHECK-NEXT:   G_BRCOND [[AND]](s32), %bb.2
  ; CHECK-NEXT:   G_BR %bb.1
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.1:
  ; CHECK-NEXT:   successors: %bb.2(0x80000000)
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[LOAD2:%[0-9]+]]:_(<2 x s64>) = G_LOAD %ptr2(p0) :: (load (<2 x s64>), align 32)
  ; CHECK-NEXT:   [[BITCAST2:%[0-9]+]]:_(<2 x p0>) = G_BITCAST [[LOAD2]](<2 x s64>)
  ; CHECK-NEXT:   [[C2:%[0-9]+]]:_(s64) = G_CONSTANT i64 16
  ; CHECK-NEXT:   [[PTR_ADD1:%[0-9]+]]:_(p0) = G_PTR_ADD %ptr2, [[C2]](s64)
  ; CHECK-NEXT:   [[LOAD3:%[0-9]+]]:_(<2 x s64>) = G_LOAD [[PTR_ADD1]](p0) :: (load (<2 x s64>) from unknown-address + 16)
  ; CHECK-NEXT:   [[BITCAST3:%[0-9]+]]:_(<2 x p0>) = G_BITCAST [[LOAD3]](<2 x s64>)
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.2:
  ; CHECK-NEXT:   [[PHI:%[0-9]+]]:_(<2 x p0>) = G_PHI [[BITCAST2]](<2 x p0>), %bb.1, [[BITCAST]](<2 x p0>), %bb.0
  ; CHECK-NEXT:   [[PHI1:%[0-9]+]]:_(<2 x p0>) = G_PHI [[BITCAST3]](<2 x p0>), %bb.1, [[BITCAST1]](<2 x p0>), %bb.0
  ; CHECK-NEXT:   $q0 = COPY [[PHI]](<2 x p0>)
  ; CHECK-NEXT:   $q1 = COPY [[PHI1]](<2 x p0>)
  ; CHECK-NEXT:   RET_ReallyLR implicit $q0, implicit $q1
  bb.0:
    successors: %bb.1(0x50000000), %bb.2(0x30000000)
    liveins: $x0, $x1

    %ptr1:_(p0) = COPY $x1
    %ptr2:_(p0) = COPY $x0
    %cond:_(s1) = G_IMPLICIT_DEF
    %val_1:_(<4 x p0>) = G_LOAD %ptr1(p0) :: (load (<4 x p0>))
    G_BRCOND %cond(s1), %bb.2
    G_BR %bb.1
  bb.1:
    %val_2:_(<4 x p0>) = G_LOAD %ptr2(p0) :: (load (<4 x p0>))
  bb.2:
    %phi:_(<4 x p0>) = G_PHI %val_2(<4 x p0>), %bb.1, %val_1(<4 x p0>), %bb.0
    %unmerge_1:_(<2 x p0>), %unmerge_2:_(<2 x p0>) = G_UNMERGE_VALUES %phi(<4 x p0>)
    $q0 = COPY %unmerge_1(<2 x p0>)
    $q1 = COPY %unmerge_2(<2 x p0>)
    RET_ReallyLR implicit $q0, implicit $q1