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(<2 x i8> addrspace(1)* %out, <2 x i8> addrspace(1)* %a.ptr, <2 x i8> addrspace(1)* %b.ptr, i32 %c) #0 {
20 %a = load <2 x i8>, <2 x i8> addrspace(1)* %a.ptr, align 2
21 %b = load <2 x i8>, <2 x i8> 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, <2 x i8> 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(<4 x i8> addrspace(1)* %out, <4 x i8> addrspace(1)* %a.ptr, <4 x i8> addrspace(1)* %b.ptr, i32 %c) #0 {
32 %a = load <4 x i8>, <4 x i8> addrspace(1)* %a.ptr
33 %b = load <4 x i8>, <4 x i8> 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, <4 x i8> 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(<8 x i8> addrspace(1)* %out, <8 x i8> addrspace(1)* %a.ptr, <8 x i8> addrspace(1)* %b.ptr, i32 %c) #0 {
45 %a = load <8 x i8>, <8 x i8> addrspace(1)* %a.ptr
46 %b = load <8 x i8>, <8 x i8> 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, <8 x i8> 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(<16 x i8> addrspace(1)* %out, <16 x i8> addrspace(1)* %a.ptr, <16 x i8> addrspace(1)* %b.ptr, i32 %c) #0 {
60 %a = load <16 x i8>, <16 x i8> addrspace(1)* %a.ptr
61 %b = load <16 x i8>, <16 x i8> 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, <16 x i8> 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(<4 x i8> 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, <4 x i8> 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
86 ; SI: v_cndmask_b32_e32
87 ; SI-NOT: v_cndmask_b32e
88 define amdgpu_kernel void @select_v2i16(<2 x i16> 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, <2 x i16> 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(<2 x i16> addrspace(1)* %out, <2 x i16> addrspace(1)* %a.ptr, <2 x i16> addrspace(1)* %b.ptr, i32 %c) #0 {
101 %a = load <2 x i16>, <2 x i16> addrspace(1)* %a.ptr
102 %b = load <2 x i16>, <2 x i16> 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, <2 x i16> addrspace(1)* %out, align 4
109 ; GCN-LABEL: {{^}}v_select_v3i16:
110 ; SI: v_cndmask_b32_e32
114 ; GFX89: v_cndmask_b32_e32
118 define amdgpu_kernel void @v_select_v3i16(<3 x i16> addrspace(1)* %out, <3 x i16> addrspace(1)* %a.ptr, <3 x i16> addrspace(1)* %b.ptr, i32 %c) #0 {
119 %a = load <3 x i16>, <3 x i16> addrspace(1)* %a.ptr
120 %b = load <3 x i16>, <3 x i16> 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, <3 x i16> 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(<4 x i16> addrspace(1)* %out, <4 x i16> addrspace(1)* %a.ptr, <4 x i16> addrspace(1)* %b.ptr, i32 %c) #0 {
132 %a = load <4 x i16>, <4 x i16> addrspace(1)* %a.ptr
133 %b = load <4 x i16>, <4 x i16> 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, <4 x i16> 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(<8 x i16> addrspace(1)* %out, <8 x i16> addrspace(1)* %a.ptr, <8 x i16> addrspace(1)* %b.ptr, i32 %c) #0 {
147 %a = load <8 x i16>, <8 x i16> addrspace(1)* %a.ptr
148 %b = load <8 x i16>, <8 x i16> 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, <8 x i16> 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:
159 ; GCN: v_cndmask_b32_e32
160 ; GCN: v_cndmask_b32_e32
161 ; GCN: buffer_store_dwordx2
162 define amdgpu_kernel void @s_select_v2i32(<2 x i32> 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, <2 x i32> addrspace(1)* %out, align 8
169 ; GCN-LABEL: {{^}}s_select_v4i32:
170 ; GCN: v_cndmask_b32_e32
171 ; GCN: v_cndmask_b32_e32
172 ; GCN: v_cndmask_b32_e32
173 ; GCN: v_cndmask_b32_e32
174 ; GCN: buffer_store_dwordx4
175 define amdgpu_kernel void @s_select_v4i32(<4 x i32> 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, <4 x i32> 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(<4 x i32> addrspace(1)* %out, <4 x i32> addrspace(1)* %in, i32 %cond) #0 {
193 %tmp2 = icmp ult i32 %cond, 32
194 %val = load <4 x i32>, <4 x i32> addrspace(1)* %in
195 %tmp3 = select i1 %tmp2, <4 x i32> %val, <4 x i32> zeroinitializer
196 store <4 x i32> %tmp3, <4 x i32> addrspace(1)* %out, align 16
200 ; GCN-LABEL: {{^}}select_v8i32:
201 ; GCN: v_cndmask_b32_e32
202 ; GCN: v_cndmask_b32_e32
203 ; GCN: v_cndmask_b32_e32
204 ; GCN: v_cndmask_b32_e32
205 ; GCN: v_cndmask_b32_e32
206 ; GCN: v_cndmask_b32_e32
207 ; GCN: v_cndmask_b32_e32
208 ; GCN: v_cndmask_b32_e32
209 define amdgpu_kernel void @select_v8i32(<8 x i32> 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, <8 x i32> addrspace(1)* %out, align 16
216 ; GCN-LABEL: {{^}}s_select_v2f32:
217 ; GCN-DAG: s_load_dwordx4 s[[[ALO:[0-9]+]]:[[BHI:[0-9]+]]], s{{\[[0-9]+:[0-9]+\]}}, {{0xb|0x2c}}
219 ; GCN-DAG: v_mov_b32_e32 v{{[0-9]+}}, s[[BHI]]
220 ; GCN-DAG: v_mov_b32_e32 v{{[0-9]+}}, s[[ALO]]
221 ; GCN-DAG: s_cmp_eq_u32 s{{[0-9]+}}, 0{{$}}
223 ; GCN-DAG: v_cndmask_b32_e32
224 ; GCN-DAG: v_mov_b32_e32 v{{[0-9]+}}, s{{[0-9]+}}
225 ; GCN-DAG: v_cndmask_b32_e32
226 ; GCN: buffer_store_dwordx2
227 define amdgpu_kernel void @s_select_v2f32(<2 x float> addrspace(1)* %out, <2 x float> %a, <2 x float> %b, i32 %c) #0 {
228 %cmp = icmp eq i32 %c, 0
229 %select = select i1 %cmp, <2 x float> %a, <2 x float> %b
230 store <2 x float> %select, <2 x float> addrspace(1)* %out, align 16
234 ; GCN-LABEL: {{^}}s_select_v3f32:
235 ; GCN: s_cmp_eq_u32 s{{[0-9]+}}, 0{{$}}
237 ; GCN: v_cndmask_b32_e32
238 ; GCN: v_cndmask_b32_e32
239 ; GCN: v_cndmask_b32_e32
241 ; GCN: buffer_store_dwordx
242 define amdgpu_kernel void @s_select_v3f32(<3 x float> addrspace(1)* %out, <3 x float> %a, <3 x float> %b, i32 %c) #0 {
243 %cmp = icmp eq i32 %c, 0
244 %select = select i1 %cmp, <3 x float> %a, <3 x float> %b
245 store <3 x float> %select, <3 x float> addrspace(1)* %out, align 16
249 ; GCN-LABEL: {{^}}s_select_v4f32:
250 ; GCN: s_load_dwordx8
251 ; GCN: s_cmp_eq_u32 s{{[0-9]+}}, 0{{$}}
253 ; GCN: v_cndmask_b32_e32
254 ; GCN: v_cndmask_b32_e32
255 ; GCN: v_cndmask_b32_e32
256 ; GCN: v_cndmask_b32_e32
258 ; GCN: buffer_store_dwordx4
259 define amdgpu_kernel void @s_select_v4f32(<4 x float> addrspace(1)* %out, <4 x float> %a, <4 x float> %b, i32 %c) #0 {
260 %cmp = icmp eq i32 %c, 0
261 %select = select i1 %cmp, <4 x float> %a, <4 x float> %b
262 store <4 x float> %select, <4 x float> addrspace(1)* %out, align 16
266 ; GCN-LABEL: {{^}}v_select_v4f32:
267 ; GCN: buffer_load_dwordx4
268 ; GCN: s_cmp_lt_u32 s{{[0-9]+}}, 32
269 ; GCN: s_cselect_b64 vcc, -1, 0
270 ; GCN: v_cndmask_b32_e32 v{{[0-9]+}}, 0, v{{[0-9]+}}, vcc
271 ; GCN: v_cndmask_b32_e32 v{{[0-9]+}}, 0, v{{[0-9]+}}, vcc
272 ; GCN: v_cndmask_b32_e32 v{{[0-9]+}}, 0, v{{[0-9]+}}, vcc
273 ; GCN: v_cndmask_b32_e32 v{{[0-9]+}}, 0, v{{[0-9]+}}, vcc
274 ; GCN: buffer_store_dwordx4
275 define amdgpu_kernel void @v_select_v4f32(<4 x float> addrspace(1)* %out, <4 x float> addrspace(1)* %in, i32 %cond) #0 {
277 %tmp2 = icmp ult i32 %cond, 32
278 %val = load <4 x float>, <4 x float> addrspace(1)* %in
279 %tmp3 = select i1 %tmp2, <4 x float> %val, <4 x float> zeroinitializer
280 store <4 x float> %tmp3, <4 x float> addrspace(1)* %out, align 16
284 ; GCN-LABEL: {{^}}s_select_v5f32:
285 ; GCN: s_cmp_eq_u32 s{{[0-9]+}}, 0{{$}}
287 ; GCN: v_cndmask_b32_e32
288 ; GCN: v_cndmask_b32_e32
289 ; GCN: v_cndmask_b32_e32
290 ; GCN: v_cndmask_b32_e32
291 ; GCN: v_cndmask_b32_e32
293 ; GCN: buffer_store_dwordx
294 define amdgpu_kernel void @s_select_v5f32(<5 x float> addrspace(1)* %out, <5 x float> %a, <5 x float> %b, i32 %c) #0 {
295 %cmp = icmp eq i32 %c, 0
296 %select = select i1 %cmp, <5 x float> %a, <5 x float> %b
297 store <5 x float> %select, <5 x float> addrspace(1)* %out, align 16
301 ; GCN-LABEL: {{^}}select_v8f32:
302 ; GCN: v_cndmask_b32_e32
303 ; GCN: v_cndmask_b32_e32
304 ; GCN: v_cndmask_b32_e32
305 ; GCN: v_cndmask_b32_e32
306 ; GCN: v_cndmask_b32_e32
307 ; GCN: v_cndmask_b32_e32
308 ; GCN: v_cndmask_b32_e32
309 ; GCN: v_cndmask_b32_e32
310 define amdgpu_kernel void @select_v8f32(<8 x float> addrspace(1)* %out, <8 x float> %a, <8 x float> %b, i32 %c) #0 {
311 %cmp = icmp eq i32 %c, 0
312 %select = select i1 %cmp, <8 x float> %a, <8 x float> %b
313 store <8 x float> %select, <8 x float> addrspace(1)* %out, align 16
317 ; GCN-LABEL: {{^}}select_v2f64:
318 ; GCN: v_cndmask_b32_e32
319 ; GCN: v_cndmask_b32_e32
320 ; GCN: v_cndmask_b32_e32
321 ; GCN: v_cndmask_b32_e32
322 define amdgpu_kernel void @select_v2f64(<2 x double> addrspace(1)* %out, <2 x double> %a, <2 x double> %b, i32 %c) #0 {
323 %cmp = icmp eq i32 %c, 0
324 %select = select i1 %cmp, <2 x double> %a, <2 x double> %b
325 store <2 x double> %select, <2 x double> addrspace(1)* %out, align 16
329 ; GCN-LABEL: {{^}}select_v4f64:
330 ; GCN: v_cndmask_b32_e32
331 ; GCN: v_cndmask_b32_e32
332 ; GCN: v_cndmask_b32_e32
333 ; GCN: v_cndmask_b32_e32
334 ; GCN: v_cndmask_b32_e32
335 ; GCN: v_cndmask_b32_e32
336 ; GCN: v_cndmask_b32_e32
337 ; GCN: v_cndmask_b32_e32
338 define amdgpu_kernel void @select_v4f64(<4 x double> addrspace(1)* %out, <4 x double> %a, <4 x double> %b, i32 %c) #0 {
339 %cmp = icmp eq i32 %c, 0
340 %select = select i1 %cmp, <4 x double> %a, <4 x double> %b
341 store <4 x double> %select, <4 x double> addrspace(1)* %out, align 16
345 ; GCN-LABEL: {{^}}select_v8f64:
346 ; GCN: v_cndmask_b32_e32
347 ; GCN: v_cndmask_b32_e32
348 ; GCN: v_cndmask_b32_e32
349 ; GCN: v_cndmask_b32_e32
350 ; GCN: v_cndmask_b32_e32
351 ; GCN: v_cndmask_b32_e32
352 ; GCN: v_cndmask_b32_e32
353 ; GCN: v_cndmask_b32_e32
354 ; GCN: v_cndmask_b32_e32
355 ; GCN: v_cndmask_b32_e32
356 ; GCN: v_cndmask_b32_e32
357 ; GCN: v_cndmask_b32_e32
358 ; GCN: v_cndmask_b32_e32
359 ; GCN: v_cndmask_b32_e32
360 ; GCN: v_cndmask_b32_e32
361 ; GCN: v_cndmask_b32_e32
362 define amdgpu_kernel void @select_v8f64(<8 x double> addrspace(1)* %out, <8 x double> %a, <8 x double> %b, i32 %c) #0 {
363 %cmp = icmp eq i32 %c, 0
364 %select = select i1 %cmp, <8 x double> %a, <8 x double> %b
365 store <8 x double> %select, <8 x double> addrspace(1)* %out, align 16
369 ; GCN-LABEL: {{^}}v_select_v2f16:
372 define amdgpu_kernel void @v_select_v2f16(<2 x half> addrspace(1)* %out, <2 x half> addrspace(1)* %a.ptr, <2 x half> addrspace(1)* %b.ptr, i32 %c) #0 {
373 %a = load <2 x half>, <2 x half> addrspace(1)* %a.ptr
374 %b = load <2 x half>, <2 x half> addrspace(1)* %b.ptr
375 %cmp = icmp eq i32 %c, 0
376 %select = select i1 %cmp, <2 x half> %a, <2 x half> %b
377 store <2 x half> %select, <2 x half> addrspace(1)* %out, align 4
381 ; GCN-LABEL: {{^}}v_select_v3f16:
382 ; GCN: v_cndmask_b32_e32
383 ; GCN: v_cndmask_b32_e32
385 define amdgpu_kernel void @v_select_v3f16(<3 x half> addrspace(1)* %out, <3 x half> addrspace(1)* %a.ptr, <3 x half> addrspace(1)* %b.ptr, i32 %c) #0 {
386 %a = load <3 x half>, <3 x half> addrspace(1)* %a.ptr
387 %b = load <3 x half>, <3 x half> addrspace(1)* %b.ptr
388 %cmp = icmp eq i32 %c, 0
389 %select = select i1 %cmp, <3 x half> %a, <3 x half> %b
390 store <3 x half> %select, <3 x half> addrspace(1)* %out, align 4
394 ; GCN-LABEL: {{^}}v_select_v4f16:
395 ; GCN: v_cndmask_b32_e32
396 ; GCN: v_cndmask_b32_e32
398 define amdgpu_kernel void @v_select_v4f16(<4 x half> addrspace(1)* %out, <4 x half> addrspace(1)* %a.ptr, <4 x half> addrspace(1)* %b.ptr, i32 %c) #0 {
399 %a = load <4 x half>, <4 x half> addrspace(1)* %a.ptr
400 %b = load <4 x half>, <4 x half> addrspace(1)* %b.ptr
401 %cmp = icmp eq i32 %c, 0
402 %select = select i1 %cmp, <4 x half> %a, <4 x half> %b
403 store <4 x half> %select, <4 x half> addrspace(1)* %out, align 4
407 ; Function Attrs: nounwind readnone
408 declare i32 @llvm.amdgcn.workitem.id.x() #1
410 attributes #0 = { nounwind }
411 attributes #1 = { nounwind readnone }