llvm/llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-addrspacecast.mir

# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
# RUN: llc -mtriple=amdgcn -mcpu=fiji -O0 -run-pass=legalizer --amdhsa-code-object-version=4 -o - %s  | FileCheck -check-prefixes=GCN,SIVI %s
# RUN: llc -mtriple=amdgcn -mcpu=tahiti -O0 -run-pass=legalizer --amdhsa-code-object-version=4 -o - %s  | FileCheck -check-prefixes=GCN,SIVI %s
# RUN: llc -mtriple=amdgcn -mcpu=gfx900 -O0 -run-pass=legalizer --amdhsa-code-object-version=4 -o - %s  | FileCheck -check-prefixes=GCN,GFX9 %s
# RUN: llc -mtriple=amdgcn -mcpu=gfx1010 -O0 -run-pass=legalizer --amdhsa-code-object-version=4 -o - %s  | FileCheck -check-prefixes=GCN,GFX9 %s
# RUN: llc -mtriple=amdgcn -mcpu=gfx1100 -O0 -run-pass=legalizer --amdhsa-code-object-version=4 -o - %s  | FileCheck -check-prefixes=GCN,GFX9 %s

---
name: test_addrspacecast_p0_to_p1
machineFunctionInfo:
  argumentInfo:
    queuePtr: { reg: '$sgpr4_sgpr5' }

body: |
  bb.0:
    liveins: $vgpr0_vgpr1

    ; GCN-LABEL: name: test_addrspacecast_p0_to_p1
    ; GCN: liveins: $vgpr0_vgpr1
    ; GCN-NEXT: {{  $}}
    ; GCN-NEXT: [[COPY:%[0-9]+]]:_(p0) = COPY $vgpr0_vgpr1
    ; GCN-NEXT: [[BITCAST:%[0-9]+]]:_(p1) = G_BITCAST [[COPY]](p0)
    ; GCN-NEXT: $vgpr0_vgpr1 = COPY [[BITCAST]](p1)
    %0:_(p0) = COPY $vgpr0_vgpr1
    %1:_(p1) = G_ADDRSPACE_CAST %0
    $vgpr0_vgpr1 = COPY %1
...

---
name: test_addrspacecast_p1_to_p0
machineFunctionInfo:
  argumentInfo:
    queuePtr: { reg: '$sgpr4_sgpr5' }

body: |
  bb.0:
    liveins: $vgpr0_vgpr1

    ; GCN-LABEL: name: test_addrspacecast_p1_to_p0
    ; GCN: liveins: $vgpr0_vgpr1
    ; GCN-NEXT: {{  $}}
    ; GCN-NEXT: [[COPY:%[0-9]+]]:_(p1) = COPY $vgpr0_vgpr1
    ; GCN-NEXT: [[BITCAST:%[0-9]+]]:_(p0) = G_BITCAST [[COPY]](p1)
    ; GCN-NEXT: $vgpr0_vgpr1 = COPY [[BITCAST]](p0)
    %0:_(p1) = COPY $vgpr0_vgpr1
    %1:_(p0) = G_ADDRSPACE_CAST %0
    $vgpr0_vgpr1 = COPY %1
...

---
name: test_addrspacecast_p0_to_p4
machineFunctionInfo:
  argumentInfo:
    queuePtr: { reg: '$sgpr4_sgpr5' }
body: |
  bb.0:
    liveins: $vgpr0_vgpr1

    ; GCN-LABEL: name: test_addrspacecast_p0_to_p4
    ; GCN: liveins: $vgpr0_vgpr1
    ; GCN-NEXT: {{  $}}
    ; GCN-NEXT: [[COPY:%[0-9]+]]:_(p0) = COPY $vgpr0_vgpr1
    ; GCN-NEXT: [[BITCAST:%[0-9]+]]:_(p4) = G_BITCAST [[COPY]](p0)
    ; GCN-NEXT: $vgpr0_vgpr1 = COPY [[BITCAST]](p4)
    %0:_(p0) = COPY $vgpr0_vgpr1
    %1:_(p4) = G_ADDRSPACE_CAST %0
    $vgpr0_vgpr1 = COPY %1
...

---
name: test_addrspacecast_p4_to_p0
machineFunctionInfo:
  argumentInfo:
    queuePtr: { reg: '$sgpr4_sgpr5' }
body: |
  bb.0:
    liveins: $vgpr0_vgpr1

    ; GCN-LABEL: name: test_addrspacecast_p4_to_p0
    ; GCN: liveins: $vgpr0_vgpr1
    ; GCN-NEXT: {{  $}}
    ; GCN-NEXT: [[COPY:%[0-9]+]]:_(p4) = COPY $vgpr0_vgpr1
    ; GCN-NEXT: [[BITCAST:%[0-9]+]]:_(p0) = G_BITCAST [[COPY]](p4)
    ; GCN-NEXT: $vgpr0_vgpr1 = COPY [[BITCAST]](p0)
    %0:_(p4) = COPY $vgpr0_vgpr1
    %1:_(p0) = G_ADDRSPACE_CAST %0
    $vgpr0_vgpr1 = COPY %1
...

---
name: test_addrspacecast_p0_to_p999
machineFunctionInfo:
  argumentInfo:
    queuePtr: { reg: '$sgpr4_sgpr5' }
body: |
  bb.0:
    liveins: $vgpr0_vgpr1

    ; GCN-LABEL: name: test_addrspacecast_p0_to_p999
    ; GCN: liveins: $vgpr0_vgpr1
    ; GCN-NEXT: {{  $}}
    ; GCN-NEXT: [[COPY:%[0-9]+]]:_(p0) = COPY $vgpr0_vgpr1
    ; GCN-NEXT: [[BITCAST:%[0-9]+]]:_(p999) = G_BITCAST [[COPY]](p0)
    ; GCN-NEXT: $vgpr0_vgpr1 = COPY [[BITCAST]](p999)
    %0:_(p0) = COPY $vgpr0_vgpr1
    %1:_(p999) = G_ADDRSPACE_CAST %0
    $vgpr0_vgpr1 = COPY %1
...

---
name: test_addrspacecast_p999_to_p0
machineFunctionInfo:
  argumentInfo:
    queuePtr: { reg: '$sgpr4_sgpr5' }
body: |
  bb.0:
    liveins: $vgpr0_vgpr1

    ; GCN-LABEL: name: test_addrspacecast_p999_to_p0
    ; GCN: liveins: $vgpr0_vgpr1
    ; GCN-NEXT: {{  $}}
    ; GCN-NEXT: [[COPY:%[0-9]+]]:_(p999) = COPY $vgpr0_vgpr1
    ; GCN-NEXT: [[BITCAST:%[0-9]+]]:_(p0) = G_BITCAST [[COPY]](p999)
    ; GCN-NEXT: $vgpr0_vgpr1 = COPY [[BITCAST]](p0)
    %0:_(p999) = COPY $vgpr0_vgpr1
    %1:_(p0) = G_ADDRSPACE_CAST %0
    $vgpr0_vgpr1 = COPY %1
...

---
name: test_addrspacecast_p5_to_p0
machineFunctionInfo:
  argumentInfo:
    queuePtr: { reg: '$sgpr4_sgpr5' }
body: |
  bb.0:
    liveins: $vgpr0

    ; SIVI-LABEL: name: test_addrspacecast_p5_to_p0
    ; SIVI: liveins: $vgpr0, $sgpr4_sgpr5
    ; SIVI-NEXT: {{  $}}
    ; SIVI-NEXT: [[COPY:%[0-9]+]]:sgpr_64(p4) = COPY $sgpr4_sgpr5
    ; SIVI-NEXT: [[COPY1:%[0-9]+]]:_(p5) = COPY $vgpr0
    ; SIVI-NEXT: [[COPY2:%[0-9]+]]:_(p4) = COPY [[COPY]](p4)
    ; SIVI-NEXT: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 68
    ; SIVI-NEXT: [[PTR_ADD:%[0-9]+]]:_(p4) = G_PTR_ADD [[COPY2]], [[C]](s64)
    ; SIVI-NEXT: [[LOAD:%[0-9]+]]:_(s32) = G_LOAD [[PTR_ADD]](p4) :: (dereferenceable invariant load (s32), addrspace 4)
    ; SIVI-NEXT: [[PTRTOINT:%[0-9]+]]:_(s32) = G_PTRTOINT [[COPY1]](p5)
    ; SIVI-NEXT: [[MV:%[0-9]+]]:_(p0) = G_MERGE_VALUES [[PTRTOINT]](s32), [[LOAD]](s32)
    ; SIVI-NEXT: [[C1:%[0-9]+]]:_(p5) = G_CONSTANT i32 -1
    ; SIVI-NEXT: [[C2:%[0-9]+]]:_(p0) = G_CONSTANT i64 0
    ; SIVI-NEXT: [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(ne), [[COPY1]](p5), [[C1]]
    ; SIVI-NEXT: [[SELECT:%[0-9]+]]:_(p0) = G_SELECT [[ICMP]](s1), [[MV]], [[C2]]
    ; SIVI-NEXT: $vgpr0_vgpr1 = COPY [[SELECT]](p0)
    ; GFX9-LABEL: name: test_addrspacecast_p5_to_p0
    ; GFX9: liveins: $vgpr0
    ; GFX9-NEXT: {{  $}}
    ; GFX9-NEXT: [[COPY:%[0-9]+]]:_(p5) = COPY $vgpr0
    ; GFX9-NEXT: [[S_MOV_B64_:%[0-9]+]]:sreg_64(s64) = S_MOV_B64 $src_private_base
    ; GFX9-NEXT: [[UV:%[0-9]+]]:_(s32), [[UV1:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[S_MOV_B64_]](s64)
    ; GFX9-NEXT: [[PTRTOINT:%[0-9]+]]:_(s32) = G_PTRTOINT [[COPY]](p5)
    ; GFX9-NEXT: [[MV:%[0-9]+]]:_(p0) = G_MERGE_VALUES [[PTRTOINT]](s32), [[UV1]](s32)
    ; GFX9-NEXT: [[C:%[0-9]+]]:_(p5) = G_CONSTANT i32 -1
    ; GFX9-NEXT: [[C1:%[0-9]+]]:_(p0) = G_CONSTANT i64 0
    ; GFX9-NEXT: [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(ne), [[COPY]](p5), [[C]]
    ; GFX9-NEXT: [[SELECT:%[0-9]+]]:_(p0) = G_SELECT [[ICMP]](s1), [[MV]], [[C1]]
    ; GFX9-NEXT: $vgpr0_vgpr1 = COPY [[SELECT]](p0)
    %0:_(p5) = COPY $vgpr0
    %1:_(p0) = G_ADDRSPACE_CAST %0
    $vgpr0_vgpr1 = COPY %1
...

---
name: test_addrspacecast_p0_to_p5
machineFunctionInfo:
  argumentInfo:
    queuePtr: { reg: '$sgpr4_sgpr5' }
body: |
  bb.0:
    liveins: $vgpr0_vgpr1

    ; GCN-LABEL: name: test_addrspacecast_p0_to_p5
    ; GCN: liveins: $vgpr0_vgpr1
    ; GCN-NEXT: {{  $}}
    ; GCN-NEXT: [[COPY:%[0-9]+]]:_(p0) = COPY $vgpr0_vgpr1
    ; GCN-NEXT: [[C:%[0-9]+]]:_(p5) = G_CONSTANT i32 -1
    ; GCN-NEXT: [[C1:%[0-9]+]]:_(p0) = G_CONSTANT i64 0
    ; GCN-NEXT: [[EXTRACT:%[0-9]+]]:_(p5) = G_EXTRACT [[COPY]](p0), 0
    ; GCN-NEXT: [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(ne), [[COPY]](p0), [[C1]]
    ; GCN-NEXT: [[SELECT:%[0-9]+]]:_(p5) = G_SELECT [[ICMP]](s1), [[EXTRACT]], [[C]]
    ; GCN-NEXT: $vgpr0 = COPY [[SELECT]](p5)
    %0:_(p0) = COPY $vgpr0_vgpr1
    %1:_(p5) = G_ADDRSPACE_CAST %0
    $vgpr0 = COPY %1
...

---
name: test_addrspacecast_p3_to_p0
machineFunctionInfo:
  argumentInfo:
    queuePtr: { reg: '$sgpr4_sgpr5' }

body: |
  bb.0:
    liveins: $vgpr0

    ; SIVI-LABEL: name: test_addrspacecast_p3_to_p0
    ; SIVI: liveins: $vgpr0, $sgpr4_sgpr5
    ; SIVI-NEXT: {{  $}}
    ; SIVI-NEXT: [[COPY:%[0-9]+]]:sgpr_64(p4) = COPY $sgpr4_sgpr5
    ; SIVI-NEXT: [[COPY1:%[0-9]+]]:_(p3) = COPY $vgpr0
    ; SIVI-NEXT: [[COPY2:%[0-9]+]]:_(p4) = COPY [[COPY]](p4)
    ; SIVI-NEXT: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 64
    ; SIVI-NEXT: [[PTR_ADD:%[0-9]+]]:_(p4) = G_PTR_ADD [[COPY2]], [[C]](s64)
    ; SIVI-NEXT: [[LOAD:%[0-9]+]]:_(s32) = G_LOAD [[PTR_ADD]](p4) :: (dereferenceable invariant load (s32), align 64, addrspace 4)
    ; SIVI-NEXT: [[PTRTOINT:%[0-9]+]]:_(s32) = G_PTRTOINT [[COPY1]](p3)
    ; SIVI-NEXT: [[MV:%[0-9]+]]:_(p0) = G_MERGE_VALUES [[PTRTOINT]](s32), [[LOAD]](s32)
    ; SIVI-NEXT: [[C1:%[0-9]+]]:_(p3) = G_CONSTANT i32 -1
    ; SIVI-NEXT: [[C2:%[0-9]+]]:_(p0) = G_CONSTANT i64 0
    ; SIVI-NEXT: [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(ne), [[COPY1]](p3), [[C1]]
    ; SIVI-NEXT: [[SELECT:%[0-9]+]]:_(p0) = G_SELECT [[ICMP]](s1), [[MV]], [[C2]]
    ; SIVI-NEXT: $vgpr0_vgpr1 = COPY [[SELECT]](p0)
    ; GFX9-LABEL: name: test_addrspacecast_p3_to_p0
    ; GFX9: liveins: $vgpr0
    ; GFX9-NEXT: {{  $}}
    ; GFX9-NEXT: [[COPY:%[0-9]+]]:_(p3) = COPY $vgpr0
    ; GFX9-NEXT: [[S_MOV_B64_:%[0-9]+]]:sreg_64(s64) = S_MOV_B64 $src_shared_base
    ; GFX9-NEXT: [[UV:%[0-9]+]]:_(s32), [[UV1:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[S_MOV_B64_]](s64)
    ; GFX9-NEXT: [[PTRTOINT:%[0-9]+]]:_(s32) = G_PTRTOINT [[COPY]](p3)
    ; GFX9-NEXT: [[MV:%[0-9]+]]:_(p0) = G_MERGE_VALUES [[PTRTOINT]](s32), [[UV1]](s32)
    ; GFX9-NEXT: [[C:%[0-9]+]]:_(p3) = G_CONSTANT i32 -1
    ; GFX9-NEXT: [[C1:%[0-9]+]]:_(p0) = G_CONSTANT i64 0
    ; GFX9-NEXT: [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(ne), [[COPY]](p3), [[C]]
    ; GFX9-NEXT: [[SELECT:%[0-9]+]]:_(p0) = G_SELECT [[ICMP]](s1), [[MV]], [[C1]]
    ; GFX9-NEXT: $vgpr0_vgpr1 = COPY [[SELECT]](p0)
    %0:_(p3) = COPY $vgpr0
    %1:_(p0) = G_ADDRSPACE_CAST %0
    $vgpr0_vgpr1 = COPY %1
...

---
name: test_addrspacecast_p0_to_p3
machineFunctionInfo:
  argumentInfo:
    queuePtr: { reg: '$sgpr4_sgpr5' }
body: |
  bb.0:
    liveins: $vgpr0_vgpr1

    ; GCN-LABEL: name: test_addrspacecast_p0_to_p3
    ; GCN: liveins: $vgpr0_vgpr1
    ; GCN-NEXT: {{  $}}
    ; GCN-NEXT: [[COPY:%[0-9]+]]:_(p0) = COPY $vgpr0_vgpr1
    ; GCN-NEXT: [[C:%[0-9]+]]:_(p3) = G_CONSTANT i32 -1
    ; GCN-NEXT: [[C1:%[0-9]+]]:_(p0) = G_CONSTANT i64 0
    ; GCN-NEXT: [[EXTRACT:%[0-9]+]]:_(p3) = G_EXTRACT [[COPY]](p0), 0
    ; GCN-NEXT: [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(ne), [[COPY]](p0), [[C1]]
    ; GCN-NEXT: [[SELECT:%[0-9]+]]:_(p3) = G_SELECT [[ICMP]](s1), [[EXTRACT]], [[C]]
    ; GCN-NEXT: $vgpr0 = COPY [[SELECT]](p3)
    %0:_(p0) = COPY $vgpr0_vgpr1
    %1:_(p3) = G_ADDRSPACE_CAST %0
    $vgpr0 = COPY %1
...

---
name: test_addrspacecast_v2p0_to_v2p1
machineFunctionInfo:
  argumentInfo:
    queuePtr: { reg: '$sgpr4_sgpr5' }
body: |
  bb.0:
    liveins: $vgpr0_vgpr1_vgpr2_vgpr3

    ; GCN-LABEL: name: test_addrspacecast_v2p0_to_v2p1
    ; GCN: liveins: $vgpr0_vgpr1_vgpr2_vgpr3
    ; GCN-NEXT: {{  $}}
    ; GCN-NEXT: [[COPY:%[0-9]+]]:_(<2 x p0>) = COPY $vgpr0_vgpr1_vgpr2_vgpr3
    ; GCN-NEXT: [[UV:%[0-9]+]]:_(p0), [[UV1:%[0-9]+]]:_(p0) = G_UNMERGE_VALUES [[COPY]](<2 x p0>)
    ; GCN-NEXT: [[BITCAST:%[0-9]+]]:_(p1) = G_BITCAST [[UV]](p0)
    ; GCN-NEXT: [[BITCAST1:%[0-9]+]]:_(p1) = G_BITCAST [[UV1]](p0)
    ; GCN-NEXT: [[BUILD_VECTOR:%[0-9]+]]:_(<2 x p1>) = G_BUILD_VECTOR [[BITCAST]](p1), [[BITCAST1]](p1)
    ; GCN-NEXT: $vgpr0_vgpr1_vgpr2_vgpr3 = COPY [[BUILD_VECTOR]](<2 x p1>)
    %0:_(<2 x p0>) = COPY $vgpr0_vgpr1_vgpr2_vgpr3
    %1:_(<2 x p1>) = G_ADDRSPACE_CAST %0
    $vgpr0_vgpr1_vgpr2_vgpr3 = COPY %1
...

---
name: test_addrspacecast_v2p1_to_v2p0
machineFunctionInfo:
  argumentInfo:
    queuePtr: { reg: '$sgpr4_sgpr5' }
body: |
  bb.0:
    liveins: $vgpr0_vgpr1_vgpr2_vgpr3

    ; GCN-LABEL: name: test_addrspacecast_v2p1_to_v2p0
    ; GCN: liveins: $vgpr0_vgpr1_vgpr2_vgpr3
    ; GCN-NEXT: {{  $}}
    ; GCN-NEXT: [[COPY:%[0-9]+]]:_(<2 x p1>) = COPY $vgpr0_vgpr1_vgpr2_vgpr3
    ; GCN-NEXT: [[UV:%[0-9]+]]:_(p1), [[UV1:%[0-9]+]]:_(p1) = G_UNMERGE_VALUES [[COPY]](<2 x p1>)
    ; GCN-NEXT: [[BITCAST:%[0-9]+]]:_(p0) = G_BITCAST [[UV]](p1)
    ; GCN-NEXT: [[BITCAST1:%[0-9]+]]:_(p0) = G_BITCAST [[UV1]](p1)
    ; GCN-NEXT: [[BUILD_VECTOR:%[0-9]+]]:_(<2 x p0>) = G_BUILD_VECTOR [[BITCAST]](p0), [[BITCAST1]](p0)
    ; GCN-NEXT: $vgpr0_vgpr1_vgpr2_vgpr3 = COPY [[BUILD_VECTOR]](<2 x p0>)
    %0:_(<2 x p1>) = COPY $vgpr0_vgpr1_vgpr2_vgpr3
    %1:_(<2 x p0>) = G_ADDRSPACE_CAST %0
    $vgpr0_vgpr1_vgpr2_vgpr3 = COPY %1
...

---
name: test_addrspacecast_v2p0_to_v2p3
machineFunctionInfo:
  argumentInfo:
    queuePtr: { reg: '$sgpr4_sgpr5' }
body: |
  bb.0:
    liveins: $vgpr0_vgpr1_vgpr2_vgpr3

    ; GCN-LABEL: name: test_addrspacecast_v2p0_to_v2p3
    ; GCN: liveins: $vgpr0_vgpr1_vgpr2_vgpr3
    ; GCN-NEXT: {{  $}}
    ; GCN-NEXT: [[COPY:%[0-9]+]]:_(<2 x p0>) = COPY $vgpr0_vgpr1_vgpr2_vgpr3
    ; GCN-NEXT: [[UV:%[0-9]+]]:_(p0), [[UV1:%[0-9]+]]:_(p0) = G_UNMERGE_VALUES [[COPY]](<2 x p0>)
    ; GCN-NEXT: [[C:%[0-9]+]]:_(p3) = G_CONSTANT i32 -1
    ; GCN-NEXT: [[C1:%[0-9]+]]:_(p0) = G_CONSTANT i64 0
    ; GCN-NEXT: [[EXTRACT:%[0-9]+]]:_(p3) = G_EXTRACT [[UV]](p0), 0
    ; GCN-NEXT: [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(ne), [[UV]](p0), [[C1]]
    ; GCN-NEXT: [[SELECT:%[0-9]+]]:_(p3) = G_SELECT [[ICMP]](s1), [[EXTRACT]], [[C]]
    ; GCN-NEXT: [[EXTRACT1:%[0-9]+]]:_(p3) = G_EXTRACT [[UV1]](p0), 0
    ; GCN-NEXT: [[ICMP1:%[0-9]+]]:_(s1) = G_ICMP intpred(ne), [[UV1]](p0), [[C1]]
    ; GCN-NEXT: [[SELECT1:%[0-9]+]]:_(p3) = G_SELECT [[ICMP1]](s1), [[EXTRACT1]], [[C]]
    ; GCN-NEXT: [[BUILD_VECTOR:%[0-9]+]]:_(<2 x p3>) = G_BUILD_VECTOR [[SELECT]](p3), [[SELECT1]](p3)
    ; GCN-NEXT: $vgpr0_vgpr1 = COPY [[BUILD_VECTOR]](<2 x p3>)
    %0:_(<2 x p0>) = COPY $vgpr0_vgpr1_vgpr2_vgpr3
    %1:_(<2 x p3>) = G_ADDRSPACE_CAST %0
    $vgpr0_vgpr1 = COPY %1
...

---
name: test_addrspacecast_v2p3_to_v2p0
machineFunctionInfo:
  argumentInfo:
    queuePtr: { reg: '$sgpr4_sgpr5' }
body: |
  bb.0:
    liveins: $vgpr0_vgpr1

    ; SIVI-LABEL: name: test_addrspacecast_v2p3_to_v2p0
    ; SIVI: liveins: $vgpr0_vgpr1, $sgpr4_sgpr5
    ; SIVI-NEXT: {{  $}}
    ; SIVI-NEXT: [[COPY:%[0-9]+]]:sgpr_64(p4) = COPY $sgpr4_sgpr5
    ; SIVI-NEXT: [[COPY1:%[0-9]+]]:_(<2 x p3>) = COPY $vgpr0_vgpr1
    ; SIVI-NEXT: [[UV:%[0-9]+]]:_(p3), [[UV1:%[0-9]+]]:_(p3) = G_UNMERGE_VALUES [[COPY1]](<2 x p3>)
    ; SIVI-NEXT: [[COPY2:%[0-9]+]]:_(p4) = COPY [[COPY]](p4)
    ; SIVI-NEXT: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 64
    ; SIVI-NEXT: [[PTR_ADD:%[0-9]+]]:_(p4) = G_PTR_ADD [[COPY2]], [[C]](s64)
    ; SIVI-NEXT: [[LOAD:%[0-9]+]]:_(s32) = G_LOAD [[PTR_ADD]](p4) :: (dereferenceable invariant load (s32), align 64, addrspace 4)
    ; SIVI-NEXT: [[PTRTOINT:%[0-9]+]]:_(s32) = G_PTRTOINT [[UV]](p3)
    ; SIVI-NEXT: [[MV:%[0-9]+]]:_(p0) = G_MERGE_VALUES [[PTRTOINT]](s32), [[LOAD]](s32)
    ; SIVI-NEXT: [[C1:%[0-9]+]]:_(p3) = G_CONSTANT i32 -1
    ; SIVI-NEXT: [[C2:%[0-9]+]]:_(p0) = G_CONSTANT i64 0
    ; SIVI-NEXT: [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(ne), [[UV]](p3), [[C1]]
    ; SIVI-NEXT: [[SELECT:%[0-9]+]]:_(p0) = G_SELECT [[ICMP]](s1), [[MV]], [[C2]]
    ; SIVI-NEXT: [[COPY3:%[0-9]+]]:_(p4) = COPY [[COPY]](p4)
    ; SIVI-NEXT: [[PTR_ADD1:%[0-9]+]]:_(p4) = G_PTR_ADD [[COPY3]], [[C]](s64)
    ; SIVI-NEXT: [[LOAD1:%[0-9]+]]:_(s32) = G_LOAD [[PTR_ADD1]](p4) :: (dereferenceable invariant load (s32), align 64, addrspace 4)
    ; SIVI-NEXT: [[PTRTOINT1:%[0-9]+]]:_(s32) = G_PTRTOINT [[UV1]](p3)
    ; SIVI-NEXT: [[MV1:%[0-9]+]]:_(p0) = G_MERGE_VALUES [[PTRTOINT1]](s32), [[LOAD1]](s32)
    ; SIVI-NEXT: [[ICMP1:%[0-9]+]]:_(s1) = G_ICMP intpred(ne), [[UV1]](p3), [[C1]]
    ; SIVI-NEXT: [[SELECT1:%[0-9]+]]:_(p0) = G_SELECT [[ICMP1]](s1), [[MV1]], [[C2]]
    ; SIVI-NEXT: [[BUILD_VECTOR:%[0-9]+]]:_(<2 x p0>) = G_BUILD_VECTOR [[SELECT]](p0), [[SELECT1]](p0)
    ; SIVI-NEXT: $vgpr0_vgpr1_vgpr2_vgpr3 = COPY [[BUILD_VECTOR]](<2 x p0>)
    ; GFX9-LABEL: name: test_addrspacecast_v2p3_to_v2p0
    ; GFX9: liveins: $vgpr0_vgpr1
    ; GFX9-NEXT: {{  $}}
    ; GFX9-NEXT: [[COPY:%[0-9]+]]:_(<2 x p3>) = COPY $vgpr0_vgpr1
    ; GFX9-NEXT: [[UV:%[0-9]+]]:_(p3), [[UV1:%[0-9]+]]:_(p3) = G_UNMERGE_VALUES [[COPY]](<2 x p3>)
    ; GFX9-NEXT: [[S_MOV_B64_:%[0-9]+]]:sreg_64(s64) = S_MOV_B64 $src_shared_base
    ; GFX9-NEXT: [[UV2:%[0-9]+]]:_(s32), [[UV3:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[S_MOV_B64_]](s64)
    ; GFX9-NEXT: [[PTRTOINT:%[0-9]+]]:_(s32) = G_PTRTOINT [[UV]](p3)
    ; GFX9-NEXT: [[MV:%[0-9]+]]:_(p0) = G_MERGE_VALUES [[PTRTOINT]](s32), [[UV3]](s32)
    ; GFX9-NEXT: [[C:%[0-9]+]]:_(p3) = G_CONSTANT i32 -1
    ; GFX9-NEXT: [[C1:%[0-9]+]]:_(p0) = G_CONSTANT i64 0
    ; GFX9-NEXT: [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(ne), [[UV]](p3), [[C]]
    ; GFX9-NEXT: [[SELECT:%[0-9]+]]:_(p0) = G_SELECT [[ICMP]](s1), [[MV]], [[C1]]
    ; GFX9-NEXT: [[S_MOV_B64_1:%[0-9]+]]:sreg_64(s64) = S_MOV_B64 $src_shared_base
    ; GFX9-NEXT: [[UV4:%[0-9]+]]:_(s32), [[UV5:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[S_MOV_B64_1]](s64)
    ; GFX9-NEXT: [[PTRTOINT1:%[0-9]+]]:_(s32) = G_PTRTOINT [[UV1]](p3)
    ; GFX9-NEXT: [[MV1:%[0-9]+]]:_(p0) = G_MERGE_VALUES [[PTRTOINT1]](s32), [[UV5]](s32)
    ; GFX9-NEXT: [[ICMP1:%[0-9]+]]:_(s1) = G_ICMP intpred(ne), [[UV1]](p3), [[C]]
    ; GFX9-NEXT: [[SELECT1:%[0-9]+]]:_(p0) = G_SELECT [[ICMP1]](s1), [[MV1]], [[C1]]
    ; GFX9-NEXT: [[BUILD_VECTOR:%[0-9]+]]:_(<2 x p0>) = G_BUILD_VECTOR [[SELECT]](p0), [[SELECT1]](p0)
    ; GFX9-NEXT: $vgpr0_vgpr1_vgpr2_vgpr3 = COPY [[BUILD_VECTOR]](<2 x p0>)
    %0:_(<2 x p3>) = COPY $vgpr0_vgpr1
    %1:_(<2 x p0>) = G_ADDRSPACE_CAST %0
    $vgpr0_vgpr1_vgpr2_vgpr3 = COPY %1
...

---
name: test_addrspacecast_p4_to_p6
body: |
  bb.0:
    liveins: $vgpr0_vgpr1

    ; GCN-LABEL: name: test_addrspacecast_p4_to_p6
    ; GCN: liveins: $vgpr0_vgpr1
    ; GCN-NEXT: {{  $}}
    ; GCN-NEXT: [[COPY:%[0-9]+]]:_(p4) = COPY $vgpr0_vgpr1
    ; GCN-NEXT: [[EXTRACT:%[0-9]+]]:_(p6) = G_EXTRACT [[COPY]](p4), 0
    ; GCN-NEXT: $vgpr0 = COPY [[EXTRACT]](p6)
    %0:_(p4) = COPY $vgpr0_vgpr1
    %1:_(p6) = G_ADDRSPACE_CAST %0
    $vgpr0 = COPY %1
...

---
name: test_addrspacecast_p6_to_p4_0
body: |
  bb.0:
    liveins: $vgpr0

    ; GCN-LABEL: name: test_addrspacecast_p6_to_p4_0
    ; GCN: liveins: $vgpr0
    ; GCN-NEXT: {{  $}}
    ; GCN-NEXT: [[COPY:%[0-9]+]]:_(p6) = COPY $vgpr0
    ; GCN-NEXT: [[PTRTOINT:%[0-9]+]]:_(s32) = G_PTRTOINT [[COPY]](p6)
    ; GCN-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
    ; GCN-NEXT: [[MV:%[0-9]+]]:_(p4) = G_MERGE_VALUES [[PTRTOINT]](s32), [[C]](s32)
    ; GCN-NEXT: $vgpr0_vgpr1 = COPY [[MV]](p4)
    %0:_(p6) = COPY $vgpr0
    %1:_(p4) = G_ADDRSPACE_CAST %0
    $vgpr0_vgpr1 = COPY %1
...

---
name: test_addrspacecast_p6_to_p4_0xdeadbeef
machineFunctionInfo:
  highBitsOf32BitAddress: 0xdeadbeef
body: |
  bb.0:
    liveins: $vgpr0

    ; GCN-LABEL: name: test_addrspacecast_p6_to_p4_0xdeadbeef
    ; GCN: liveins: $vgpr0
    ; GCN-NEXT: {{  $}}
    ; GCN-NEXT: [[COPY:%[0-9]+]]:_(p6) = COPY $vgpr0
    ; GCN-NEXT: [[PTRTOINT:%[0-9]+]]:_(s32) = G_PTRTOINT [[COPY]](p6)
    ; GCN-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 -559038737
    ; GCN-NEXT: [[MV:%[0-9]+]]:_(p4) = G_MERGE_VALUES [[PTRTOINT]](s32), [[C]](s32)
    ; GCN-NEXT: $vgpr0_vgpr1 = COPY [[MV]](p4)
    %0:_(p6) = COPY $vgpr0
    %1:_(p4) = G_ADDRSPACE_CAST %0
    $vgpr0_vgpr1 = COPY %1
...

---
name: test_addrspacecast_p0_to_p6
body: |
  bb.0:
    liveins: $vgpr0_vgpr1

    ; GCN-LABEL: name: test_addrspacecast_p0_to_p6
    ; GCN: liveins: $vgpr0_vgpr1
    ; GCN-NEXT: {{  $}}
    ; GCN-NEXT: [[COPY:%[0-9]+]]:_(p0) = COPY $vgpr0_vgpr1
    ; GCN-NEXT: [[EXTRACT:%[0-9]+]]:_(p6) = G_EXTRACT [[COPY]](p0), 0
    ; GCN-NEXT: $vgpr0 = COPY [[EXTRACT]](p6)
    %0:_(p0) = COPY $vgpr0_vgpr1
    %1:_(p6) = G_ADDRSPACE_CAST %0
    $vgpr0 = COPY %1
...

---
name: test_addrspacecast_p6_to_p0
body: |
  bb.0:
    liveins: $vgpr0

    ; GCN-LABEL: name: test_addrspacecast_p6_to_p0
    ; GCN: liveins: $vgpr0
    ; GCN-NEXT: {{  $}}
    ; GCN-NEXT: [[COPY:%[0-9]+]]:_(p6) = COPY $vgpr0
    ; GCN-NEXT: [[PTRTOINT:%[0-9]+]]:_(s32) = G_PTRTOINT [[COPY]](p6)
    ; GCN-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
    ; GCN-NEXT: [[MV:%[0-9]+]]:_(p0) = G_MERGE_VALUES [[PTRTOINT]](s32), [[C]](s32)
    ; GCN-NEXT: $vgpr0_vgpr1 = COPY [[MV]](p0)
    %0:_(p6) = COPY $vgpr0
    %1:_(p0) = G_ADDRSPACE_CAST %0
    $vgpr0_vgpr1 = COPY %1
...
---
name: test_addrspacecast_p5_fi_to_p0
machineFunctionInfo:
  argumentInfo:
    queuePtr: { reg: '$sgpr4_sgpr5' }
stack:
  - { id: 0, size: 4, alignment: 4 }
body: |
  bb.0:
    ; SIVI-LABEL: name: test_addrspacecast_p5_fi_to_p0
    ; SIVI: liveins: $sgpr4_sgpr5
    ; SIVI-NEXT: {{  $}}
    ; SIVI-NEXT: [[COPY:%[0-9]+]]:sgpr_64(p4) = COPY $sgpr4_sgpr5
    ; SIVI-NEXT: [[FRAME_INDEX:%[0-9]+]]:_(p5) = G_FRAME_INDEX %stack.0
    ; SIVI-NEXT: [[COPY1:%[0-9]+]]:_(p4) = COPY [[COPY]](p4)
    ; SIVI-NEXT: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 68
    ; SIVI-NEXT: [[PTR_ADD:%[0-9]+]]:_(p4) = G_PTR_ADD [[COPY1]], [[C]](s64)
    ; SIVI-NEXT: [[LOAD:%[0-9]+]]:_(s32) = G_LOAD [[PTR_ADD]](p4) :: (dereferenceable invariant load (s32), addrspace 4)
    ; SIVI-NEXT: [[PTRTOINT:%[0-9]+]]:_(s32) = G_PTRTOINT [[FRAME_INDEX]](p5)
    ; SIVI-NEXT: [[MV:%[0-9]+]]:_(p0) = G_MERGE_VALUES [[PTRTOINT]](s32), [[LOAD]](s32)
    ; SIVI-NEXT: $vgpr0_vgpr1 = COPY [[MV]](p0)
    ; GFX9-LABEL: name: test_addrspacecast_p5_fi_to_p0
    ; GFX9: [[FRAME_INDEX:%[0-9]+]]:_(p5) = G_FRAME_INDEX %stack.0
    ; GFX9-NEXT: [[S_MOV_B64_:%[0-9]+]]:sreg_64(s64) = S_MOV_B64 $src_private_base
    ; GFX9-NEXT: [[UV:%[0-9]+]]:_(s32), [[UV1:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[S_MOV_B64_]](s64)
    ; GFX9-NEXT: [[PTRTOINT:%[0-9]+]]:_(s32) = G_PTRTOINT [[FRAME_INDEX]](p5)
    ; GFX9-NEXT: [[MV:%[0-9]+]]:_(p0) = G_MERGE_VALUES [[PTRTOINT]](s32), [[UV1]](s32)
    ; GFX9-NEXT: $vgpr0_vgpr1 = COPY [[MV]](p0)
    %0:_(p5) = G_FRAME_INDEX %stack.0
    %1:_(p0) = G_ADDRSPACE_CAST %0
    $vgpr0_vgpr1 = COPY %1
...