1 ; RUN: llc -amdgpu-scalarize-global-loads=false -march=amdgcn -mtriple=amdgcn-- -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefix=GCN -check-prefix=SI -check-prefix=FUNC %s
2 ; RUN: llc -amdgpu-scalarize-global-loads=false -march=amdgcn -mtriple=amdgcn-- -mcpu=tonga -mattr=-flat-for-global -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefix=GCN -check-prefix=VI -check-prefix=GFX89 -check-prefix=FUNC %s
3 ; RUN: llc -amdgpu-scalarize-global-loads=false -march=amdgcn -mtriple=amdgcn-- -mcpu=gfx900 -mattr=-flat-for-global -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefix=GCN -check-prefix=GFX9 -check-prefix=GFX89 -check-prefix=FUNC %s
4 ; RUN: llc -amdgpu-scalarize-global-loads=false -march=r600 -mtriple=r600-- -mcpu=cypress < %s | FileCheck -enable-var-scope -check-prefix=EG -check-prefix=FUNC %s
6 ; FIXME: i16 promotion pass ruins the scalar cases when legal.
7 ; FIXME: r600 fails verifier
9 ; FUNC-LABEL: {{^}}sext_in_reg_i1_i32:
10 ; GCN: s_load_dword [[ARG:s[0-9]+]],
11 ; GCN: s_bfe_i32 [[SEXTRACT:s[0-9]+]], [[ARG]], 0x10000
12 ; GCN: v_mov_b32_e32 [[EXTRACT:v[0-9]+]], [[SEXTRACT]]
13 ; GCN: buffer_store_dword [[EXTRACT]],
15 ; EG: MEM_{{.*}} STORE_{{.*}} [[RES:T[0-9]+\.[XYZW]]], [[ADDR:T[0-9]+.[XYZW]]]
17 ; EG: BFE_INT * [[RES]], {{.*}}, 0.0, 1
18 define amdgpu_kernel void @sext_in_reg_i1_i32(i32 addrspace(1)* %out, i32 %in) #0 {
19 %shl = shl i32 %in, 31
20 %sext = ashr i32 %shl, 31
21 store i32 %sext, i32 addrspace(1)* %out
25 ; FUNC-LABEL: {{^}}sext_in_reg_i8_to_i32:
26 ; GCN: s_add_i32 [[VAL:s[0-9]+]],
27 ; GCN: s_sext_i32_i8 [[EXTRACT:s[0-9]+]], [[VAL]]
28 ; GCN: v_mov_b32_e32 [[VEXTRACT:v[0-9]+]], [[EXTRACT]]
29 ; GCN: buffer_store_dword [[VEXTRACT]],
31 ; EG: MEM_{{.*}} STORE_{{.*}} [[RES:T[0-9]+\.[XYZW]]], [[ADDR:T[0-9]+.[XYZW]]]
33 ; EG-NEXT: BFE_INT [[RES]], {{.*}}, 0.0, literal
34 ; EG-NEXT: LSHR * [[ADDR]]
35 define amdgpu_kernel void @sext_in_reg_i8_to_i32(i32 addrspace(1)* %out, i32 %a, i32 %b) #0 {
36 %c = add i32 %a, %b ; add to prevent folding into extload
38 %ashr = ashr i32 %shl, 24
39 store i32 %ashr, i32 addrspace(1)* %out, align 4
43 ; FUNC-LABEL: {{^}}sext_in_reg_i16_to_i32:
44 ; GCN: s_add_i32 [[VAL:s[0-9]+]],
45 ; GCN: s_sext_i32_i16 [[EXTRACT:s[0-9]+]], [[VAL]]
46 ; GCN: v_mov_b32_e32 [[VEXTRACT:v[0-9]+]], [[EXTRACT]]
47 ; GCN: buffer_store_dword [[VEXTRACT]],
49 ; EG: MEM_{{.*}} STORE_{{.*}} [[RES:T[0-9]+\.[XYZW]]], [[ADDR:T[0-9]+.[XYZW]]]
51 ; EG-NEXT: BFE_INT [[RES]], {{.*}}, 0.0, literal
52 ; EG-NEXT: LSHR * [[ADDR]]
53 define amdgpu_kernel void @sext_in_reg_i16_to_i32(i32 addrspace(1)* %out, i32 %a, i32 %b) #0 {
54 %c = add i32 %a, %b ; add to prevent folding into extload
56 %ashr = ashr i32 %shl, 16
57 store i32 %ashr, i32 addrspace(1)* %out, align 4
61 ; FUNC-LABEL: {{^}}sext_in_reg_i8_to_v1i32:
62 ; GCN: s_add_i32 [[VAL:s[0-9]+]],
63 ; GCN: s_sext_i32_i8 [[EXTRACT:s[0-9]+]], [[VAL]]
64 ; GCN: v_mov_b32_e32 [[VEXTRACT:v[0-9]+]], [[EXTRACT]]
65 ; GCN: buffer_store_dword [[VEXTRACT]],
67 ; EG: MEM_{{.*}} STORE_{{.*}} [[RES:T[0-9]+\.[XYZW]]], [[ADDR:T[0-9]+.[XYZW]]]
69 ; EG-NEXT: BFE_INT [[RES]], {{.*}}, 0.0, literal
70 ; EG-NEXT: LSHR * [[ADDR]]
71 define amdgpu_kernel void @sext_in_reg_i8_to_v1i32(<1 x i32> addrspace(1)* %out, <1 x i32> %a, <1 x i32> %b) #0 {
72 %c = add <1 x i32> %a, %b ; add to prevent folding into extload
73 %shl = shl <1 x i32> %c, <i32 24>
74 %ashr = ashr <1 x i32> %shl, <i32 24>
75 store <1 x i32> %ashr, <1 x i32> addrspace(1)* %out, align 4
79 ; FUNC-LABEL: {{^}}sext_in_reg_i1_to_i64:
80 ; GCN: s_lshl_b64 [[VAL:s\[[0-9]+:[0-9]+\]]]
81 ; GCN-DAG: s_bfe_i64 s{{\[}}[[SLO:[0-9]+]]:[[SHI:[0-9]+]]{{\]}}, [[VAL]], 0x10000
82 ; GCN-DAG: v_mov_b32_e32 v[[VLO:[0-9]+]], s[[SLO]]
83 ; GCN-DAG: v_mov_b32_e32 v[[VHI:[0-9]+]], s[[SHI]]
84 ; GCN: buffer_store_dwordx2 v{{\[}}[[VLO]]:[[VHI]]{{\]}}
85 define amdgpu_kernel void @sext_in_reg_i1_to_i64(i64 addrspace(1)* %out, i64 %a, i64 %b) #0 {
88 %ashr = ashr i64 %shl, 63
89 store i64 %ashr, i64 addrspace(1)* %out, align 8
93 ; FUNC-LABEL: {{^}}sext_in_reg_i8_to_i64:
94 ; GCN: s_lshl_b64 [[VAL:s\[[0-9]+:[0-9]+\]]]
95 ; GCN-DAG: s_bfe_i64 s{{\[}}[[SLO:[0-9]+]]:[[SHI:[0-9]+]]{{\]}}, [[VAL]], 0x80000
96 ; GCN-DAG: v_mov_b32_e32 v[[VLO:[0-9]+]], s[[SLO]]
97 ; GCN-DAG: v_mov_b32_e32 v[[VHI:[0-9]+]], s[[SHI]]
98 ; GCN: buffer_store_dwordx2 v{{\[}}[[VLO]]:[[VHI]]{{\]}}
99 define amdgpu_kernel void @sext_in_reg_i8_to_i64(i64 addrspace(1)* %out, i64 %a, i64 %b) #0 {
101 %shl = shl i64 %c, 56
102 %ashr = ashr i64 %shl, 56
103 store i64 %ashr, i64 addrspace(1)* %out, align 8
107 ; FUNC-LABEL: {{^}}sext_in_reg_i16_to_i64:
108 ; GCN: s_lshl_b64 [[VAL:s\[[0-9]+:[0-9]+\]]]
109 ; GCN-DAG: s_bfe_i64 s{{\[}}[[SLO:[0-9]+]]:[[SHI:[0-9]+]]{{\]}}, [[VAL]], 0x100000
110 ; GCN-DAG: v_mov_b32_e32 v[[VLO:[0-9]+]], s[[SLO]]
111 ; GCN-DAG: v_mov_b32_e32 v[[VHI:[0-9]+]], s[[SHI]]
112 ; GCN: buffer_store_dwordx2 v{{\[}}[[VLO]]:[[VHI]]{{\]}}
114 define amdgpu_kernel void @sext_in_reg_i16_to_i64(i64 addrspace(1)* %out, i64 %a, i64 %b) #0 {
116 %shl = shl i64 %c, 48
117 %ashr = ashr i64 %shl, 48
118 store i64 %ashr, i64 addrspace(1)* %out, align 8
122 ; FUNC-LABEL: {{^}}sext_in_reg_i32_to_i64:
123 ; GCN: s_lshl_b64 [[VAL:s\[[0-9]+:[0-9]+\]]]
124 ; GCN-DAG: s_bfe_i64 s{{\[}}[[SLO:[0-9]+]]:[[SHI:[0-9]+]]{{\]}}, [[VAL]], 0x200000
125 ; GCN-DAG: v_mov_b32_e32 v[[VLO:[0-9]+]], s[[SLO]]
126 ; GCN-DAG: v_mov_b32_e32 v[[VHI:[0-9]+]], s[[SHI]]
127 ; GCN: buffer_store_dwordx2 v{{\[}}[[VLO]]:[[VHI]]{{\]}}
128 define amdgpu_kernel void @sext_in_reg_i32_to_i64(i64 addrspace(1)* %out, i64 %a, i64 %b) #0 {
130 %shl = shl i64 %c, 32
131 %ashr = ashr i64 %shl, 32
132 store i64 %ashr, i64 addrspace(1)* %out, align 8
136 ; This is broken on Evergreen for some reason related to the <1 x i64> kernel arguments.
137 ; XFUNC-LABEL: {{^}}sext_in_reg_i8_to_v1i64:
138 ; XGCN: s_bfe_i32 [[EXTRACT:s[0-9]+]], {{s[0-9]+}}, 524288
139 ; XGCN: s_ashr_i32 {{v[0-9]+}}, [[EXTRACT]], 31
140 ; XGCN: buffer_store_dword
143 ; define amdgpu_kernel void @sext_in_reg_i8_to_v1i64(<1 x i64> addrspace(1)* %out, <1 x i64> %a, <1 x i64> %b) #0 {
144 ; %c = add <1 x i64> %a, %b
145 ; %shl = shl <1 x i64> %c, <i64 56>
146 ; %ashr = ashr <1 x i64> %shl, <i64 56>
147 ; store <1 x i64> %ashr, <1 x i64> addrspace(1)* %out, align 8
151 ; FUNC-LABEL: {{^}}v_sext_in_reg_i1_to_i64:
152 ; SI: buffer_load_dwordx2
153 ; SI: v_lshl_b64 v{{\[}}[[VAL_LO:[0-9]+]]:[[VAL_HI:[0-9]+]]{{\]}}
155 ; GFX89: {{flat|global}}_load_dwordx2
156 ; GFX89: v_lshlrev_b64 v{{\[}}[[VAL_LO:[0-9]+]]:[[VAL_HI:[0-9]+]]{{\]}}
158 ; GCN: v_bfe_i32 v[[LO:[0-9]+]], v[[VAL_LO]], 0, 1
159 ; GCN: v_ashrrev_i32_e32 v[[HI:[0-9]+]], 31, v[[LO]]
161 ; SI: buffer_store_dwordx2 v{{\[}}[[LO]]:[[HI]]{{\]}}
162 ; GFX89: {{flat|global}}_store_dwordx2 v{{\[[0-9]+:[0-9]+\]}}, v{{\[}}[[LO]]:[[HI]]{{\]}}
163 define amdgpu_kernel void @v_sext_in_reg_i1_to_i64(i64 addrspace(1)* %out, i64 addrspace(1)* %aptr, i64 addrspace(1)* %bptr) #0 {
164 %tid = call i32 @llvm.r600.read.tidig.x()
165 %a.gep = getelementptr i64, i64 addrspace(1)* %aptr, i32 %tid
166 %b.gep = getelementptr i64, i64 addrspace(1)* %aptr, i32 %tid
167 %out.gep = getelementptr i64, i64 addrspace(1)* %out, i32 %tid
168 %a = load i64, i64 addrspace(1)* %a.gep, align 8
169 %b = load i64, i64 addrspace(1)* %b.gep, align 8
172 %shl = shl i64 %c, 63
173 %ashr = ashr i64 %shl, 63
174 store i64 %ashr, i64 addrspace(1)* %out.gep, align 8
178 ; FUNC-LABEL: {{^}}v_sext_in_reg_i8_to_i64:
179 ; SI: buffer_load_dwordx2
180 ; SI: v_lshl_b64 v{{\[}}[[VAL_LO:[0-9]+]]:[[VAL_HI:[0-9]+]]{{\]}}
182 ; GFX89: {{flat|global}}_load_dwordx2
183 ; GFX89: v_lshlrev_b64 v{{\[}}[[VAL_LO:[0-9]+]]:[[VAL_HI:[0-9]+]]{{\]}}
185 ; GCN: v_bfe_i32 v[[LO:[0-9]+]], v[[VAL_LO]], 0, 8
186 ; GCN: v_ashrrev_i32_e32 v[[HI:[0-9]+]], 31, v[[LO]]
188 ; SI: buffer_store_dwordx2 v{{\[}}[[LO]]:[[HI]]{{\]}}
189 ; GFX89: {{flat|global}}_store_dwordx2 v{{\[[0-9]+:[0-9]+\]}}, v{{\[}}[[LO]]:[[HI]]{{\]}}
190 define amdgpu_kernel void @v_sext_in_reg_i8_to_i64(i64 addrspace(1)* %out, i64 addrspace(1)* %aptr, i64 addrspace(1)* %bptr) #0 {
191 %tid = call i32 @llvm.r600.read.tidig.x()
192 %a.gep = getelementptr i64, i64 addrspace(1)* %aptr, i32 %tid
193 %b.gep = getelementptr i64, i64 addrspace(1)* %aptr, i32 %tid
194 %out.gep = getelementptr i64, i64 addrspace(1)* %out, i32 %tid
195 %a = load i64, i64 addrspace(1)* %a.gep, align 8
196 %b = load i64, i64 addrspace(1)* %b.gep, align 8
199 %shl = shl i64 %c, 56
200 %ashr = ashr i64 %shl, 56
201 store i64 %ashr, i64 addrspace(1)* %out.gep, align 8
205 ; FUNC-LABEL: {{^}}v_sext_in_reg_i16_to_i64:
206 ; SI: buffer_load_dwordx2
207 ; SI: v_lshl_b64 v{{\[}}[[VAL_LO:[0-9]+]]:[[VAL_HI:[0-9]+]]{{\]}}
209 ; GFX89: {{flat|global}}_load_dwordx2
210 ; GFX89: v_lshlrev_b64 v{{\[}}[[VAL_LO:[0-9]+]]:[[VAL_HI:[0-9]+]]{{\]}}
212 ; GCN: v_bfe_i32 v[[LO:[0-9]+]], v[[VAL_LO]], 0, 16
213 ; GCN: v_ashrrev_i32_e32 v[[HI:[0-9]+]], 31, v[[LO]]
215 ; SI: buffer_store_dwordx2 v{{\[}}[[LO]]:[[HI]]{{\]}}
216 ; GFX89: {{flat|global}}_store_dwordx2 v{{\[[0-9]+:[0-9]+\]}}, v{{\[}}[[LO]]:[[HI]]{{\]}}
217 define amdgpu_kernel void @v_sext_in_reg_i16_to_i64(i64 addrspace(1)* %out, i64 addrspace(1)* %aptr, i64 addrspace(1)* %bptr) #0 {
218 %tid = call i32 @llvm.r600.read.tidig.x()
219 %a.gep = getelementptr i64, i64 addrspace(1)* %aptr, i32 %tid
220 %b.gep = getelementptr i64, i64 addrspace(1)* %aptr, i32 %tid
221 %out.gep = getelementptr i64, i64 addrspace(1)* %out, i32 %tid
222 %a = load i64, i64 addrspace(1)* %a.gep, align 8
223 %b = load i64, i64 addrspace(1)* %b.gep, align 8
226 %shl = shl i64 %c, 48
227 %ashr = ashr i64 %shl, 48
228 store i64 %ashr, i64 addrspace(1)* %out.gep, align 8
232 ; FUNC-LABEL: {{^}}v_sext_in_reg_i32_to_i64:
233 ; SI: buffer_load_dwordx2
234 ; SI: v_lshl_b64 v{{\[}}[[LO:[0-9]+]]:[[HI:[0-9]+]]{{\]}},
236 ; GFX89: {{flat|global}}_load_dwordx2
237 ; GFX89: v_lshlrev_b64 v{{\[}}[[LO:[0-9]+]]:[[HI:[0-9]+]]{{\]}},
239 ; GCN: v_ashrrev_i32_e32 v[[SHR:[0-9]+]], 31, v[[LO]]
240 ; GFX89: {{flat|global}}_store_dwordx2 v{{\[[0-9]+:[0-9]+\]}}, v{{\[}}[[LO]]:[[SHR]]{{\]}}
241 define amdgpu_kernel void @v_sext_in_reg_i32_to_i64(i64 addrspace(1)* %out, i64 addrspace(1)* %aptr, i64 addrspace(1)* %bptr) #0 {
242 %tid = call i32 @llvm.r600.read.tidig.x()
243 %a.gep = getelementptr i64, i64 addrspace(1)* %aptr, i32 %tid
244 %b.gep = getelementptr i64, i64 addrspace(1)* %aptr, i32 %tid
245 %out.gep = getelementptr i64, i64 addrspace(1)* %out, i32 %tid
246 %a = load i64, i64 addrspace(1)* %a.gep, align 8
247 %b = load i64, i64 addrspace(1)* %b.gep, align 8
250 %shl = shl i64 %c, 32
251 %ashr = ashr i64 %shl, 32
252 store i64 %ashr, i64 addrspace(1)* %out.gep, align 8
256 ; FUNC-LABEL: {{^}}sext_in_reg_i1_in_i32_other_amount:
259 ; GCN: s_bfe_i32 {{s[0-9]+}}, {{s[0-9]+}}, 0x190001
261 ; EG: MEM_{{.*}} STORE_{{.*}} [[RES:T[0-9]+\.[XYZW]]], [[ADDR:T[0-9]+.[XYZW]]]
266 ; EG: LSHR {{\*?}} [[ADDR]]
267 define amdgpu_kernel void @sext_in_reg_i1_in_i32_other_amount(i32 addrspace(1)* %out, i32 %a, i32 %b) #0 {
271 store i32 %y, i32 addrspace(1)* %out
275 ; FUNC-LABEL: {{^}}sext_in_reg_v2i1_in_v2i32_other_amount:
278 ; GCN-DAG: s_bfe_i32 {{s[0-9]+}}, {{s[0-9]+}}, 0x190001
279 ; GCN-DAG: s_bfe_i32 {{s[0-9]+}}, {{s[0-9]+}}, 0x190001
282 ; EG: MEM_{{.*}} STORE_{{.*}} [[RES:T[0-9]+]]{{\.[XYZW][XYZW]}}, [[ADDR:T[0-9]+.[XYZW]]]
289 ; EG: LSHR {{\*?}} [[ADDR]]
290 define amdgpu_kernel void @sext_in_reg_v2i1_in_v2i32_other_amount(<2 x i32> addrspace(1)* %out, <2 x i32> %a, <2 x i32> %b) #0 {
291 %c = add <2 x i32> %a, %b
292 %x = shl <2 x i32> %c, <i32 6, i32 6>
293 %y = ashr <2 x i32> %x, <i32 7, i32 7>
294 store <2 x i32> %y, <2 x i32> addrspace(1)* %out
299 ; FUNC-LABEL: {{^}}sext_in_reg_v2i1_to_v2i32:
300 ; GCN: s_bfe_i32 {{s[0-9]+}}, {{s[0-9]+}}, 0x10000
301 ; GCN: s_bfe_i32 {{s[0-9]+}}, {{s[0-9]+}}, 0x10000
302 ; GCN: buffer_store_dwordx2
304 ; EG: MEM_{{.*}} STORE_{{.*}} [[RES:T[0-9]+]]{{\.[XYZW][XYZW]}}, [[ADDR:T[0-9]+.[XYZW]]]
305 ; EG: BFE_INT [[RES]]
306 ; EG: BFE_INT [[RES]]
307 ; EG: LSHR {{\*?}} [[ADDR]]
308 define amdgpu_kernel void @sext_in_reg_v2i1_to_v2i32(<2 x i32> addrspace(1)* %out, <2 x i32> %a, <2 x i32> %b) #0 {
309 %c = add <2 x i32> %a, %b ; add to prevent folding into extload
310 %shl = shl <2 x i32> %c, <i32 31, i32 31>
311 %ashr = ashr <2 x i32> %shl, <i32 31, i32 31>
312 store <2 x i32> %ashr, <2 x i32> addrspace(1)* %out, align 8
316 ; FUNC-LABEL: {{^}}sext_in_reg_v4i1_to_v4i32:
317 ; GCN: s_bfe_i32 {{s[0-9]+}}, {{s[0-9]+}}, 0x10000
318 ; GCN: s_bfe_i32 {{s[0-9]+}}, {{s[0-9]+}}, 0x10000
319 ; GCN: s_bfe_i32 {{s[0-9]+}}, {{s[0-9]+}}, 0x10000
320 ; GCN: s_bfe_i32 {{s[0-9]+}}, {{s[0-9]+}}, 0x10000
321 ; GCN: buffer_store_dwordx4
323 ; EG: MEM_{{.*}} STORE_{{.*}} [[RES:T[0-9]+]]{{\.[XYZW][XYZW][XYZW][XYZW]}}, [[ADDR:T[0-9]+.[XYZW]]]
324 ; EG: BFE_INT [[RES]]
325 ; EG: BFE_INT [[RES]]
326 ; EG: BFE_INT [[RES]]
327 ; EG: BFE_INT [[RES]]
328 ; EG: LSHR {{\*?}} [[ADDR]]
329 define amdgpu_kernel void @sext_in_reg_v4i1_to_v4i32(<4 x i32> addrspace(1)* %out, <4 x i32> %a, <4 x i32> %b) #0 {
330 %c = add <4 x i32> %a, %b ; add to prevent folding into extload
331 %shl = shl <4 x i32> %c, <i32 31, i32 31, i32 31, i32 31>
332 %ashr = ashr <4 x i32> %shl, <i32 31, i32 31, i32 31, i32 31>
333 store <4 x i32> %ashr, <4 x i32> addrspace(1)* %out, align 8
337 ; FUNC-LABEL: {{^}}sext_in_reg_v2i8_to_v2i32:
338 ; GCN: s_sext_i32_i8 {{s[0-9]+}}, {{s[0-9]+}}
339 ; GCN: s_sext_i32_i8 {{s[0-9]+}}, {{s[0-9]+}}
340 ; GCN: buffer_store_dwordx2
342 ; EG: MEM_{{.*}} STORE_{{.*}} [[RES:T[0-9]+]]{{\.[XYZW][XYZW]}}, [[ADDR:T[0-9]+.[XYZW]]]
343 ; EG: BFE_INT [[RES]]
344 ; EG: BFE_INT [[RES]]
345 ; EG: LSHR {{\*?}} [[ADDR]]
346 define amdgpu_kernel void @sext_in_reg_v2i8_to_v2i32(<2 x i32> addrspace(1)* %out, <2 x i32> %a, <2 x i32> %b) #0 {
347 %c = add <2 x i32> %a, %b ; add to prevent folding into extload
348 %shl = shl <2 x i32> %c, <i32 24, i32 24>
349 %ashr = ashr <2 x i32> %shl, <i32 24, i32 24>
350 store <2 x i32> %ashr, <2 x i32> addrspace(1)* %out, align 8
354 ; FUNC-LABEL: {{^}}sext_in_reg_v4i8_to_v4i32:
355 ; GCN: s_sext_i32_i8 {{s[0-9]+}}, {{s[0-9]+}}
356 ; GCN: s_sext_i32_i8 {{s[0-9]+}}, {{s[0-9]+}}
357 ; GCN: s_sext_i32_i8 {{s[0-9]+}}, {{s[0-9]+}}
358 ; GCN: s_sext_i32_i8 {{s[0-9]+}}, {{s[0-9]+}}
359 ; GCN: buffer_store_dwordx4
361 ; EG: MEM_{{.*}} STORE_{{.*}} [[RES:T[0-9]+]]{{\.[XYZW][XYZW][XYZW][XYZW]}}, [[ADDR:T[0-9]+.[XYZW]]]
362 ; EG: BFE_INT [[RES]]
363 ; EG: BFE_INT [[RES]]
364 ; EG: BFE_INT [[RES]]
365 ; EG: BFE_INT [[RES]]
366 ; EG: LSHR {{\*?}} [[ADDR]]
367 define amdgpu_kernel void @sext_in_reg_v4i8_to_v4i32(<4 x i32> addrspace(1)* %out, <4 x i32> %a, <4 x i32> %b) #0 {
368 %c = add <4 x i32> %a, %b ; add to prevent folding into extload
369 %shl = shl <4 x i32> %c, <i32 24, i32 24, i32 24, i32 24>
370 %ashr = ashr <4 x i32> %shl, <i32 24, i32 24, i32 24, i32 24>
371 store <4 x i32> %ashr, <4 x i32> addrspace(1)* %out, align 8
375 ; FUNC-LABEL: {{^}}sext_in_reg_v2i16_to_v2i32:
376 ; GCN: s_sext_i32_i16 {{s[0-9]+}}, {{s[0-9]+}}
377 ; GCN: s_sext_i32_i16 {{s[0-9]+}}, {{s[0-9]+}}
378 ; GCN: buffer_store_dwordx2
380 ; EG: MEM_{{.*}} STORE_{{.*}} [[RES:T[0-9]+]]{{\.[XYZW][XYZW]}}, [[ADDR:T[0-9]+.[XYZW]]]
381 ; EG: BFE_INT [[RES]]
382 ; EG: BFE_INT [[RES]]
383 ; EG: LSHR {{\*?}} [[ADDR]]
384 define amdgpu_kernel void @sext_in_reg_v2i16_to_v2i32(<2 x i32> addrspace(1)* %out, <2 x i32> %a, <2 x i32> %b) #0 {
385 %c = add <2 x i32> %a, %b ; add to prevent folding into extload
386 %shl = shl <2 x i32> %c, <i32 16, i32 16>
387 %ashr = ashr <2 x i32> %shl, <i32 16, i32 16>
388 store <2 x i32> %ashr, <2 x i32> addrspace(1)* %out, align 8
392 ; FUNC-LABEL: {{^}}testcase:
393 define amdgpu_kernel void @testcase(i8 addrspace(1)* %out, i8 %a) #0 {
394 %and_a_1 = and i8 %a, 1
395 %cmp_eq = icmp eq i8 %and_a_1, 0
396 %cmp_slt = icmp slt i8 %a, 0
397 %sel0 = select i1 %cmp_slt, i8 0, i8 %a
398 %sel1 = select i1 %cmp_eq, i8 0, i8 %a
399 %xor = xor i8 %sel0, %sel1
400 store i8 %xor, i8 addrspace(1)* %out
404 ; FUNC-LABEL: {{^}}testcase_3:
405 define amdgpu_kernel void @testcase_3(i8 addrspace(1)* %out, i8 %a) #0 {
406 %and_a_1 = and i8 %a, 1
407 %cmp_eq = icmp eq i8 %and_a_1, 0
408 %cmp_slt = icmp slt i8 %a, 0
409 %sel0 = select i1 %cmp_slt, i8 0, i8 %a
410 %sel1 = select i1 %cmp_eq, i8 0, i8 %a
411 %xor = xor i8 %sel0, %sel1
412 store i8 %xor, i8 addrspace(1)* %out
416 ; FUNC-LABEL: {{^}}vgpr_sext_in_reg_v4i8_to_v4i32:
417 ; GCN: v_bfe_i32 [[EXTRACT:v[0-9]+]], {{v[0-9]+}}, 0, 8
418 ; GCN: v_bfe_i32 [[EXTRACT:v[0-9]+]], {{v[0-9]+}}, 0, 8
419 ; GCN: v_bfe_i32 [[EXTRACT:v[0-9]+]], {{v[0-9]+}}, 0, 8
420 ; GCN: v_bfe_i32 [[EXTRACT:v[0-9]+]], {{v[0-9]+}}, 0, 8
421 define amdgpu_kernel void @vgpr_sext_in_reg_v4i8_to_v4i32(<4 x i32> addrspace(1)* %out, <4 x i32> addrspace(1)* %a, <4 x i32> addrspace(1)* %b) #0 {
422 %loada = load <4 x i32>, <4 x i32> addrspace(1)* %a, align 16
423 %loadb = load <4 x i32>, <4 x i32> addrspace(1)* %b, align 16
424 %c = add <4 x i32> %loada, %loadb ; add to prevent folding into extload
425 %shl = shl <4 x i32> %c, <i32 24, i32 24, i32 24, i32 24>
426 %ashr = ashr <4 x i32> %shl, <i32 24, i32 24, i32 24, i32 24>
427 store <4 x i32> %ashr, <4 x i32> addrspace(1)* %out, align 8
431 ; FUNC-LABEL: {{^}}vgpr_sext_in_reg_v4i16_to_v4i32:
432 ; GCN: v_bfe_i32 [[EXTRACT:v[0-9]+]], {{v[0-9]+}}, 0, 16
433 ; GCN: v_bfe_i32 [[EXTRACT:v[0-9]+]], {{v[0-9]+}}, 0, 16
434 define amdgpu_kernel void @vgpr_sext_in_reg_v4i16_to_v4i32(<4 x i32> addrspace(1)* %out, <4 x i32> addrspace(1)* %a, <4 x i32> addrspace(1)* %b) #0 {
435 %loada = load <4 x i32>, <4 x i32> addrspace(1)* %a, align 16
436 %loadb = load <4 x i32>, <4 x i32> addrspace(1)* %b, align 16
437 %c = add <4 x i32> %loada, %loadb ; add to prevent folding into extload
438 %shl = shl <4 x i32> %c, <i32 16, i32 16, i32 16, i32 16>
439 %ashr = ashr <4 x i32> %shl, <i32 16, i32 16, i32 16, i32 16>
440 store <4 x i32> %ashr, <4 x i32> addrspace(1)* %out, align 8
444 ; FUNC-LABEL: {{^}}sext_in_reg_to_illegal_type:
445 ; GCN: buffer_load_sbyte
448 ; GCN: buffer_store_short
449 define amdgpu_kernel void @sext_in_reg_to_illegal_type(i16 addrspace(1)* nocapture %out, i8 addrspace(1)* nocapture %src) #0 {
450 %tmp5 = load i8, i8 addrspace(1)* %src, align 1
451 %tmp2 = sext i8 %tmp5 to i32
452 %tmp2.5 = icmp sgt i32 %tmp2, 0
453 %tmp3 = select i1 %tmp2.5, i32 %tmp2, i32 0
454 %tmp4 = trunc i32 %tmp3 to i8
455 %tmp6 = sext i8 %tmp4 to i16
456 store i16 %tmp6, i16 addrspace(1)* %out, align 2
460 ; Make sure we propagate the VALUness to users of a moved scalar BFE.
462 ; FUNC-LABEL: {{^}}v_sext_in_reg_i1_to_i64_move_use:
463 ; SI: buffer_load_dwordx2
464 ; SI: v_lshl_b64 v{{\[}}[[VAL_LO:[0-9]+]]:[[VAL_HI:[0-9]+]]{{\]}}
466 ; GFX89: {{flat|global}}_load_dwordx2
467 ; GFX89: v_lshlrev_b64 v{{\[}}[[VAL_LO:[0-9]+]]:[[VAL_HI:[0-9]+]]{{\]}}
469 ; GCN-DAG: v_bfe_i32 v[[LO:[0-9]+]], v[[VAL_LO]], 0, 1
470 ; GCN-DAG: v_ashrrev_i32_e32 v[[HI:[0-9]+]], 31, v[[LO]]
471 ; GCN-DAG: v_and_b32_e32 v[[RESULT_LO:[0-9]+]], s{{[0-9]+}}, v[[LO]]
472 ; GCN-DAG: v_and_b32_e32 v[[RESULT_HI:[0-9]+]], s{{[0-9]+}}, v[[HI]]
473 ; SI: buffer_store_dwordx2 v{{\[}}[[RESULT_LO]]:[[RESULT_HI]]{{\]}}
474 ; GFX89: {{flat|global}}_store_dwordx2 v{{\[[0-9]+:[0-9]+\]}}, v{{\[}}[[RESULT_LO]]:[[RESULT_HI]]{{\]}}
475 define amdgpu_kernel void @v_sext_in_reg_i1_to_i64_move_use(i64 addrspace(1)* %out, i64 addrspace(1)* %aptr, i64 addrspace(1)* %bptr, i64 %s.val) #0 {
476 %tid = call i32 @llvm.r600.read.tidig.x()
477 %a.gep = getelementptr i64, i64 addrspace(1)* %aptr, i32 %tid
478 %b.gep = getelementptr i64, i64 addrspace(1)* %aptr, i32 %tid
479 %out.gep = getelementptr i64, i64 addrspace(1)* %out, i32 %tid
480 %a = load i64, i64 addrspace(1)* %a.gep, align 8
481 %b = load i64, i64 addrspace(1)* %b.gep, align 8
484 %shl = shl i64 %c, 63
485 %ashr = ashr i64 %shl, 63
487 %and = and i64 %ashr, %s.val
488 store i64 %and, i64 addrspace(1)* %out.gep, align 8
492 ; FUNC-LABEL: {{^}}v_sext_in_reg_i32_to_i64_move_use:
493 ; SI: buffer_load_dwordx2
494 ; SI: v_lshl_b64 v{{\[}}[[LO:[0-9]+]]:[[HI:[0-9]+]]{{\]}},
496 ; GFX89: {{flat|global}}_load_dwordx2
497 ; GFX89: v_lshlrev_b64 v{{\[}}[[LO:[0-9]+]]:[[HI:[0-9]+]]{{\]}},
499 ; GCN-DAG: v_ashrrev_i32_e32 v[[SHR:[0-9]+]], 31, v[[LO]]
500 ; GCN-DAG: v_and_b32_e32 v[[RESULT_LO:[0-9]+]], s{{[0-9]+}}, v[[LO]]
501 ; GCN-DAG: v_and_b32_e32 v[[RESULT_HI:[0-9]+]], s{{[0-9]+}}, v[[SHR]]
503 ; SI: buffer_store_dwordx2 v{{\[}}[[RESULT_LO]]:[[RESULT_HI]]{{\]}}
504 ; GFX89: {{flat|global}}_store_dwordx2 v{{\[[0-9]+:[0-9]+\]}}, v{{\[}}[[RESULT_LO]]:[[RESULT_HI]]{{\]}}
505 define amdgpu_kernel void @v_sext_in_reg_i32_to_i64_move_use(i64 addrspace(1)* %out, i64 addrspace(1)* %aptr, i64 addrspace(1)* %bptr, i64 %s.val) #0 {
506 %tid = call i32 @llvm.r600.read.tidig.x()
507 %a.gep = getelementptr i64, i64 addrspace(1)* %aptr, i32 %tid
508 %b.gep = getelementptr i64, i64 addrspace(1)* %aptr, i32 %tid
509 %out.gep = getelementptr i64, i64 addrspace(1)* %out, i32 %tid
510 %a = load i64, i64 addrspace(1)* %a.gep, align 8
511 %b = load i64, i64 addrspace(1)* %b.gep, align 8
514 %shl = shl i64 %c, 32
515 %ashr = ashr i64 %shl, 32
516 %and = and i64 %ashr, %s.val
517 store i64 %and, i64 addrspace(1)* %out.gep, align 8
521 ; FUNC-LABEL: {{^}}s_sext_in_reg_i1_i16:
522 ; GCN: s_load_dword [[VAL:s[0-9]+]]
524 ; SI: s_bfe_i32 [[BFE:s[0-9]+]], [[VAL]], 0x10000
525 ; SI: v_mov_b32_e32 [[VBFE:v[0-9]+]], [[BFE]]
526 ; SI: buffer_store_short [[VBFE]]
528 ; GFX89: s_lshl_b32 s{{[0-9]+}}, s{{[0-9]+}}, 15
529 ; GFX89: s_sext_i32_i16 s{{[0-9]+}}, s{{[0-9]+}}
530 ; GFX89: s_lshr_b32 s{{[0-9]+}}, s{{[0-9]+}}, 15
531 define amdgpu_kernel void @s_sext_in_reg_i1_i16(i16 addrspace(1)* %out, i32 addrspace(4)* %ptr) #0 {
532 %ld = load i32, i32 addrspace(4)* %ptr
533 %in = trunc i32 %ld to i16
534 %shl = shl i16 %in, 15
535 %sext = ashr i16 %shl, 15
536 store i16 %sext, i16 addrspace(1)* %out
540 ; FUNC-LABEL: {{^}}s_sext_in_reg_i2_i16:
541 ; GCN: s_load_dword [[VAL:s[0-9]+]]
543 ; SI: s_bfe_i32 [[BFE:s[0-9]+]], [[VAL]], 0x20000
544 ; SI: v_mov_b32_e32 [[VBFE:v[0-9]+]], [[BFE]]
545 ; SI: buffer_store_short [[VBFE]]
547 ; GFX89: s_lshl_b32 s{{[0-9]+}}, s{{[0-9]+}}, 14
548 ; GFX89: s_sext_i32_i16 s{{[0-9]+}}, s{{[0-9]+}}
549 ; GFX89: s_lshr_b32 s{{[0-9]+}}, s{{[0-9]+}}, 14
550 define amdgpu_kernel void @s_sext_in_reg_i2_i16(i16 addrspace(1)* %out, i32 addrspace(4)* %ptr) #0 {
551 %ld = load i32, i32 addrspace(4)* %ptr
552 %in = trunc i32 %ld to i16
553 %shl = shl i16 %in, 14
554 %sext = ashr i16 %shl, 14
555 store i16 %sext, i16 addrspace(1)* %out
559 ; FUNC-LABEL: {{^}}v_sext_in_reg_i1_i16:
560 ; GCN: {{buffer|flat|global}}_load_ushort [[VAL:v[0-9]+]]
561 ; GCN: v_bfe_i32 [[BFE:v[0-9]+]], [[VAL]], 0, 1{{$}}
563 ; GCN: ds_write_b16 v{{[0-9]+}}, [[BFE]]
564 define amdgpu_kernel void @v_sext_in_reg_i1_i16(i16 addrspace(3)* %out, i16 addrspace(1)* %ptr) #0 {
565 %tid = call i32 @llvm.r600.read.tidig.x()
566 %gep = getelementptr i16, i16 addrspace(1)* %ptr, i32 %tid
567 %out.gep = getelementptr i16, i16 addrspace(3)* %out, i32 %tid
569 %in = load i16, i16 addrspace(1)* %gep
570 %shl = shl i16 %in, 15
571 %sext = ashr i16 %shl, 15
572 store i16 %sext, i16 addrspace(3)* %out.gep
576 ; FUNC-LABEL: {{^}}v_sext_in_reg_i1_i16_nonload:
577 ; GCN: {{buffer|flat|global}}_load_ushort [[VAL0:v[0-9]+]]
578 ; GCN: {{buffer|flat|global}}_load_ushort [[VAL1:v[0-9]+]]
580 ; SI: v_lshlrev_b32_e32 [[REG:v[0-9]+]], [[VAL1]], [[VAL0]]
581 ; GFX89: v_lshlrev_b16_e32 [[REG:v[0-9]+]], [[VAL1]], [[VAL0]]
583 ; GCN: v_bfe_i32 [[BFE:v[0-9]+]], [[REG]], 0, 1{{$}}
584 ; GCN: ds_write_b16 v{{[0-9]+}}, [[BFE]]
585 define amdgpu_kernel void @v_sext_in_reg_i1_i16_nonload(i16 addrspace(3)* %out, i16 addrspace(1)* %aptr, i16 addrspace(1)* %bptr, i16 %s.val) nounwind {
586 %tid = call i32 @llvm.r600.read.tidig.x()
587 %a.gep = getelementptr i16, i16 addrspace(1)* %aptr, i32 %tid
588 %b.gep = getelementptr i16, i16 addrspace(1)* %bptr, i32 %tid
589 %out.gep = getelementptr i16, i16 addrspace(3)* %out, i32 %tid
590 %a = load volatile i16, i16 addrspace(1)* %a.gep, align 2
591 %b = load volatile i16, i16 addrspace(1)* %b.gep, align 2
594 %shl = shl i16 %c, 15
595 %ashr = ashr i16 %shl, 15
597 store i16 %ashr, i16 addrspace(3)* %out.gep, align 2
601 ; FUNC-LABEL: {{^}}s_sext_in_reg_i2_i16_arg:
602 ; GCN: s_load_dword [[VAL:s[0-9]+]]
604 ; SI: s_bfe_i32 [[BFE:s[0-9]+]], [[VAL]], 0x20000
605 ; SI: v_mov_b32_e32 [[VBFE:v[0-9]+]], [[BFE]]
606 ; SI: buffer_store_short [[VBFE]]
608 ; GFX89: s_lshl_b32 s{{[0-9]+}}, s{{[0-9]+}}, 14{{$}}
609 ; GFX89: s_sext_i32_i16 s{{[0-9]+}}, s{{[0-9]+}}
610 ; GFX89: s_lshr_b32 s{{[0-9]+}}, s{{[0-9]+}}, 14{{$}}
611 define amdgpu_kernel void @s_sext_in_reg_i2_i16_arg(i16 addrspace(1)* %out, i16 %in) #0 {
612 %shl = shl i16 %in, 14
613 %sext = ashr i16 %shl, 14
614 store i16 %sext, i16 addrspace(1)* %out
618 ; FUNC-LABEL: {{^}}s_sext_in_reg_i8_i16_arg:
619 ; GCN: s_load_dword [[VAL:s[0-9]+]]
621 ; SI: s_sext_i32_i8 [[SSEXT:s[0-9]+]], [[VAL]]
622 ; SI: v_mov_b32_e32 [[VSEXT:v[0-9]+]], [[SSEXT]]
623 ; SI: buffer_store_short [[VSEXT]]
625 ; GFX89: s_lshl_b32 s{{[0-9]+}}, s{{[0-9]+}}, 8{{$}}
626 ; GFX89: s_sext_i32_i16 s{{[0-9]+}}, s{{[0-9]+}}
627 ; GFX89: s_lshr_b32 s{{[0-9]+}}, s{{[0-9]+}}, 8{{$}}
628 define amdgpu_kernel void @s_sext_in_reg_i8_i16_arg(i16 addrspace(1)* %out, i16 %in) #0 {
629 %shl = shl i16 %in, 8
630 %sext = ashr i16 %shl, 8
631 store i16 %sext, i16 addrspace(1)* %out
635 ; FUNC-LABEL: {{^}}s_sext_in_reg_i15_i16_arg:
636 ; GCN: s_load_dword [[VAL:s[0-9]+]]
638 ; SI: s_bfe_i32 [[BFE:s[0-9]+]], [[VAL]], 0xf0000
639 ; SI: v_mov_b32_e32 [[VBFE:v[0-9]+]], [[BFE]]
640 ; SI: buffer_store_short [[VBFE]]
642 ; GFX89: s_lshl_b32 s{{[0-9]+}}, s{{[0-9]+}}, 1{{$}}
643 ; GFX89: s_sext_i32_i16 s{{[0-9]+}}, s{{[0-9]+}}
644 ; GFX89: s_lshr_b32 s{{[0-9]+}}, s{{[0-9]+}}, 1{{$}}
645 define amdgpu_kernel void @s_sext_in_reg_i15_i16_arg(i16 addrspace(1)* %out, i16 %in) #0 {
646 %shl = shl i16 %in, 1
647 %sext = ashr i16 %shl, 1
648 store i16 %sext, i16 addrspace(1)* %out
652 ; FUNC-LABEL: {{^}}sext_in_reg_v2i1_to_v2i16:
653 ; GFX9: v_pk_add_u16 [[ADD:v[0-9]+]]
654 ; GFX9: v_pk_lshlrev_b16 [[SHL:v[0-9]+]], 15, [[ADD]]
655 ; GFX9: v_pk_ashrrev_i16 [[SRA:v[0-9]+]], 15, [[SHL]]
656 define amdgpu_kernel void @sext_in_reg_v2i1_to_v2i16(<2 x i16> addrspace(1)* %out, <2 x i16> %a, <2 x i16> %b) #0 {
657 %c = add <2 x i16> %a, %b ; add to prevent folding into extload
658 %shl = shl <2 x i16> %c, <i16 15, i16 15>
659 %ashr = ashr <2 x i16> %shl, <i16 15, i16 15>
660 store <2 x i16> %ashr, <2 x i16> addrspace(1)* %out
664 ; FUNC-LABEL: {{^}}sext_in_reg_v3i1_to_v3i16:
667 ; GFX9: v_pk_lshlrev_b16 v{{[0-9]+}}, 15, v{{[0-9]+}}
668 ; GFX9: v_pk_lshlrev_b16 v{{[0-9]+}}, 15, v{{[0-9]+}}
669 ; GFX9: v_pk_ashrrev_i16 v{{[0-9]+}}, 15, v{{[0-9]+}}
670 ; GFX9: v_pk_ashrrev_i16 v{{[0-9]+}}, 15, v{{[0-9]+}}
671 define amdgpu_kernel void @sext_in_reg_v3i1_to_v3i16(<3 x i16> addrspace(1)* %out, <3 x i16> %a, <3 x i16> %b) #0 {
672 %c = add <3 x i16> %a, %b ; add to prevent folding into extload
673 %shl = shl <3 x i16> %c, <i16 15, i16 15, i16 15>
674 %ashr = ashr <3 x i16> %shl, <i16 15, i16 15, i16 15>
675 store <3 x i16> %ashr, <3 x i16> addrspace(1)* %out
679 ; FUNC-LABEL: {{^}}sext_in_reg_v2i2_to_v2i16:
680 ; GFX9: v_pk_add_u16 [[ADD:v[0-9]+]]
681 ; GFX9: v_pk_lshlrev_b16 [[SHL:v[0-9]+]], 14, [[ADD]]
682 ; GFX9: v_pk_ashrrev_i16 [[SRA:v[0-9]+]], 14, [[SHL]]
683 define amdgpu_kernel void @sext_in_reg_v2i2_to_v2i16(<2 x i16> addrspace(1)* %out, <2 x i16> %a, <2 x i16> %b) #0 {
684 %c = add <2 x i16> %a, %b ; add to prevent folding into extload
685 %shl = shl <2 x i16> %c, <i16 14, i16 14>
686 %ashr = ashr <2 x i16> %shl, <i16 14, i16 14>
687 store <2 x i16> %ashr, <2 x i16> addrspace(1)* %out
691 ; FUNC-LABEL: {{^}}sext_in_reg_v2i8_to_v2i16:
692 ; GFX9: v_pk_add_u16 [[ADD:v[0-9]+]]
693 ; GFX9: v_pk_lshlrev_b16 [[SHL:v[0-9]+]], 8, [[ADD]]
694 ; GFX9: v_pk_ashrrev_i16 [[SRA:v[0-9]+]], 8, [[SHL]]
695 define amdgpu_kernel void @sext_in_reg_v2i8_to_v2i16(<2 x i16> addrspace(1)* %out, <2 x i16> %a, <2 x i16> %b) #0 {
696 %c = add <2 x i16> %a, %b ; add to prevent folding into extload
697 %shl = shl <2 x i16> %c, <i16 8, i16 8>
698 %ashr = ashr <2 x i16> %shl, <i16 8, i16 8>
699 store <2 x i16> %ashr, <2 x i16> addrspace(1)* %out
703 ; FUNC-LABEL: {{^}}sext_in_reg_v3i8_to_v3i16:
706 ; GFX9: v_pk_lshlrev_b16 v{{[0-9]+}}, 8, v{{[0-9]+}}
707 ; GFX9: v_pk_lshlrev_b16 v{{[0-9]+}}, 8, v{{[0-9]+}}
708 ; GFX9: v_pk_ashrrev_i16 v{{[0-9]+}}, 8, v{{[0-9]+}}
709 ; GFX9: v_pk_ashrrev_i16 v{{[0-9]+}}, 8, v{{[0-9]+}}
710 define amdgpu_kernel void @sext_in_reg_v3i8_to_v3i16(<3 x i16> addrspace(1)* %out, <3 x i16> %a, <3 x i16> %b) #0 {
711 %c = add <3 x i16> %a, %b ; add to prevent folding into extload
712 %shl = shl <3 x i16> %c, <i16 8, i16 8, i16 8>
713 %ashr = ashr <3 x i16> %shl, <i16 8, i16 8, i16 8>
714 store <3 x i16> %ashr, <3 x i16> addrspace(1)* %out
718 declare i32 @llvm.r600.read.tidig.x() #1
720 attributes #0 = { nounwind }
721 attributes #1 = { nounwind readnone }