1 ; RUN: llc -mtriple=amdgcn-- -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,SI,SIVI %s
2 ; RUN: llc -mtriple=amdgcn-- -mcpu=tonga -mattr=-flat-for-global -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,VI,GFX89,SIVI %s
3 ; RUN: llc -mtriple=amdgcn-- -mcpu=gfx900 -mattr=-flat-for-global -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,GFX9,GFX89 %s
5 ; GCN-LABEL: {{^}}extract_vector_elt_v2i16:
6 ; GCN: s_load_dword [[VEC:s[0-9]+]]
7 ; SIVI: s_lshr_b32 [[ELT1:s[0-9]+]], [[VEC]], 16
8 ; SIVI-DAG: v_mov_b32_e32 [[VELT0:v[0-9]+]], [[VEC]]
9 ; SIVI-DAG: v_mov_b32_e32 [[VELT1:v[0-9]+]], [[ELT1]]
10 ; SIVI-DAG: buffer_store_short [[VELT0]]
11 ; SIVI-DAG: buffer_store_short [[VELT1]]
12 ; GFX9: v_mov_b32_e32 [[VVEC:v[0-9]+]], [[VEC]]
13 ; GFX9: global_store_short_d16_hi v{{[0-9]+}}, [[VVEC]],
14 ; GFX9: buffer_store_short [[VVEC]],
15 define amdgpu_kernel void @extract_vector_elt_v2i16(ptr addrspace(1) %out, ptr addrspace(4) %vec.ptr) #0 {
16 %vec = load <2 x i16>, ptr addrspace(4) %vec.ptr
17 %p0 = extractelement <2 x i16> %vec, i32 0
18 %p1 = extractelement <2 x i16> %vec, i32 1
19 %out1 = getelementptr i16, ptr addrspace(1) %out, i32 10
20 store i16 %p1, ptr addrspace(1) %out, align 2
21 store i16 %p0, ptr addrspace(1) %out1, align 2
25 ; GCN-LABEL: {{^}}extract_vector_elt_v2i16_dynamic_sgpr:
26 ; GCN: s_load_dword [[IDX:s[0-9]+]]
27 ; GCN: s_load_dword [[VEC:s[0-9]+]]
28 ; GCN: s_lshl_b32 [[IDX_SCALED:s[0-9]+]], [[IDX]], 4
29 ; GCN: s_lshr_b32 [[ELT1:s[0-9]+]], [[VEC]], [[IDX_SCALED]]
30 ; GCN: v_mov_b32_e32 [[VELT1:v[0-9]+]], [[ELT1]]
31 ; GCN: buffer_store_short [[VELT1]]
33 define amdgpu_kernel void @extract_vector_elt_v2i16_dynamic_sgpr(ptr addrspace(1) %out, ptr addrspace(4) %vec.ptr, [8 x i32], i32 %idx) #0 {
34 %vec = load <2 x i16>, ptr addrspace(4) %vec.ptr
35 %elt = extractelement <2 x i16> %vec, i32 %idx
36 store i16 %elt, ptr addrspace(1) %out, align 2
40 ; GCN-LABEL: {{^}}extract_vector_elt_v2i16_dynamic_vgpr:
41 ; GCN-DAG: {{flat|buffer|global}}_load_dword [[IDX:v[0-9]+]]
42 ; GCN-DAG: v_lshlrev_b32_e32 [[IDX_SCALED:v[0-9]+]], 4, [[IDX]]
43 ; GCN-DAG: s_load_dword [[VEC:s[0-9]+]]
45 ; SI: v_lshr_b32_e32 [[ELT:v[0-9]+]], [[VEC]], [[IDX_SCALED]]
46 ; VI: v_lshrrev_b32_e64 [[ELT:v[0-9]+]], [[IDX_SCALED]], [[VEC]]
48 ; SI: buffer_store_short [[ELT]]
49 ; VI: flat_store_short v{{\[[0-9]+:[0-9]+\]}}, [[ELT]]
50 ; GCN: ScratchSize: 0{{$}}
51 define amdgpu_kernel void @extract_vector_elt_v2i16_dynamic_vgpr(ptr addrspace(1) %out, ptr addrspace(4) %vec.ptr, ptr addrspace(1) %idx.ptr) #0 {
52 %tid = call i32 @llvm.amdgcn.workitem.id.x()
53 %tid.ext = sext i32 %tid to i64
54 %gep = getelementptr inbounds i32, ptr addrspace(1) %idx.ptr, i64 %tid.ext
55 %out.gep = getelementptr inbounds i16, ptr addrspace(1) %out, i64 %tid.ext
56 %idx = load volatile i32, ptr addrspace(1) %gep
57 %vec = load <2 x i16>, ptr addrspace(4) %vec.ptr
58 %elt = extractelement <2 x i16> %vec, i32 %idx
59 store i16 %elt, ptr addrspace(1) %out.gep, align 2
63 ; GCN-LABEL: {{^}}extract_vector_elt_v3i16:
66 ; GCN-NOT: {{buffer|flat|global}}_load
68 ; GCN: buffer_store_short
69 ; GCN: buffer_store_short
70 define amdgpu_kernel void @extract_vector_elt_v3i16(ptr addrspace(1) %out, <3 x i16> %foo) #0 {
71 %p0 = extractelement <3 x i16> %foo, i32 0
72 %p1 = extractelement <3 x i16> %foo, i32 2
73 %out1 = getelementptr i16, ptr addrspace(1) %out, i32 1
74 store i16 %p1, ptr addrspace(1) %out, align 2
75 store i16 %p0, ptr addrspace(1) %out1, align 2
79 ; GCN-LABEL: {{^}}extract_vector_elt_v4i16:
81 ; SI: buffer_store_short
82 ; SI: buffer_store_short
84 ; GFX89-DAG: s_load_dwordx4 s[[[#LOAD:]]:[[#END:]]], s[0:1], 0x24
85 ; GFX89-DAG: v_mov_b32_e32 [[VLOAD0:v[0-9]+]], s[[#LOAD + 2]]
86 ; GFX89-DAG: buffer_store_short [[VLOAD0]], off
87 ; GFX89-DAG: v_mov_b32_e32 [[VLOAD1:v[0-9]+]], s[[#LOAD + 3]]
88 ; GFX89-DAG: buffer_store_short [[VLOAD1]], off
89 define amdgpu_kernel void @extract_vector_elt_v4i16(ptr addrspace(1) %out, <4 x i16> %foo) #0 {
90 %p0 = extractelement <4 x i16> %foo, i32 0
91 %p1 = extractelement <4 x i16> %foo, i32 2
92 %out1 = getelementptr i16, ptr addrspace(1) %out, i32 10
93 store volatile i16 %p1, ptr addrspace(1) %out, align 2
94 store volatile i16 %p0, ptr addrspace(1) %out1, align 2
98 ; GCN-LABEL: {{^}}dynamic_extract_vector_elt_v3i16:
100 ; SI: s_load_dwordx2 s
101 ; SI: s_load_dwordx2 s
103 ; GFX89-DAG: s_load_dwordx2 s[[[LOAD0:[0-9]+]]:[[LOAD1:[0-9]+]]], s[0:1], 0x24
104 ; GFX89-DAG: s_load_dwordx2 s[[[LOAD0:[0-9]+]]:[[LOAD1:[0-9]+]]], s[0:1], 0x4c
105 ; GFX89-DAG: s_load_dword s{{[0-9]+}}, s[0:1], 0x54
107 ; GCN-NOT: {{buffer|flat|global}}
109 ; SICI: buffer_store_short
110 ; SICI: buffer_store_short
111 ; SICI: buffer_store_short
113 ; GFX9-NOT: s_pack_ll_b32_b16
114 ; GFX9-NOT: s_pack_lh_b32_b16
116 ; GCN-DAG: s_lshl_b32 s{{[0-9]+}}, s{{[0-9]+}}, 4
117 ; GCN: s_lshr_b64 s{{\[[0-9]+:[0-9]+\]}}, s{{\[[0-9]+:[0-9]+\]}}, s
118 ; GCN: {{buffer|global}}_store_short
119 define amdgpu_kernel void @dynamic_extract_vector_elt_v3i16(ptr addrspace(1) %out, [8 x i32], <3 x i16> %foo, i32 %idx) #0 {
120 %p0 = extractelement <3 x i16> %foo, i32 %idx
121 %out1 = getelementptr i16, ptr addrspace(1) %out, i32 1
122 store i16 %p0, ptr addrspace(1) %out
126 ; GCN-LABEL: {{^}}v_insertelement_v4i16_dynamic_sgpr:
127 define amdgpu_kernel void @v_insertelement_v4i16_dynamic_sgpr(ptr addrspace(1) %out, ptr addrspace(1) %in, i32 %idx) #0 {
128 %tid = call i32 @llvm.amdgcn.workitem.id.x() #1
129 %tid.ext = sext i32 %tid to i64
130 %in.gep = getelementptr inbounds <4 x i16>, ptr addrspace(1) %in, i64 %tid.ext
131 %out.gep = getelementptr inbounds i16, ptr addrspace(1) %out, i64 %tid.ext
132 %vec = load <4 x i16>, ptr addrspace(1) %in.gep
133 %vec.extract = extractelement <4 x i16> %vec, i32 %idx
134 store i16 %vec.extract, ptr addrspace(1) %out.gep
138 ; GCN-LABEL: {{^}}reduce_load_vector_v8i16_extract_01:
139 ; GCN: s_load_dwordx2 [[PTR:s\[[0-9]+:[0-9]+\]]],
140 ; GCN-NOT: {{s|buffer|flat|global}}_load_
141 ; GCN: s_load_dword s{{[0-9]+}}, [[PTR]], 0x0
142 ; GCN-NOT: {{s|buffer|flat|global}}_load_
143 ; GCN: s_lshr_b32 s{{[0-9]+}}, s{{[0-9]+}}, 16
144 define amdgpu_kernel void @reduce_load_vector_v8i16_extract_01(ptr addrspace(4) %ptr) #0 {
145 %load = load <16 x i16>, ptr addrspace(4) %ptr
146 %elt0 = extractelement <16 x i16> %load, i32 0
147 %elt1 = extractelement <16 x i16> %load, i32 1
148 store volatile i16 %elt0, ptr addrspace(1) undef, align 2
149 store volatile i16 %elt1, ptr addrspace(1) undef, align 2
153 ; GCN-LABEL: {{^}}reduce_load_vector_v8i16_extract_23:
154 ; GCN: s_load_dwordx2 [[PTR:s\[[0-9]+:[0-9]+\]]],
155 ; GCN-NOT: {{s|buffer|flat|global}}_load_
156 ; GCN: s_load_dword s{{[0-9]+}}, [[PTR]], {{0x1|0x4}}
157 ; GCN-NOT: {{s|buffer|flat|global}}_load_
158 ; GCN: s_lshr_b32 s{{[0-9]+}}, s{{[0-9]+}}, 16
159 define amdgpu_kernel void @reduce_load_vector_v8i16_extract_23(ptr addrspace(4) %ptr) #0 {
160 %load = load <16 x i16>, ptr addrspace(4) %ptr
161 %elt2 = extractelement <16 x i16> %load, i32 2
162 %elt3 = extractelement <16 x i16> %load, i32 3
163 store volatile i16 %elt2, ptr addrspace(1) undef, align 2
164 store volatile i16 %elt3, ptr addrspace(1) undef, align 2
168 ; GCN-LABEL: {{^}}v_extractelement_v8i16_2:
169 ; SI: buffer_load_dword [[RES:v[0-9]+]], v[{{[0-9:]+}}], s[{{[0-9:]+}}], 0 addr64 offset:4
170 ; SI: buffer_store_short [[RES]]
171 ; VI: flat_load_dword [[RES:v[0-9]+]]
172 ; VI: flat_store_short v[{{[0-9:]+}}], [[RES]]
173 ; GFX9: global_load_dword [[RES:v[0-9]+]], v{{[0-9]+}}, s[{{[0-9:]+}}] offset:4
174 ; GFX9: global_store_short v{{[0-9]+}}, [[RES]]
175 define amdgpu_kernel void @v_extractelement_v8i16_2(ptr addrspace(1) %out, ptr addrspace(1) %in) #0 {
176 %tid = call i32 @llvm.amdgcn.workitem.id.x() #1
177 %tid.ext = sext i32 %tid to i64
178 %in.gep = getelementptr inbounds <8 x i16>, ptr addrspace(1) %in, i64 %tid.ext
179 %out.gep = getelementptr inbounds i16, ptr addrspace(1) %out, i64 %tid.ext
180 %vec = load <8 x i16>, ptr addrspace(1) %in.gep
181 %vec.extract = extractelement <8 x i16> %vec, i32 2
182 store i16 %vec.extract, ptr addrspace(1) %out.gep
186 ; GCN-LABEL: {{^}}v_extractelement_v8i16_6:
187 ; SI: buffer_load_dword [[RES:v[0-9]+]], v[{{[0-9:]+}}], s[{{[0-9:]+}}], 0 addr64 offset:12
188 ; SI: buffer_store_short [[RES]]
189 ; VI: flat_load_dword [[RES:v[0-9]+]]
190 ; VI: flat_store_short v[{{[0-9:]+}}], [[RES]]
191 ; GFX9: global_load_dword [[RES:v[0-9]+]], v{{[0-9]+}}, s[{{[0-9:]+}}] offset:12
192 ; GFX9: global_store_short v{{[0-9]+}}, [[RES]]
193 define amdgpu_kernel void @v_extractelement_v8i16_6(ptr addrspace(1) %out, ptr addrspace(1) %in) #0 {
194 %tid = call i32 @llvm.amdgcn.workitem.id.x() #1
195 %tid.ext = sext i32 %tid to i64
196 %in.gep = getelementptr inbounds <8 x i16>, ptr addrspace(1) %in, i64 %tid.ext
197 %out.gep = getelementptr inbounds i16, ptr addrspace(1) %out, i64 %tid.ext
198 %vec = load <8 x i16>, ptr addrspace(1) %in.gep
199 %vec.extract = extractelement <8 x i16> %vec, i32 6
200 store i16 %vec.extract, ptr addrspace(1) %out.gep
204 ; GCN-LABEL: {{^}}v_extractelement_v8i16_dynamic_sgpr:
205 ; GCN-COUNT-7: v_cndmask_b32_e32
206 define amdgpu_kernel void @v_extractelement_v8i16_dynamic_sgpr(ptr addrspace(1) %out, ptr addrspace(1) %in, i32 %n) #0 {
207 %tid = call i32 @llvm.amdgcn.workitem.id.x() #1
208 %tid.ext = sext i32 %tid to i64
209 %in.gep = getelementptr inbounds <8 x i16>, ptr addrspace(1) %in, i64 %tid.ext
210 %out.gep = getelementptr inbounds i16, ptr addrspace(1) %out, i64 %tid.ext
211 %vec = load <8 x i16>, ptr addrspace(1) %in.gep
212 %vec.extract = extractelement <8 x i16> %vec, i32 %n
213 store i16 %vec.extract, ptr addrspace(1) %out.gep
217 ; GCN-LABEL: {{^}}v_extractelement_v16i16_2:
218 ; SI: buffer_load_dword [[RES:v[0-9]+]], v[{{[0-9:]+}}], s[{{[0-9:]+}}], 0 addr64 offset:4
219 ; SI: buffer_store_short [[RES]]
220 ; VI: flat_load_dword [[RES:v[0-9]+]]
221 ; VI: flat_store_short v[{{[0-9:]+}}], [[RES]]
222 ; GFX9: global_load_dword [[RES:v[0-9]+]], v{{[0-9]+}}, s[{{[0-9:]+}}] offset:4
223 ; GFX9: global_store_short v{{[0-9]+}}, [[RES]]
224 define amdgpu_kernel void @v_extractelement_v16i16_2(ptr addrspace(1) %out, ptr addrspace(1) %in) #0 {
225 %tid = call i32 @llvm.amdgcn.workitem.id.x() #1
226 %tid.ext = sext i32 %tid to i64
227 %in.gep = getelementptr inbounds <16 x i16>, ptr addrspace(1) %in, i64 %tid.ext
228 %out.gep = getelementptr inbounds i16, ptr addrspace(1) %out, i64 %tid.ext
229 %vec = load <16 x i16>, ptr addrspace(1) %in.gep
230 %vec.extract = extractelement <16 x i16> %vec, i32 2
231 store i16 %vec.extract, ptr addrspace(1) %out.gep
235 ; GCN-LABEL: {{^}}v_extractelement_v16i16_6:
236 ; SI: buffer_load_dword [[RES:v[0-9]+]], v[{{[0-9:]+}}], s[{{[0-9:]+}}], 0 addr64 offset:12
237 ; SI: buffer_store_short [[RES]]
238 ; VI: flat_load_dword [[RES:v[0-9]+]]
239 ; VI: flat_store_short v[{{[0-9:]+}}], [[RES]]
240 ; GFX9: global_load_dword [[RES:v[0-9]+]], v{{[0-9]+}}, s[{{[0-9:]+}}] offset:12
241 ; GFX9: global_store_short v{{[0-9]+}}, [[RES]]
242 define amdgpu_kernel void @v_extractelement_v16i16_6(ptr addrspace(1) %out, ptr addrspace(1) %in) #0 {
243 %tid = call i32 @llvm.amdgcn.workitem.id.x() #1
244 %tid.ext = sext i32 %tid to i64
245 %in.gep = getelementptr inbounds <16 x i16>, ptr addrspace(1) %in, i64 %tid.ext
246 %out.gep = getelementptr inbounds i16, ptr addrspace(1) %out, i64 %tid.ext
247 %vec = load <16 x i16>, ptr addrspace(1) %in.gep
248 %vec.extract = extractelement <16 x i16> %vec, i32 6
249 store i16 %vec.extract, ptr addrspace(1) %out.gep
253 ; GCN-LABEL: {{^}}v_extractelement_v16i16_dynamic_sgpr:
254 ; GCN-COUNT-15: v_cndmask_b32_e32
255 define amdgpu_kernel void @v_extractelement_v16i16_dynamic_sgpr(ptr addrspace(1) %out, ptr addrspace(1) %in, i32 %n) #0 {
256 %tid = call i32 @llvm.amdgcn.workitem.id.x() #1
257 %tid.ext = sext i32 %tid to i64
258 %in.gep = getelementptr inbounds <16 x i16>, ptr addrspace(1) %in, i64 %tid.ext
259 %out.gep = getelementptr inbounds i16, ptr addrspace(1) %out, i64 %tid.ext
260 %vec = load <16 x i16>, ptr addrspace(1) %in.gep
261 %vec.extract = extractelement <16 x i16> %vec, i32 %n
262 store i16 %vec.extract, ptr addrspace(1) %out.gep
266 declare i32 @llvm.amdgcn.workitem.id.x() #1
268 attributes #0 = { nounwind }
269 attributes #1 = { nounwind readnone }