1 ; RUN: llc -amdgpu-scalarize-global-loads=false -verify-machineinstrs -march=amdgcn -mcpu=tahiti < %s | FileCheck -enable-var-scope -check-prefixes=GCN,SI %s
2 ; RUN: llc -amdgpu-scalarize-global-loads=false -verify-machineinstrs -march=amdgcn -mcpu=tonga -mattr=-flat-for-global < %s | FileCheck -enable-var-scope -check-prefixes=GCN,VI,GFX89 %s
3 ; RUN: llc -amdgpu-scalarize-global-loads=false -verify-machineinstrs -march=amdgcn -mcpu=gfx900 -mattr=-flat-for-global < %s | FileCheck -enable-var-scope -check-prefixes=GCN,GFX9,GFX89 %s
5 ; Test expansion of scalar selects on vectors.
6 ; Evergreen not enabled since it seems to be having problems with doubles.
8 ; GCN-LABEL: {{^}}v_select_v2i8:
15 ; This is worse when i16 is legal and packed is not because
16 ; SelectionDAGBuilder for some reason changes the select type.
19 define amdgpu_kernel void @v_select_v2i8(ptr addrspace(1) %out, ptr addrspace(1) %a.ptr, ptr addrspace(1) %b.ptr, i32 %c) #0 {
20 %a = load <2 x i8>, ptr addrspace(1) %a.ptr, align 2
21 %b = load <2 x i8>, ptr addrspace(1) %b.ptr, align 2
22 %cmp = icmp eq i32 %c, 0
23 %select = select i1 %cmp, <2 x i8> %a, <2 x i8> %b
24 store <2 x i8> %select, ptr addrspace(1) %out, align 2
28 ; GCN-LABEL: {{^}}v_select_v4i8:
29 ; GCN: v_cndmask_b32_e32
31 define amdgpu_kernel void @v_select_v4i8(ptr addrspace(1) %out, ptr addrspace(1) %a.ptr, ptr addrspace(1) %b.ptr, i32 %c) #0 {
32 %a = load <4 x i8>, ptr addrspace(1) %a.ptr
33 %b = load <4 x i8>, ptr addrspace(1) %b.ptr
34 %cmp = icmp eq i32 %c, 0
35 %select = select i1 %cmp, <4 x i8> %a, <4 x i8> %b
36 store <4 x i8> %select, ptr addrspace(1) %out, align 4
40 ; GCN-LABEL: {{^}}v_select_v8i8:
41 ; GCN: v_cndmask_b32_e32
42 ; GCN: v_cndmask_b32_e32
44 define amdgpu_kernel void @v_select_v8i8(ptr addrspace(1) %out, ptr addrspace(1) %a.ptr, ptr addrspace(1) %b.ptr, i32 %c) #0 {
45 %a = load <8 x i8>, ptr addrspace(1) %a.ptr
46 %b = load <8 x i8>, ptr addrspace(1) %b.ptr
47 %cmp = icmp eq i32 %c, 0
48 %select = select i1 %cmp, <8 x i8> %a, <8 x i8> %b
49 store <8 x i8> %select, ptr addrspace(1) %out, align 4
53 ; GCN-LABEL: {{^}}v_select_v16i8:
54 ; GCN: v_cndmask_b32_e32
55 ; GCN: v_cndmask_b32_e32
56 ; GCN: v_cndmask_b32_e32
57 ; GCN: v_cndmask_b32_e32
59 define amdgpu_kernel void @v_select_v16i8(ptr addrspace(1) %out, ptr addrspace(1) %a.ptr, ptr addrspace(1) %b.ptr, i32 %c) #0 {
60 %a = load <16 x i8>, ptr addrspace(1) %a.ptr
61 %b = load <16 x i8>, ptr addrspace(1) %b.ptr
62 %cmp = icmp eq i32 %c, 0
63 %select = select i1 %cmp, <16 x i8> %a, <16 x i8> %b
64 store <16 x i8> %select, ptr addrspace(1) %out, align 4
68 ; GCN-LABEL: {{^}}select_v4i8:
69 ; GFX89: s_cselect_b32
70 ; GFX89-NOT: s_cselect_b32
74 define amdgpu_kernel void @select_v4i8(ptr addrspace(1) %out, <4 x i8> %a, <4 x i8> %b, i8 %c) #0 {
75 %cmp = icmp eq i8 %c, 0
76 %select = select i1 %cmp, <4 x i8> %a, <4 x i8> %b
77 store <4 x i8> %select, ptr addrspace(1) %out, align 4
81 ; GCN-LABEL: {{^}}select_v2i16:
82 ; GFX89: s_load_dwordx4
83 ; GFX89: s_cselect_b32
84 ; GFX89-NOT: s_cselect_b32
87 ; SI-NOT: v_cndmask_b32e
88 define amdgpu_kernel void @select_v2i16(ptr addrspace(1) %out, <2 x i16> %a, <2 x i16> %b, i32 %c) #0 {
89 %cmp = icmp eq i32 %c, 0
90 %select = select i1 %cmp, <2 x i16> %a, <2 x i16> %b
91 store <2 x i16> %select, ptr addrspace(1) %out, align 4
95 ; GCN-LABEL: {{^}}v_select_v2i16:
96 ; GCN: buffer_load_dword v
97 ; GCN: buffer_load_dword v
100 define amdgpu_kernel void @v_select_v2i16(ptr addrspace(1) %out, ptr addrspace(1) %a.ptr, ptr addrspace(1) %b.ptr, i32 %c) #0 {
101 %a = load <2 x i16>, ptr addrspace(1) %a.ptr
102 %b = load <2 x i16>, ptr addrspace(1) %b.ptr
103 %cmp = icmp eq i32 %c, 0
104 %select = select i1 %cmp, <2 x i16> %a, <2 x i16> %b
105 store <2 x i16> %select, ptr addrspace(1) %out, align 4
109 ; GCN-LABEL: {{^}}v_select_v3i16:
110 ; SI: v_cndmask_b32_e32
118 define amdgpu_kernel void @v_select_v3i16(ptr addrspace(1) %out, ptr addrspace(1) %a.ptr, ptr addrspace(1) %b.ptr, i32 %c) #0 {
119 %a = load <3 x i16>, ptr addrspace(1) %a.ptr
120 %b = load <3 x i16>, ptr addrspace(1) %b.ptr
121 %cmp = icmp eq i32 %c, 0
122 %select = select i1 %cmp, <3 x i16> %a, <3 x i16> %b
123 store <3 x i16> %select, ptr addrspace(1) %out, align 4
127 ; GCN-LABEL: {{^}}v_select_v4i16:
128 ; GCN: v_cndmask_b32_e32
129 ; GCN: v_cndmask_b32_e32
131 define amdgpu_kernel void @v_select_v4i16(ptr addrspace(1) %out, ptr addrspace(1) %a.ptr, ptr addrspace(1) %b.ptr, i32 %c) #0 {
132 %a = load <4 x i16>, ptr addrspace(1) %a.ptr
133 %b = load <4 x i16>, ptr addrspace(1) %b.ptr
134 %cmp = icmp eq i32 %c, 0
135 %select = select i1 %cmp, <4 x i16> %a, <4 x i16> %b
136 store <4 x i16> %select, ptr addrspace(1) %out, align 4
140 ; GCN-LABEL: {{^}}v_select_v8i16:
141 ; GCN: v_cndmask_b32_e32
142 ; GCN: v_cndmask_b32_e32
143 ; GCN: v_cndmask_b32_e32
144 ; GCN: v_cndmask_b32_e32
146 define amdgpu_kernel void @v_select_v8i16(ptr addrspace(1) %out, ptr addrspace(1) %a.ptr, ptr addrspace(1) %b.ptr, i32 %c) #0 {
147 %a = load <8 x i16>, ptr addrspace(1) %a.ptr
148 %b = load <8 x i16>, ptr addrspace(1) %b.ptr
149 %cmp = icmp eq i32 %c, 0
150 %select = select i1 %cmp, <8 x i16> %a, <8 x i16> %b
151 store <8 x i16> %select, ptr addrspace(1) %out, align 4
155 ; FIXME: Expansion with bitwise operations may be better if doing a
156 ; vector select with SGPR inputs.
158 ; GCN-LABEL: {{^}}s_select_v2i32:
161 ; GCN: buffer_store_dwordx2
162 define amdgpu_kernel void @s_select_v2i32(ptr addrspace(1) %out, <2 x i32> %a, <2 x i32> %b, i32 %c) #0 {
163 %cmp = icmp eq i32 %c, 0
164 %select = select i1 %cmp, <2 x i32> %a, <2 x i32> %b
165 store <2 x i32> %select, ptr addrspace(1) %out, align 8
169 ; GCN-LABEL: {{^}}s_select_v4i32:
174 ; GCN: buffer_store_dwordx4
175 define amdgpu_kernel void @s_select_v4i32(ptr addrspace(1) %out, <4 x i32> %a, <4 x i32> %b, i32 %c) #0 {
176 %cmp = icmp eq i32 %c, 0
177 %select = select i1 %cmp, <4 x i32> %a, <4 x i32> %b
178 store <4 x i32> %select, ptr addrspace(1) %out, align 16
182 ; GCN-LABEL: {{^}}v_select_v4i32:
183 ; GCN: buffer_load_dwordx4
184 ; GCN: s_cmp_lt_u32 s{{[0-9]+}}, 32
185 ; GCN: s_cselect_b64 vcc, -1, 0
186 ; GCN: v_cndmask_b32_e32 v{{[0-9]+}}, 0, v{{[0-9]+}}, vcc
187 ; GCN: v_cndmask_b32_e32 v{{[0-9]+}}, 0, v{{[0-9]+}}, vcc
188 ; GCN: v_cndmask_b32_e32 v{{[0-9]+}}, 0, v{{[0-9]+}}, vcc
189 ; GCN: v_cndmask_b32_e32 v{{[0-9]+}}, 0, v{{[0-9]+}}, vcc
190 ; GCN: buffer_store_dwordx4
191 define amdgpu_kernel void @v_select_v4i32(ptr addrspace(1) %out, ptr addrspace(1) %in, i32 %cond) #0 {
193 %tmp2 = icmp ult i32 %cond, 32
194 %val = load <4 x i32>, ptr addrspace(1) %in
195 %tmp3 = select i1 %tmp2, <4 x i32> %val, <4 x i32> zeroinitializer
196 store <4 x i32> %tmp3, ptr addrspace(1) %out, align 16
200 ; GCN-LABEL: {{^}}select_v8i32:
209 define amdgpu_kernel void @select_v8i32(ptr addrspace(1) %out, <8 x i32> %a, <8 x i32> %b, i32 %c) #0 {
210 %cmp = icmp eq i32 %c, 0
211 %select = select i1 %cmp, <8 x i32> %a, <8 x i32> %b
212 store <8 x i32> %select, ptr addrspace(1) %out, align 16
216 ; GCN-LABEL: {{^}}s_select_v2f32:
217 ; GCN-DAG: s_cmp_eq_u32 s{{[0-9]+}}, 0{{$}}
218 ; GCN-DAG: s_cselect_b32
219 ; GCN-DAG: s_cselect_b32
220 ; GCN: buffer_store_dwordx2
221 define amdgpu_kernel void @s_select_v2f32(ptr addrspace(1) %out, <2 x float> %a, <2 x float> %b, i32 %c) #0 {
222 %cmp = icmp eq i32 %c, 0
223 %select = select i1 %cmp, <2 x float> %a, <2 x float> %b
224 store <2 x float> %select, ptr addrspace(1) %out, align 16
228 ; GCN-LABEL: {{^}}s_select_v3f32:
229 ; GCN: s_cmp_eq_u32 s{{[0-9]+}}, 0{{$}}
235 ; GCN: buffer_store_dwordx
236 define amdgpu_kernel void @s_select_v3f32(ptr addrspace(1) %out, <3 x float> %a, <3 x float> %b, i32 %c) #0 {
237 %cmp = icmp eq i32 %c, 0
238 %select = select i1 %cmp, <3 x float> %a, <3 x float> %b
239 store <3 x float> %select, ptr addrspace(1) %out, align 16
243 ; GCN-LABEL: {{^}}s_select_v4f32:
244 ; GCN: s_load_dwordx8
245 ; GCN: s_cmp_eq_u32 s{{[0-9]+}}, 0{{$}}
252 ; GCN: buffer_store_dwordx4
253 define amdgpu_kernel void @s_select_v4f32(ptr addrspace(1) %out, <4 x float> %a, <4 x float> %b, i32 %c) #0 {
254 %cmp = icmp eq i32 %c, 0
255 %select = select i1 %cmp, <4 x float> %a, <4 x float> %b
256 store <4 x float> %select, ptr addrspace(1) %out, align 16
260 ; GCN-LABEL: {{^}}v_select_v4f32:
261 ; GCN: buffer_load_dwordx4
262 ; GCN: s_cmp_lt_u32 s{{[0-9]+}}, 32
263 ; GCN: s_cselect_b64 vcc, -1, 0
264 ; GCN: v_cndmask_b32_e32 v{{[0-9]+}}, 0, v{{[0-9]+}}, vcc
265 ; GCN: v_cndmask_b32_e32 v{{[0-9]+}}, 0, v{{[0-9]+}}, vcc
266 ; GCN: v_cndmask_b32_e32 v{{[0-9]+}}, 0, v{{[0-9]+}}, vcc
267 ; GCN: v_cndmask_b32_e32 v{{[0-9]+}}, 0, v{{[0-9]+}}, vcc
268 ; GCN: buffer_store_dwordx4
269 define amdgpu_kernel void @v_select_v4f32(ptr addrspace(1) %out, ptr addrspace(1) %in, i32 %cond) #0 {
271 %tmp2 = icmp ult i32 %cond, 32
272 %val = load <4 x float>, ptr addrspace(1) %in
273 %tmp3 = select i1 %tmp2, <4 x float> %val, <4 x float> zeroinitializer
274 store <4 x float> %tmp3, ptr addrspace(1) %out, align 16
278 ; GCN-LABEL: {{^}}s_select_v5f32:
279 ; GCN: s_cmp_eq_u32 s{{[0-9]+}}, 0{{$}}
287 ; GCN: buffer_store_dwordx
288 define amdgpu_kernel void @s_select_v5f32(ptr addrspace(1) %out, <5 x float> %a, <5 x float> %b, i32 %c) #0 {
289 %cmp = icmp eq i32 %c, 0
290 %select = select i1 %cmp, <5 x float> %a, <5 x float> %b
291 store <5 x float> %select, ptr addrspace(1) %out, align 16
295 ; GCN-LABEL: {{^}}select_v8f32:
296 ; GCN: v_cndmask_b32_e32
297 ; GCN: v_cndmask_b32_e32
298 ; GCN: v_cndmask_b32_e32
299 ; GCN: v_cndmask_b32_e32
300 ; GCN: v_cndmask_b32_e32
301 ; GCN: v_cndmask_b32_e32
302 ; GCN: v_cndmask_b32_e32
303 ; GCN: v_cndmask_b32_e32
304 define amdgpu_kernel void @select_v8f32(ptr addrspace(1) %out, <8 x float> %a, <8 x float> %b, i32 %c) #0 {
305 %cmp = icmp eq i32 %c, 0
306 %select = select i1 %cmp, <8 x float> %a, <8 x float> %b
307 store <8 x float> %select, ptr addrspace(1) %out, align 16
311 ; GCN-LABEL: {{^}}select_v2f64:
316 define amdgpu_kernel void @select_v2f64(ptr addrspace(1) %out, <2 x double> %a, <2 x double> %b, i32 %c) #0 {
317 %cmp = icmp eq i32 %c, 0
318 %select = select i1 %cmp, <2 x double> %a, <2 x double> %b
319 store <2 x double> %select, ptr addrspace(1) %out, align 16
323 ; GCN-LABEL: {{^}}select_v4f64:
332 define amdgpu_kernel void @select_v4f64(ptr addrspace(1) %out, <4 x double> %a, <4 x double> %b, i32 %c) #0 {
333 %cmp = icmp eq i32 %c, 0
334 %select = select i1 %cmp, <4 x double> %a, <4 x double> %b
335 store <4 x double> %select, ptr addrspace(1) %out, align 16
339 ; GCN-LABEL: {{^}}select_v8f64:
356 define amdgpu_kernel void @select_v8f64(ptr addrspace(1) %out, <8 x double> %a, <8 x double> %b, i32 %c) #0 {
357 %cmp = icmp eq i32 %c, 0
358 %select = select i1 %cmp, <8 x double> %a, <8 x double> %b
359 store <8 x double> %select, ptr addrspace(1) %out, align 16
363 ; GCN-LABEL: {{^}}v_select_v2f16:
366 define amdgpu_kernel void @v_select_v2f16(ptr addrspace(1) %out, ptr addrspace(1) %a.ptr, ptr addrspace(1) %b.ptr, i32 %c) #0 {
367 %a = load <2 x half>, ptr addrspace(1) %a.ptr
368 %b = load <2 x half>, ptr addrspace(1) %b.ptr
369 %cmp = icmp eq i32 %c, 0
370 %select = select i1 %cmp, <2 x half> %a, <2 x half> %b
371 store <2 x half> %select, ptr addrspace(1) %out, align 4
375 ; GCN-LABEL: {{^}}v_select_v3f16:
376 ; GCN: v_cndmask_b32_e32
377 ; GCN: v_cndmask_b32_e32
379 define amdgpu_kernel void @v_select_v3f16(ptr addrspace(1) %out, ptr addrspace(1) %a.ptr, ptr addrspace(1) %b.ptr, i32 %c) #0 {
380 %a = load <3 x half>, ptr addrspace(1) %a.ptr
381 %b = load <3 x half>, ptr addrspace(1) %b.ptr
382 %cmp = icmp eq i32 %c, 0
383 %select = select i1 %cmp, <3 x half> %a, <3 x half> %b
384 store <3 x half> %select, ptr addrspace(1) %out, align 4
388 ; GCN-LABEL: {{^}}v_select_v4f16:
389 ; GCN: v_cndmask_b32_e32
390 ; GCN: v_cndmask_b32_e32
392 define amdgpu_kernel void @v_select_v4f16(ptr addrspace(1) %out, ptr addrspace(1) %a.ptr, ptr addrspace(1) %b.ptr, i32 %c) #0 {
393 %a = load <4 x half>, ptr addrspace(1) %a.ptr
394 %b = load <4 x half>, ptr addrspace(1) %b.ptr
395 %cmp = icmp eq i32 %c, 0
396 %select = select i1 %cmp, <4 x half> %a, <4 x half> %b
397 store <4 x half> %select, ptr addrspace(1) %out, align 4
401 ; Function Attrs: nounwind readnone
402 declare i32 @llvm.amdgcn.workitem.id.x() #1
404 attributes #0 = { nounwind }
405 attributes #1 = { nounwind readnone }