1 ; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2 ; RUN: llc -global-isel -mtriple=amdgcn-amd-amdhsa -mcpu=hawaii -stop-after=legalizer < %s | FileCheck -check-prefix=HSA %s
3 ; RUN: llc -global-isel -mtriple=amdgcn-amd-amdpal -mcpu=hawaii -stop-after=legalizer < %s | FileCheck -check-prefix=PAL %s
5 @external_constant = external addrspace(4) constant i32, align 4
6 @external_constant32 = external addrspace(6) constant i32, align 4
7 @external_global = external addrspace(1) global i32, align 4
9 @internal_constant = internal addrspace(4) constant i32 9, align 4
10 @internal_constant32 = internal addrspace(6) constant i32 9, align 4
11 @internal_global = internal addrspace(1) global i32 9, align 4
14 define i32 addrspace(4)* @external_constant_got() {
15 ; HSA-LABEL: name: external_constant_got
16 ; HSA: bb.1 (%ir-block.0):
17 ; HSA: liveins: $sgpr30_sgpr31
18 ; HSA: [[COPY:%[0-9]+]]:sgpr_64 = COPY $sgpr30_sgpr31
19 ; HSA: [[SI_PC_ADD_REL_OFFSET:%[0-9]+]]:sreg_64(p4) = SI_PC_ADD_REL_OFFSET target-flags(amdgpu-gotprel32-lo) @external_constant + 4, target-flags(amdgpu-gotprel32-hi) @external_constant + 4, implicit-def $scc
20 ; HSA: [[LOAD:%[0-9]+]]:_(p4) = G_LOAD [[SI_PC_ADD_REL_OFFSET]](p4) :: (dereferenceable invariant load 8 from got, addrspace 4)
21 ; HSA: [[UV:%[0-9]+]]:_(s32), [[UV1:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[LOAD]](p4)
22 ; HSA: $vgpr0 = COPY [[UV]](s32)
23 ; HSA: $vgpr1 = COPY [[UV1]](s32)
24 ; HSA: [[COPY1:%[0-9]+]]:ccr_sgpr_64 = COPY [[COPY]]
25 ; HSA: S_SETPC_B64_return [[COPY1]], implicit $vgpr0, implicit $vgpr1
26 ; PAL-LABEL: name: external_constant_got
27 ; PAL: bb.1 (%ir-block.0):
28 ; PAL: liveins: $sgpr30_sgpr31
29 ; PAL: [[COPY:%[0-9]+]]:sgpr_64 = COPY $sgpr30_sgpr31
30 ; PAL: [[SI_PC_ADD_REL_OFFSET:%[0-9]+]]:sreg_64(p4) = SI_PC_ADD_REL_OFFSET @external_constant + 4, 0, implicit-def $scc
31 ; PAL: [[UV:%[0-9]+]]:_(s32), [[UV1:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[SI_PC_ADD_REL_OFFSET]](p4)
32 ; PAL: $vgpr0 = COPY [[UV]](s32)
33 ; PAL: $vgpr1 = COPY [[UV1]](s32)
34 ; PAL: [[COPY1:%[0-9]+]]:ccr_sgpr_64 = COPY [[COPY]]
35 ; PAL: S_SETPC_B64_return [[COPY1]], implicit $vgpr0, implicit $vgpr1
36 ret i32 addrspace(4)* @external_constant
39 define i32 addrspace(1)* @external_global_got() {
40 ; HSA-LABEL: name: external_global_got
41 ; HSA: bb.1 (%ir-block.0):
42 ; HSA: liveins: $sgpr30_sgpr31
43 ; HSA: [[COPY:%[0-9]+]]:sgpr_64 = COPY $sgpr30_sgpr31
44 ; HSA: [[SI_PC_ADD_REL_OFFSET:%[0-9]+]]:sreg_64(p4) = SI_PC_ADD_REL_OFFSET target-flags(amdgpu-gotprel32-lo) @external_global + 4, target-flags(amdgpu-gotprel32-hi) @external_global + 4, implicit-def $scc
45 ; HSA: [[LOAD:%[0-9]+]]:_(p1) = G_LOAD [[SI_PC_ADD_REL_OFFSET]](p4) :: (dereferenceable invariant load 8 from got, addrspace 4)
46 ; HSA: [[UV:%[0-9]+]]:_(s32), [[UV1:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[LOAD]](p1)
47 ; HSA: $vgpr0 = COPY [[UV]](s32)
48 ; HSA: $vgpr1 = COPY [[UV1]](s32)
49 ; HSA: [[COPY1:%[0-9]+]]:ccr_sgpr_64 = COPY [[COPY]]
50 ; HSA: S_SETPC_B64_return [[COPY1]], implicit $vgpr0, implicit $vgpr1
51 ; PAL-LABEL: name: external_global_got
52 ; PAL: bb.1 (%ir-block.0):
53 ; PAL: liveins: $sgpr30_sgpr31
54 ; PAL: [[COPY:%[0-9]+]]:sgpr_64 = COPY $sgpr30_sgpr31
55 ; PAL: [[SI_PC_ADD_REL_OFFSET:%[0-9]+]]:sreg_64(p4) = SI_PC_ADD_REL_OFFSET target-flags(amdgpu-gotprel32-lo) @external_global + 4, target-flags(amdgpu-gotprel32-hi) @external_global + 4, implicit-def $scc
56 ; PAL: [[LOAD:%[0-9]+]]:_(p1) = G_LOAD [[SI_PC_ADD_REL_OFFSET]](p4) :: (dereferenceable invariant load 8 from got, addrspace 4)
57 ; PAL: [[UV:%[0-9]+]]:_(s32), [[UV1:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[LOAD]](p1)
58 ; PAL: $vgpr0 = COPY [[UV]](s32)
59 ; PAL: $vgpr1 = COPY [[UV1]](s32)
60 ; PAL: [[COPY1:%[0-9]+]]:ccr_sgpr_64 = COPY [[COPY]]
61 ; PAL: S_SETPC_B64_return [[COPY1]], implicit $vgpr0, implicit $vgpr1
62 ret i32 addrspace(1)* @external_global
65 define i32 addrspace(4)* @internal_constant_pcrel() {
66 ; HSA-LABEL: name: internal_constant_pcrel
67 ; HSA: bb.1 (%ir-block.0):
68 ; HSA: liveins: $sgpr30_sgpr31
69 ; HSA: [[COPY:%[0-9]+]]:sgpr_64 = COPY $sgpr30_sgpr31
70 ; HSA: [[SI_PC_ADD_REL_OFFSET:%[0-9]+]]:sreg_64(p4) = SI_PC_ADD_REL_OFFSET target-flags(amdgpu-rel32-lo) @internal_constant + 4, target-flags(amdgpu-rel32-hi) @internal_constant + 4, implicit-def $scc
71 ; HSA: [[UV:%[0-9]+]]:_(s32), [[UV1:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[SI_PC_ADD_REL_OFFSET]](p4)
72 ; HSA: $vgpr0 = COPY [[UV]](s32)
73 ; HSA: $vgpr1 = COPY [[UV1]](s32)
74 ; HSA: [[COPY1:%[0-9]+]]:ccr_sgpr_64 = COPY [[COPY]]
75 ; HSA: S_SETPC_B64_return [[COPY1]], implicit $vgpr0, implicit $vgpr1
76 ; PAL-LABEL: name: internal_constant_pcrel
77 ; PAL: bb.1 (%ir-block.0):
78 ; PAL: liveins: $sgpr30_sgpr31
79 ; PAL: [[COPY:%[0-9]+]]:sgpr_64 = COPY $sgpr30_sgpr31
80 ; PAL: [[SI_PC_ADD_REL_OFFSET:%[0-9]+]]:sreg_64(p4) = SI_PC_ADD_REL_OFFSET @internal_constant + 4, 0, implicit-def $scc
81 ; PAL: [[UV:%[0-9]+]]:_(s32), [[UV1:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[SI_PC_ADD_REL_OFFSET]](p4)
82 ; PAL: $vgpr0 = COPY [[UV]](s32)
83 ; PAL: $vgpr1 = COPY [[UV1]](s32)
84 ; PAL: [[COPY1:%[0-9]+]]:ccr_sgpr_64 = COPY [[COPY]]
85 ; PAL: S_SETPC_B64_return [[COPY1]], implicit $vgpr0, implicit $vgpr1
86 ret i32 addrspace(4)* @internal_constant
89 define i32 addrspace(1)* @internal_global_pcrel() {
90 ; HSA-LABEL: name: internal_global_pcrel
91 ; HSA: bb.1 (%ir-block.0):
92 ; HSA: liveins: $sgpr30_sgpr31
93 ; HSA: [[COPY:%[0-9]+]]:sgpr_64 = COPY $sgpr30_sgpr31
94 ; HSA: [[SI_PC_ADD_REL_OFFSET:%[0-9]+]]:sreg_64(p1) = SI_PC_ADD_REL_OFFSET target-flags(amdgpu-rel32-lo) @internal_global + 4, target-flags(amdgpu-rel32-hi) @internal_global + 4, implicit-def $scc
95 ; HSA: [[UV:%[0-9]+]]:_(s32), [[UV1:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[SI_PC_ADD_REL_OFFSET]](p1)
96 ; HSA: $vgpr0 = COPY [[UV]](s32)
97 ; HSA: $vgpr1 = COPY [[UV1]](s32)
98 ; HSA: [[COPY1:%[0-9]+]]:ccr_sgpr_64 = COPY [[COPY]]
99 ; HSA: S_SETPC_B64_return [[COPY1]], implicit $vgpr0, implicit $vgpr1
100 ; PAL-LABEL: name: internal_global_pcrel
101 ; PAL: bb.1 (%ir-block.0):
102 ; PAL: liveins: $sgpr30_sgpr31
103 ; PAL: [[COPY:%[0-9]+]]:sgpr_64 = COPY $sgpr30_sgpr31
104 ; PAL: [[SI_PC_ADD_REL_OFFSET:%[0-9]+]]:sreg_64(p1) = SI_PC_ADD_REL_OFFSET target-flags(amdgpu-rel32-lo) @internal_global + 4, target-flags(amdgpu-rel32-hi) @internal_global + 4, implicit-def $scc
105 ; PAL: [[UV:%[0-9]+]]:_(s32), [[UV1:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[SI_PC_ADD_REL_OFFSET]](p1)
106 ; PAL: $vgpr0 = COPY [[UV]](s32)
107 ; PAL: $vgpr1 = COPY [[UV1]](s32)
108 ; PAL: [[COPY1:%[0-9]+]]:ccr_sgpr_64 = COPY [[COPY]]
109 ; PAL: S_SETPC_B64_return [[COPY1]], implicit $vgpr0, implicit $vgpr1
110 ret i32 addrspace(1)* @internal_global
113 define i32 addrspace(6)* @external_constant32_got() {
114 ; HSA-LABEL: name: external_constant32_got
115 ; HSA: bb.1 (%ir-block.0):
116 ; HSA: liveins: $sgpr30_sgpr31
117 ; HSA: [[COPY:%[0-9]+]]:sgpr_64 = COPY $sgpr30_sgpr31
118 ; HSA: [[SI_PC_ADD_REL_OFFSET:%[0-9]+]]:sreg_64(p4) = SI_PC_ADD_REL_OFFSET target-flags(amdgpu-gotprel32-lo) @external_constant32 + 4, target-flags(amdgpu-gotprel32-hi) @external_constant32 + 4, implicit-def $scc
119 ; HSA: [[LOAD:%[0-9]+]]:_(p4) = G_LOAD [[SI_PC_ADD_REL_OFFSET]](p4) :: (dereferenceable invariant load 8 from got, addrspace 4)
120 ; HSA: [[EXTRACT:%[0-9]+]]:_(p6) = G_EXTRACT [[LOAD]](p4), 0
121 ; HSA: $vgpr0 = COPY [[EXTRACT]](p6)
122 ; HSA: [[COPY1:%[0-9]+]]:ccr_sgpr_64 = COPY [[COPY]]
123 ; HSA: S_SETPC_B64_return [[COPY1]], implicit $vgpr0
124 ; PAL-LABEL: name: external_constant32_got
125 ; PAL: bb.1 (%ir-block.0):
126 ; PAL: liveins: $sgpr30_sgpr31
127 ; PAL: [[COPY:%[0-9]+]]:sgpr_64 = COPY $sgpr30_sgpr31
128 ; PAL: [[SI_PC_ADD_REL_OFFSET:%[0-9]+]]:sreg_64(p4) = SI_PC_ADD_REL_OFFSET @external_constant32 + 4, 0, implicit-def $scc
129 ; PAL: [[EXTRACT:%[0-9]+]]:_(p6) = G_EXTRACT [[SI_PC_ADD_REL_OFFSET]](p4), 0
130 ; PAL: $vgpr0 = COPY [[EXTRACT]](p6)
131 ; PAL: [[COPY1:%[0-9]+]]:ccr_sgpr_64 = COPY [[COPY]]
132 ; PAL: S_SETPC_B64_return [[COPY1]], implicit $vgpr0
133 ret i32 addrspace(6)* @external_constant32
136 define i32 addrspace(6)* @internal_constant32_pcrel() {
137 ; HSA-LABEL: name: internal_constant32_pcrel
138 ; HSA: bb.1 (%ir-block.0):
139 ; HSA: liveins: $sgpr30_sgpr31
140 ; HSA: [[COPY:%[0-9]+]]:sgpr_64 = COPY $sgpr30_sgpr31
141 ; HSA: [[SI_PC_ADD_REL_OFFSET:%[0-9]+]]:sreg_64(p4) = SI_PC_ADD_REL_OFFSET target-flags(amdgpu-rel32-lo) @internal_constant32 + 4, target-flags(amdgpu-rel32-hi) @internal_constant32 + 4, implicit-def $scc
142 ; HSA: [[EXTRACT:%[0-9]+]]:_(p6) = G_EXTRACT [[SI_PC_ADD_REL_OFFSET]](p4), 0
143 ; HSA: $vgpr0 = COPY [[EXTRACT]](p6)
144 ; HSA: [[COPY1:%[0-9]+]]:ccr_sgpr_64 = COPY [[COPY]]
145 ; HSA: S_SETPC_B64_return [[COPY1]], implicit $vgpr0
146 ; PAL-LABEL: name: internal_constant32_pcrel
147 ; PAL: bb.1 (%ir-block.0):
148 ; PAL: liveins: $sgpr30_sgpr31
149 ; PAL: [[COPY:%[0-9]+]]:sgpr_64 = COPY $sgpr30_sgpr31
150 ; PAL: [[SI_PC_ADD_REL_OFFSET:%[0-9]+]]:sreg_64(p4) = SI_PC_ADD_REL_OFFSET @internal_constant32 + 4, 0, implicit-def $scc
151 ; PAL: [[EXTRACT:%[0-9]+]]:_(p6) = G_EXTRACT [[SI_PC_ADD_REL_OFFSET]](p4), 0
152 ; PAL: $vgpr0 = COPY [[EXTRACT]](p6)
153 ; PAL: [[COPY1:%[0-9]+]]:ccr_sgpr_64 = COPY [[COPY]]
154 ; PAL: S_SETPC_B64_return [[COPY1]], implicit $vgpr0
155 ret i32 addrspace(6)* @internal_constant32