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
4
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
8@external_other = external addrspace(999) global i32, align 4
9
10@internal_constant = internal addrspace(4) constant i32 9, align 4
11@internal_constant32 = internal addrspace(6) constant i32 9, align 4
12@internal_global = internal addrspace(1) global i32 9, align 4
13@internal_other = internal addrspace(999) global i32 9, align 4
14
15
16define i32 addrspace(4)* @external_constant_got() {
17  ; HSA-LABEL: name: external_constant_got
18  ; HSA: bb.1 (%ir-block.0):
19  ; HSA:   liveins: $sgpr30_sgpr31
20  ; HSA:   [[COPY:%[0-9]+]]:sgpr_64 = COPY $sgpr30_sgpr31
21  ; 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
22  ; HSA:   [[LOAD:%[0-9]+]]:_(p4) = G_LOAD [[SI_PC_ADD_REL_OFFSET]](p4) :: (dereferenceable invariant load 8 from got, addrspace 4)
23  ; HSA:   [[UV:%[0-9]+]]:_(s32), [[UV1:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[LOAD]](p4)
24  ; HSA:   $vgpr0 = COPY [[UV]](s32)
25  ; HSA:   $vgpr1 = COPY [[UV1]](s32)
26  ; HSA:   [[COPY1:%[0-9]+]]:ccr_sgpr_64 = COPY [[COPY]]
27  ; HSA:   S_SETPC_B64_return [[COPY1]], implicit $vgpr0, implicit $vgpr1
28  ; PAL-LABEL: name: external_constant_got
29  ; PAL: bb.1 (%ir-block.0):
30  ; PAL:   liveins: $sgpr30_sgpr31
31  ; PAL:   [[COPY:%[0-9]+]]:sgpr_64 = COPY $sgpr30_sgpr31
32  ; PAL:   [[SI_PC_ADD_REL_OFFSET:%[0-9]+]]:sreg_64(p4) = SI_PC_ADD_REL_OFFSET @external_constant + 4, 0, implicit-def $scc
33  ; PAL:   [[UV:%[0-9]+]]:_(s32), [[UV1:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[SI_PC_ADD_REL_OFFSET]](p4)
34  ; PAL:   $vgpr0 = COPY [[UV]](s32)
35  ; PAL:   $vgpr1 = COPY [[UV1]](s32)
36  ; PAL:   [[COPY1:%[0-9]+]]:ccr_sgpr_64 = COPY [[COPY]]
37  ; PAL:   S_SETPC_B64_return [[COPY1]], implicit $vgpr0, implicit $vgpr1
38  ret i32 addrspace(4)* @external_constant
39}
40
41define i32 addrspace(1)* @external_global_got() {
42  ; HSA-LABEL: name: external_global_got
43  ; HSA: bb.1 (%ir-block.0):
44  ; HSA:   liveins: $sgpr30_sgpr31
45  ; HSA:   [[COPY:%[0-9]+]]:sgpr_64 = COPY $sgpr30_sgpr31
46  ; 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
47  ; HSA:   [[LOAD:%[0-9]+]]:_(p1) = G_LOAD [[SI_PC_ADD_REL_OFFSET]](p4) :: (dereferenceable invariant load 8 from got, addrspace 4)
48  ; HSA:   [[UV:%[0-9]+]]:_(s32), [[UV1:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[LOAD]](p1)
49  ; HSA:   $vgpr0 = COPY [[UV]](s32)
50  ; HSA:   $vgpr1 = COPY [[UV1]](s32)
51  ; HSA:   [[COPY1:%[0-9]+]]:ccr_sgpr_64 = COPY [[COPY]]
52  ; HSA:   S_SETPC_B64_return [[COPY1]], implicit $vgpr0, implicit $vgpr1
53  ; PAL-LABEL: name: external_global_got
54  ; PAL: bb.1 (%ir-block.0):
55  ; PAL:   liveins: $sgpr30_sgpr31
56  ; PAL:   [[COPY:%[0-9]+]]:sgpr_64 = COPY $sgpr30_sgpr31
57  ; 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
58  ; PAL:   [[LOAD:%[0-9]+]]:_(p1) = G_LOAD [[SI_PC_ADD_REL_OFFSET]](p4) :: (dereferenceable invariant load 8 from got, addrspace 4)
59  ; PAL:   [[UV:%[0-9]+]]:_(s32), [[UV1:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[LOAD]](p1)
60  ; PAL:   $vgpr0 = COPY [[UV]](s32)
61  ; PAL:   $vgpr1 = COPY [[UV1]](s32)
62  ; PAL:   [[COPY1:%[0-9]+]]:ccr_sgpr_64 = COPY [[COPY]]
63  ; PAL:   S_SETPC_B64_return [[COPY1]], implicit $vgpr0, implicit $vgpr1
64  ret i32 addrspace(1)* @external_global
65}
66
67define i32 addrspace(999)* @external_other_got() {
68  ; HSA-LABEL: name: external_other_got
69  ; HSA: bb.1 (%ir-block.0):
70  ; HSA:   liveins: $sgpr30_sgpr31
71  ; HSA:   [[COPY:%[0-9]+]]:sgpr_64 = COPY $sgpr30_sgpr31
72  ; HSA:   [[SI_PC_ADD_REL_OFFSET:%[0-9]+]]:sreg_64(p4) = SI_PC_ADD_REL_OFFSET target-flags(amdgpu-gotprel32-lo) @external_other + 4, target-flags(amdgpu-gotprel32-hi) @external_other + 4, implicit-def $scc
73  ; HSA:   [[LOAD:%[0-9]+]]:_(p999) = G_LOAD [[SI_PC_ADD_REL_OFFSET]](p4) :: (dereferenceable invariant load 8 from got, addrspace 4)
74  ; HSA:   [[UV:%[0-9]+]]:_(s32), [[UV1:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[LOAD]](p999)
75  ; HSA:   $vgpr0 = COPY [[UV]](s32)
76  ; HSA:   $vgpr1 = COPY [[UV1]](s32)
77  ; HSA:   [[COPY1:%[0-9]+]]:ccr_sgpr_64 = COPY [[COPY]]
78  ; HSA:   S_SETPC_B64_return [[COPY1]], implicit $vgpr0, implicit $vgpr1
79  ; PAL-LABEL: name: external_other_got
80  ; PAL: bb.1 (%ir-block.0):
81  ; PAL:   liveins: $sgpr30_sgpr31
82  ; PAL:   [[COPY:%[0-9]+]]:sgpr_64 = COPY $sgpr30_sgpr31
83  ; PAL:   [[SI_PC_ADD_REL_OFFSET:%[0-9]+]]:sreg_64(p4) = SI_PC_ADD_REL_OFFSET target-flags(amdgpu-gotprel32-lo) @external_other + 4, target-flags(amdgpu-gotprel32-hi) @external_other + 4, implicit-def $scc
84  ; PAL:   [[LOAD:%[0-9]+]]:_(p999) = G_LOAD [[SI_PC_ADD_REL_OFFSET]](p4) :: (dereferenceable invariant load 8 from got, addrspace 4)
85  ; PAL:   [[UV:%[0-9]+]]:_(s32), [[UV1:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[LOAD]](p999)
86  ; PAL:   $vgpr0 = COPY [[UV]](s32)
87  ; PAL:   $vgpr1 = COPY [[UV1]](s32)
88  ; PAL:   [[COPY1:%[0-9]+]]:ccr_sgpr_64 = COPY [[COPY]]
89  ; PAL:   S_SETPC_B64_return [[COPY1]], implicit $vgpr0, implicit $vgpr1
90  ret i32 addrspace(999)* @external_other
91}
92
93define i32 addrspace(4)* @internal_constant_pcrel() {
94  ; HSA-LABEL: name: internal_constant_pcrel
95  ; HSA: bb.1 (%ir-block.0):
96  ; HSA:   liveins: $sgpr30_sgpr31
97  ; HSA:   [[COPY:%[0-9]+]]:sgpr_64 = COPY $sgpr30_sgpr31
98  ; 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
99  ; HSA:   [[UV:%[0-9]+]]:_(s32), [[UV1:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[SI_PC_ADD_REL_OFFSET]](p4)
100  ; HSA:   $vgpr0 = COPY [[UV]](s32)
101  ; HSA:   $vgpr1 = COPY [[UV1]](s32)
102  ; HSA:   [[COPY1:%[0-9]+]]:ccr_sgpr_64 = COPY [[COPY]]
103  ; HSA:   S_SETPC_B64_return [[COPY1]], implicit $vgpr0, implicit $vgpr1
104  ; PAL-LABEL: name: internal_constant_pcrel
105  ; PAL: bb.1 (%ir-block.0):
106  ; PAL:   liveins: $sgpr30_sgpr31
107  ; PAL:   [[COPY:%[0-9]+]]:sgpr_64 = COPY $sgpr30_sgpr31
108  ; PAL:   [[SI_PC_ADD_REL_OFFSET:%[0-9]+]]:sreg_64(p4) = SI_PC_ADD_REL_OFFSET @internal_constant + 4, 0, implicit-def $scc
109  ; PAL:   [[UV:%[0-9]+]]:_(s32), [[UV1:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[SI_PC_ADD_REL_OFFSET]](p4)
110  ; PAL:   $vgpr0 = COPY [[UV]](s32)
111  ; PAL:   $vgpr1 = COPY [[UV1]](s32)
112  ; PAL:   [[COPY1:%[0-9]+]]:ccr_sgpr_64 = COPY [[COPY]]
113  ; PAL:   S_SETPC_B64_return [[COPY1]], implicit $vgpr0, implicit $vgpr1
114  ret i32 addrspace(4)* @internal_constant
115}
116
117define i32 addrspace(1)* @internal_global_pcrel() {
118  ; HSA-LABEL: name: internal_global_pcrel
119  ; HSA: bb.1 (%ir-block.0):
120  ; HSA:   liveins: $sgpr30_sgpr31
121  ; HSA:   [[COPY:%[0-9]+]]:sgpr_64 = COPY $sgpr30_sgpr31
122  ; 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
123  ; HSA:   [[UV:%[0-9]+]]:_(s32), [[UV1:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[SI_PC_ADD_REL_OFFSET]](p1)
124  ; HSA:   $vgpr0 = COPY [[UV]](s32)
125  ; HSA:   $vgpr1 = COPY [[UV1]](s32)
126  ; HSA:   [[COPY1:%[0-9]+]]:ccr_sgpr_64 = COPY [[COPY]]
127  ; HSA:   S_SETPC_B64_return [[COPY1]], implicit $vgpr0, implicit $vgpr1
128  ; PAL-LABEL: name: internal_global_pcrel
129  ; PAL: bb.1 (%ir-block.0):
130  ; PAL:   liveins: $sgpr30_sgpr31
131  ; PAL:   [[COPY:%[0-9]+]]:sgpr_64 = COPY $sgpr30_sgpr31
132  ; 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
133  ; PAL:   [[UV:%[0-9]+]]:_(s32), [[UV1:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[SI_PC_ADD_REL_OFFSET]](p1)
134  ; PAL:   $vgpr0 = COPY [[UV]](s32)
135  ; PAL:   $vgpr1 = COPY [[UV1]](s32)
136  ; PAL:   [[COPY1:%[0-9]+]]:ccr_sgpr_64 = COPY [[COPY]]
137  ; PAL:   S_SETPC_B64_return [[COPY1]], implicit $vgpr0, implicit $vgpr1
138  ret i32 addrspace(1)* @internal_global
139}
140
141define i32 addrspace(999)* @internal_other_pcrel() {
142  ; HSA-LABEL: name: internal_other_pcrel
143  ; HSA: bb.1 (%ir-block.0):
144  ; HSA:   liveins: $sgpr30_sgpr31
145  ; HSA:   [[COPY:%[0-9]+]]:sgpr_64 = COPY $sgpr30_sgpr31
146  ; HSA:   [[SI_PC_ADD_REL_OFFSET:%[0-9]+]]:sreg_64(p999) = SI_PC_ADD_REL_OFFSET target-flags(amdgpu-rel32-lo) @internal_other + 4, target-flags(amdgpu-rel32-hi) @internal_other + 4, implicit-def $scc
147  ; HSA:   [[UV:%[0-9]+]]:_(s32), [[UV1:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[SI_PC_ADD_REL_OFFSET]](p999)
148  ; HSA:   $vgpr0 = COPY [[UV]](s32)
149  ; HSA:   $vgpr1 = COPY [[UV1]](s32)
150  ; HSA:   [[COPY1:%[0-9]+]]:ccr_sgpr_64 = COPY [[COPY]]
151  ; HSA:   S_SETPC_B64_return [[COPY1]], implicit $vgpr0, implicit $vgpr1
152  ; PAL-LABEL: name: internal_other_pcrel
153  ; PAL: bb.1 (%ir-block.0):
154  ; PAL:   liveins: $sgpr30_sgpr31
155  ; PAL:   [[COPY:%[0-9]+]]:sgpr_64 = COPY $sgpr30_sgpr31
156  ; PAL:   [[SI_PC_ADD_REL_OFFSET:%[0-9]+]]:sreg_64(p999) = SI_PC_ADD_REL_OFFSET target-flags(amdgpu-rel32-lo) @internal_other + 4, target-flags(amdgpu-rel32-hi) @internal_other + 4, implicit-def $scc
157  ; PAL:   [[UV:%[0-9]+]]:_(s32), [[UV1:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[SI_PC_ADD_REL_OFFSET]](p999)
158  ; PAL:   $vgpr0 = COPY [[UV]](s32)
159  ; PAL:   $vgpr1 = COPY [[UV1]](s32)
160  ; PAL:   [[COPY1:%[0-9]+]]:ccr_sgpr_64 = COPY [[COPY]]
161  ; PAL:   S_SETPC_B64_return [[COPY1]], implicit $vgpr0, implicit $vgpr1
162  ret i32 addrspace(999)* @internal_other
163}
164
165define i32 addrspace(6)* @external_constant32_got() {
166  ; HSA-LABEL: name: external_constant32_got
167  ; HSA: bb.1 (%ir-block.0):
168  ; HSA:   liveins: $sgpr30_sgpr31
169  ; HSA:   [[COPY:%[0-9]+]]:sgpr_64 = COPY $sgpr30_sgpr31
170  ; 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
171  ; HSA:   [[LOAD:%[0-9]+]]:_(p4) = G_LOAD [[SI_PC_ADD_REL_OFFSET]](p4) :: (dereferenceable invariant load 8 from got, addrspace 4)
172  ; HSA:   [[EXTRACT:%[0-9]+]]:_(p6) = G_EXTRACT [[LOAD]](p4), 0
173  ; HSA:   $vgpr0 = COPY [[EXTRACT]](p6)
174  ; HSA:   [[COPY1:%[0-9]+]]:ccr_sgpr_64 = COPY [[COPY]]
175  ; HSA:   S_SETPC_B64_return [[COPY1]], implicit $vgpr0
176  ; PAL-LABEL: name: external_constant32_got
177  ; PAL: bb.1 (%ir-block.0):
178  ; PAL:   liveins: $sgpr30_sgpr31
179  ; PAL:   [[COPY:%[0-9]+]]:sgpr_64 = COPY $sgpr30_sgpr31
180  ; PAL:   [[SI_PC_ADD_REL_OFFSET:%[0-9]+]]:sreg_64(p4) = SI_PC_ADD_REL_OFFSET @external_constant32 + 4, 0, implicit-def $scc
181  ; PAL:   [[EXTRACT:%[0-9]+]]:_(p6) = G_EXTRACT [[SI_PC_ADD_REL_OFFSET]](p4), 0
182  ; PAL:   $vgpr0 = COPY [[EXTRACT]](p6)
183  ; PAL:   [[COPY1:%[0-9]+]]:ccr_sgpr_64 = COPY [[COPY]]
184  ; PAL:   S_SETPC_B64_return [[COPY1]], implicit $vgpr0
185  ret i32 addrspace(6)* @external_constant32
186}
187
188define i32 addrspace(6)* @internal_constant32_pcrel() {
189  ; HSA-LABEL: name: internal_constant32_pcrel
190  ; HSA: bb.1 (%ir-block.0):
191  ; HSA:   liveins: $sgpr30_sgpr31
192  ; HSA:   [[COPY:%[0-9]+]]:sgpr_64 = COPY $sgpr30_sgpr31
193  ; 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
194  ; HSA:   [[EXTRACT:%[0-9]+]]:_(p6) = G_EXTRACT [[SI_PC_ADD_REL_OFFSET]](p4), 0
195  ; HSA:   $vgpr0 = COPY [[EXTRACT]](p6)
196  ; HSA:   [[COPY1:%[0-9]+]]:ccr_sgpr_64 = COPY [[COPY]]
197  ; HSA:   S_SETPC_B64_return [[COPY1]], implicit $vgpr0
198  ; PAL-LABEL: name: internal_constant32_pcrel
199  ; PAL: bb.1 (%ir-block.0):
200  ; PAL:   liveins: $sgpr30_sgpr31
201  ; PAL:   [[COPY:%[0-9]+]]:sgpr_64 = COPY $sgpr30_sgpr31
202  ; PAL:   [[SI_PC_ADD_REL_OFFSET:%[0-9]+]]:sreg_64(p4) = SI_PC_ADD_REL_OFFSET @internal_constant32 + 4, 0, implicit-def $scc
203  ; PAL:   [[EXTRACT:%[0-9]+]]:_(p6) = G_EXTRACT [[SI_PC_ADD_REL_OFFSET]](p4), 0
204  ; PAL:   $vgpr0 = COPY [[EXTRACT]](p6)
205  ; PAL:   [[COPY1:%[0-9]+]]:ccr_sgpr_64 = COPY [[COPY]]
206  ; PAL:   S_SETPC_B64_return [[COPY1]], implicit $vgpr0
207  ret i32 addrspace(6)* @internal_constant32
208}
209