1 ; RUN: llc -amdgpu-scalarize-global-loads=false -march=amdgcn -verify-machineinstrs < %s | FileCheck -check-prefix=GCN -check-prefix=SI %s
2 ; RUN: llc -amdgpu-scalarize-global-loads=false -march=amdgcn -mcpu=tonga -mattr=-flat-for-global -verify-machineinstrs < %s | FileCheck -check-prefix=GCN -check-prefix=VI %s
4 ; GCN-LABEL: {{^}}bfe_i32_arg_arg_arg:
6 define amdgpu_kernel void @bfe_i32_arg_arg_arg(i32 addrspace(1)* %out, i32 %src0, i32 %src1, i32 %src2) #0 {
7 %bfe_i32 = call i32 @llvm.amdgcn.sbfe.i32(i32 %src0, i32 %src1, i32 %src1)
8 store i32 %bfe_i32, i32 addrspace(1)* %out, align 4
12 ; GCN-LABEL: {{^}}bfe_i32_arg_arg_imm:
14 define amdgpu_kernel void @bfe_i32_arg_arg_imm(i32 addrspace(1)* %out, i32 %src0, i32 %src1) #0 {
15 %bfe_i32 = call i32 @llvm.amdgcn.sbfe.i32(i32 %src0, i32 %src1, i32 123)
16 store i32 %bfe_i32, i32 addrspace(1)* %out, align 4
20 ; GCN-LABEL: {{^}}bfe_i32_arg_imm_arg:
22 define amdgpu_kernel void @bfe_i32_arg_imm_arg(i32 addrspace(1)* %out, i32 %src0, i32 %src2) #0 {
23 %bfe_i32 = call i32 @llvm.amdgcn.sbfe.i32(i32 %src0, i32 123, i32 %src2)
24 store i32 %bfe_i32, i32 addrspace(1)* %out, align 4
28 ; GCN-LABEL: {{^}}bfe_i32_imm_arg_arg:
30 define amdgpu_kernel void @bfe_i32_imm_arg_arg(i32 addrspace(1)* %out, i32 %src1, i32 %src2) #0 {
31 %bfe_i32 = call i32 @llvm.amdgcn.sbfe.i32(i32 123, i32 %src1, i32 %src2)
32 store i32 %bfe_i32, i32 addrspace(1)* %out, align 4
36 ; GCN-LABEL: {{^}}v_bfe_print_arg:
37 ; GCN: v_bfe_i32 v{{[0-9]+}}, v{{[0-9]+}}, 2, 8
38 define amdgpu_kernel void @v_bfe_print_arg(i32 addrspace(1)* %out, i32 addrspace(1)* %src0) #0 {
39 %load = load i32, i32 addrspace(1)* %src0, align 4
40 %bfe_i32 = call i32 @llvm.amdgcn.sbfe.i32(i32 %load, i32 2, i32 8)
41 store i32 %bfe_i32, i32 addrspace(1)* %out, align 4
45 ; GCN-LABEL: {{^}}bfe_i32_arg_0_width_reg_offset:
46 ; GCN-NOT: {{[^@]}}bfe
48 define amdgpu_kernel void @bfe_i32_arg_0_width_reg_offset(i32 addrspace(1)* %out, i32 %src0, i32 %src1) #0 {
49 %bfe_u32 = call i32 @llvm.amdgcn.sbfe.i32(i32 %src0, i32 %src1, i32 0)
50 store i32 %bfe_u32, i32 addrspace(1)* %out, align 4
54 ; GCN-LABEL: {{^}}bfe_i32_arg_0_width_imm_offset:
55 ; GCN-NOT: {{[^@]}}bfe
57 define amdgpu_kernel void @bfe_i32_arg_0_width_imm_offset(i32 addrspace(1)* %out, i32 %src0, i32 %src1) #0 {
58 %bfe_u32 = call i32 @llvm.amdgcn.sbfe.i32(i32 %src0, i32 8, i32 0)
59 store i32 %bfe_u32, i32 addrspace(1)* %out, align 4
63 ; GCN-LABEL: {{^}}bfe_i32_test_6:
64 ; GCN: v_lshlrev_b32_e32 v{{[0-9]+}}, 31, v{{[0-9]+}}
65 ; GCN: v_ashrrev_i32_e32 v{{[0-9]+}}, 1, v{{[0-9]+}}
67 define amdgpu_kernel void @bfe_i32_test_6(i32 addrspace(1)* %out, i32 addrspace(1)* %in) #0 {
68 %x = load i32, i32 addrspace(1)* %in, align 4
70 %bfe = call i32 @llvm.amdgcn.sbfe.i32(i32 %shl, i32 1, i32 31)
71 store i32 %bfe, i32 addrspace(1)* %out, align 4
75 ; GCN-LABEL: {{^}}bfe_i32_test_7:
77 ; GCN-NOT: {{[^@]}}bfe
78 ; GCN: v_mov_b32_e32 [[VREG:v[0-9]+]], 0
79 ; GCN: buffer_store_dword [[VREG]],
81 define amdgpu_kernel void @bfe_i32_test_7(i32 addrspace(1)* %out, i32 addrspace(1)* %in) #0 {
82 %x = load i32, i32 addrspace(1)* %in, align 4
84 %bfe = call i32 @llvm.amdgcn.sbfe.i32(i32 %shl, i32 0, i32 31)
85 store i32 %bfe, i32 addrspace(1)* %out, align 4
89 ; GCN-LABEL: {{^}}bfe_i32_test_8:
90 ; GCN: buffer_load_dword
91 ; GCN: v_bfe_i32 v{{[0-9]+}}, v{{[0-9]+}}, 0, 1
93 define amdgpu_kernel void @bfe_i32_test_8(i32 addrspace(1)* %out, i32 addrspace(1)* %in) #0 {
94 %x = load i32, i32 addrspace(1)* %in, align 4
96 %bfe = call i32 @llvm.amdgcn.sbfe.i32(i32 %shl, i32 31, i32 1)
97 store i32 %bfe, i32 addrspace(1)* %out, align 4
101 ; GCN-LABEL: {{^}}bfe_i32_test_9:
102 ; GCN-NOT: {{[^@]}}bfe
103 ; GCN: v_ashrrev_i32_e32 v{{[0-9]+}}, 31, v{{[0-9]+}}
104 ; GCN-NOT: {{[^@]}}bfe
106 define amdgpu_kernel void @bfe_i32_test_9(i32 addrspace(1)* %out, i32 addrspace(1)* %in) #0 {
107 %x = load i32, i32 addrspace(1)* %in, align 4
108 %bfe = call i32 @llvm.amdgcn.sbfe.i32(i32 %x, i32 31, i32 1)
109 store i32 %bfe, i32 addrspace(1)* %out, align 4
113 ; GCN-LABEL: {{^}}bfe_i32_test_10:
114 ; GCN-NOT: {{[^@]}}bfe
115 ; GCN: v_ashrrev_i32_e32 v{{[0-9]+}}, 1, v{{[0-9]+}}
116 ; GCN-NOT: {{[^@]}}bfe
118 define amdgpu_kernel void @bfe_i32_test_10(i32 addrspace(1)* %out, i32 addrspace(1)* %in) #0 {
119 %x = load i32, i32 addrspace(1)* %in, align 4
120 %bfe = call i32 @llvm.amdgcn.sbfe.i32(i32 %x, i32 1, i32 31)
121 store i32 %bfe, i32 addrspace(1)* %out, align 4
125 ; GCN-LABEL: {{^}}bfe_i32_test_11:
126 ; GCN-NOT: {{[^@]}}bfe
127 ; GCN: v_ashrrev_i32_e32 v{{[0-9]+}}, 8, v{{[0-9]+}}
128 ; GCN-NOT: {{[^@]}}bfe
130 define amdgpu_kernel void @bfe_i32_test_11(i32 addrspace(1)* %out, i32 addrspace(1)* %in) #0 {
131 %x = load i32, i32 addrspace(1)* %in, align 4
132 %bfe = call i32 @llvm.amdgcn.sbfe.i32(i32 %x, i32 8, i32 24)
133 store i32 %bfe, i32 addrspace(1)* %out, align 4
137 ; GCN-LABEL: {{^}}bfe_i32_test_12:
138 ; GCN-NOT: {{[^@]}}bfe
139 ; GCN: v_ashrrev_i32_e32 v{{[0-9]+}}, 24, v{{[0-9]+}}
140 ; GCN-NOT: {{[^@]}}bfe
142 define amdgpu_kernel void @bfe_i32_test_12(i32 addrspace(1)* %out, i32 addrspace(1)* %in) #0 {
143 %x = load i32, i32 addrspace(1)* %in, align 4
144 %bfe = call i32 @llvm.amdgcn.sbfe.i32(i32 %x, i32 24, i32 8)
145 store i32 %bfe, i32 addrspace(1)* %out, align 4
149 ; GCN-LABEL: {{^}}bfe_i32_test_13:
150 ; GCN: v_ashrrev_i32_e32 {{v[0-9]+}}, 31, {{v[0-9]+}}
151 ; GCN-NOT: {{[^@]}}bfe
153 define amdgpu_kernel void @bfe_i32_test_13(i32 addrspace(1)* %out, i32 addrspace(1)* %in) #0 {
154 %x = load i32, i32 addrspace(1)* %in, align 4
155 %shl = ashr i32 %x, 31
156 %bfe = call i32 @llvm.amdgcn.sbfe.i32(i32 %shl, i32 31, i32 1)
157 store i32 %bfe, i32 addrspace(1)* %out, align 4 ret void
160 ; GCN-LABEL: {{^}}bfe_i32_test_14:
162 ; GCN-NOT: {{[^@]}}bfe
164 define amdgpu_kernel void @bfe_i32_test_14(i32 addrspace(1)* %out, i32 addrspace(1)* %in) #0 {
165 %x = load i32, i32 addrspace(1)* %in, align 4
166 %shl = lshr i32 %x, 31
167 %bfe = call i32 @llvm.amdgcn.sbfe.i32(i32 %shl, i32 31, i32 1)
168 store i32 %bfe, i32 addrspace(1)* %out, align 4 ret void
171 ; GCN-LABEL: {{^}}bfe_i32_constant_fold_test_0:
172 ; GCN-NOT: {{[^@]}}bfe
173 ; GCN: v_mov_b32_e32 [[VREG:v[0-9]+]], 0
174 ; GCN: buffer_store_dword [[VREG]],
176 define amdgpu_kernel void @bfe_i32_constant_fold_test_0(i32 addrspace(1)* %out) #0 {
177 %bfe_i32 = call i32 @llvm.amdgcn.sbfe.i32(i32 0, i32 0, i32 0)
178 store i32 %bfe_i32, i32 addrspace(1)* %out, align 4
182 ; GCN-LABEL: {{^}}bfe_i32_constant_fold_test_1:
183 ; GCN-NOT: {{[^@]}}bfe
184 ; GCN: v_mov_b32_e32 [[VREG:v[0-9]+]], 0
185 ; GCN: buffer_store_dword [[VREG]],
187 define amdgpu_kernel void @bfe_i32_constant_fold_test_1(i32 addrspace(1)* %out) #0 {
188 %bfe_i32 = call i32 @llvm.amdgcn.sbfe.i32(i32 12334, i32 0, i32 0)
189 store i32 %bfe_i32, i32 addrspace(1)* %out, align 4
193 ; GCN-LABEL: {{^}}bfe_i32_constant_fold_test_2:
194 ; GCN-NOT: {{[^@]}}bfe
195 ; GCN: v_mov_b32_e32 [[VREG:v[0-9]+]], 0
196 ; GCN: buffer_store_dword [[VREG]],
198 define amdgpu_kernel void @bfe_i32_constant_fold_test_2(i32 addrspace(1)* %out) #0 {
199 %bfe_i32 = call i32 @llvm.amdgcn.sbfe.i32(i32 0, i32 0, i32 1)
200 store i32 %bfe_i32, i32 addrspace(1)* %out, align 4
204 ; GCN-LABEL: {{^}}bfe_i32_constant_fold_test_3:
205 ; GCN-NOT: {{[^@]}}bfe
206 ; GCN: v_mov_b32_e32 [[VREG:v[0-9]+]], -1
207 ; GCN: buffer_store_dword [[VREG]],
209 define amdgpu_kernel void @bfe_i32_constant_fold_test_3(i32 addrspace(1)* %out) #0 {
210 %bfe_i32 = call i32 @llvm.amdgcn.sbfe.i32(i32 1, i32 0, i32 1)
211 store i32 %bfe_i32, i32 addrspace(1)* %out, align 4
215 ; GCN-LABEL: {{^}}bfe_i32_constant_fold_test_4:
216 ; GCN-NOT: {{[^@]}}bfe
217 ; GCN: v_mov_b32_e32 [[VREG:v[0-9]+]], -1
218 ; GCN: buffer_store_dword [[VREG]],
220 define amdgpu_kernel void @bfe_i32_constant_fold_test_4(i32 addrspace(1)* %out) #0 {
221 %bfe_i32 = call i32 @llvm.amdgcn.sbfe.i32(i32 4294967295, i32 0, i32 1)
222 store i32 %bfe_i32, i32 addrspace(1)* %out, align 4
226 ; GCN-LABEL: {{^}}bfe_i32_constant_fold_test_5:
227 ; GCN-NOT: {{[^@]}}bfe
228 ; GCN: v_mov_b32_e32 [[VREG:v[0-9]+]], -1
229 ; GCN: buffer_store_dword [[VREG]],
231 define amdgpu_kernel void @bfe_i32_constant_fold_test_5(i32 addrspace(1)* %out) #0 {
232 %bfe_i32 = call i32 @llvm.amdgcn.sbfe.i32(i32 128, i32 7, i32 1)
233 store i32 %bfe_i32, i32 addrspace(1)* %out, align 4
237 ; GCN-LABEL: {{^}}bfe_i32_constant_fold_test_6:
238 ; GCN-NOT: {{[^@]}}bfe
239 ; GCN: v_mov_b32_e32 [[VREG:v[0-9]+]], 0xffffff80
240 ; GCN: buffer_store_dword [[VREG]],
242 define amdgpu_kernel void @bfe_i32_constant_fold_test_6(i32 addrspace(1)* %out) #0 {
243 %bfe_i32 = call i32 @llvm.amdgcn.sbfe.i32(i32 128, i32 0, i32 8)
244 store i32 %bfe_i32, i32 addrspace(1)* %out, align 4
248 ; GCN-LABEL: {{^}}bfe_i32_constant_fold_test_7:
249 ; GCN-NOT: {{[^@]}}bfe
250 ; GCN: v_mov_b32_e32 [[VREG:v[0-9]+]], 0x7f
251 ; GCN: buffer_store_dword [[VREG]],
253 define amdgpu_kernel void @bfe_i32_constant_fold_test_7(i32 addrspace(1)* %out) #0 {
254 %bfe_i32 = call i32 @llvm.amdgcn.sbfe.i32(i32 127, i32 0, i32 8)
255 store i32 %bfe_i32, i32 addrspace(1)* %out, align 4
259 ; GCN-LABEL: {{^}}bfe_i32_constant_fold_test_8:
260 ; GCN-NOT: {{[^@]}}bfe
261 ; GCN: v_mov_b32_e32 [[VREG:v[0-9]+]], 1
262 ; GCN: buffer_store_dword [[VREG]],
264 define amdgpu_kernel void @bfe_i32_constant_fold_test_8(i32 addrspace(1)* %out) #0 {
265 %bfe_i32 = call i32 @llvm.amdgcn.sbfe.i32(i32 127, i32 6, i32 8)
266 store i32 %bfe_i32, i32 addrspace(1)* %out, align 4
270 ; GCN-LABEL: {{^}}bfe_i32_constant_fold_test_9:
271 ; GCN-NOT: {{[^@]}}bfe
272 ; GCN: v_mov_b32_e32 [[VREG:v[0-9]+]], 1
273 ; GCN: buffer_store_dword [[VREG]],
275 define amdgpu_kernel void @bfe_i32_constant_fold_test_9(i32 addrspace(1)* %out) #0 {
276 %bfe_i32 = call i32 @llvm.amdgcn.sbfe.i32(i32 65536, i32 16, i32 8)
277 store i32 %bfe_i32, i32 addrspace(1)* %out, align 4
281 ; GCN-LABEL: {{^}}bfe_i32_constant_fold_test_10:
282 ; GCN-NOT: {{[^@]}}bfe
283 ; GCN: v_mov_b32_e32 [[VREG:v[0-9]+]], 0
284 ; GCN: buffer_store_dword [[VREG]],
286 define amdgpu_kernel void @bfe_i32_constant_fold_test_10(i32 addrspace(1)* %out) #0 {
287 %bfe_i32 = call i32 @llvm.amdgcn.sbfe.i32(i32 65535, i32 16, i32 16)
288 store i32 %bfe_i32, i32 addrspace(1)* %out, align 4
292 ; GCN-LABEL: {{^}}bfe_i32_constant_fold_test_11:
293 ; GCN-NOT: {{[^@]}}bfe
294 ; GCN: v_mov_b32_e32 [[VREG:v[0-9]+]], -6
295 ; GCN: buffer_store_dword [[VREG]],
297 define amdgpu_kernel void @bfe_i32_constant_fold_test_11(i32 addrspace(1)* %out) #0 {
298 %bfe_i32 = call i32 @llvm.amdgcn.sbfe.i32(i32 160, i32 4, i32 4)
299 store i32 %bfe_i32, i32 addrspace(1)* %out, align 4
303 ; GCN-LABEL: {{^}}bfe_i32_constant_fold_test_12:
304 ; GCN-NOT: {{[^@]}}bfe
305 ; GCN: v_mov_b32_e32 [[VREG:v[0-9]+]], 0
306 ; GCN: buffer_store_dword [[VREG]],
308 define amdgpu_kernel void @bfe_i32_constant_fold_test_12(i32 addrspace(1)* %out) #0 {
309 %bfe_i32 = call i32 @llvm.amdgcn.sbfe.i32(i32 160, i32 31, i32 1)
310 store i32 %bfe_i32, i32 addrspace(1)* %out, align 4
314 ; GCN-LABEL: {{^}}bfe_i32_constant_fold_test_13:
315 ; GCN-NOT: {{[^@]}}bfe
316 ; GCN: v_mov_b32_e32 [[VREG:v[0-9]+]], 1
317 ; GCN: buffer_store_dword [[VREG]],
319 define amdgpu_kernel void @bfe_i32_constant_fold_test_13(i32 addrspace(1)* %out) #0 {
320 %bfe_i32 = call i32 @llvm.amdgcn.sbfe.i32(i32 131070, i32 16, i32 16)
321 store i32 %bfe_i32, i32 addrspace(1)* %out, align 4
325 ; GCN-LABEL: {{^}}bfe_i32_constant_fold_test_14:
326 ; GCN-NOT: {{[^@]}}bfe
327 ; GCN: v_mov_b32_e32 [[VREG:v[0-9]+]], 40
328 ; GCN: buffer_store_dword [[VREG]],
330 define amdgpu_kernel void @bfe_i32_constant_fold_test_14(i32 addrspace(1)* %out) #0 {
331 %bfe_i32 = call i32 @llvm.amdgcn.sbfe.i32(i32 160, i32 2, i32 30)
332 store i32 %bfe_i32, i32 addrspace(1)* %out, align 4
336 ; GCN-LABEL: {{^}}bfe_i32_constant_fold_test_15:
337 ; GCN-NOT: {{[^@]}}bfe
338 ; GCN: v_mov_b32_e32 [[VREG:v[0-9]+]], 10
339 ; GCN: buffer_store_dword [[VREG]],
341 define amdgpu_kernel void @bfe_i32_constant_fold_test_15(i32 addrspace(1)* %out) #0 {
342 %bfe_i32 = call i32 @llvm.amdgcn.sbfe.i32(i32 160, i32 4, i32 28)
343 store i32 %bfe_i32, i32 addrspace(1)* %out, align 4
347 ; GCN-LABEL: {{^}}bfe_i32_constant_fold_test_16:
348 ; GCN-NOT: {{[^@]}}bfe
349 ; GCN: v_mov_b32_e32 [[VREG:v[0-9]+]], -1
350 ; GCN: buffer_store_dword [[VREG]],
352 define amdgpu_kernel void @bfe_i32_constant_fold_test_16(i32 addrspace(1)* %out) #0 {
353 %bfe_i32 = call i32 @llvm.amdgcn.sbfe.i32(i32 4294967295, i32 1, i32 7)
354 store i32 %bfe_i32, i32 addrspace(1)* %out, align 4
358 ; GCN-LABEL: {{^}}bfe_i32_constant_fold_test_17:
359 ; GCN-NOT: {{[^@]}}bfe
360 ; GCN: v_mov_b32_e32 [[VREG:v[0-9]+]], 0x7f
361 ; GCN: buffer_store_dword [[VREG]],
363 define amdgpu_kernel void @bfe_i32_constant_fold_test_17(i32 addrspace(1)* %out) #0 {
364 %bfe_i32 = call i32 @llvm.amdgcn.sbfe.i32(i32 255, i32 1, i32 31)
365 store i32 %bfe_i32, i32 addrspace(1)* %out, align 4
369 ; GCN-LABEL: {{^}}bfe_i32_constant_fold_test_18:
370 ; GCN-NOT: {{[^@]}}bfe
371 ; GCN: v_mov_b32_e32 [[VREG:v[0-9]+]], 0
372 ; GCN: buffer_store_dword [[VREG]],
374 define amdgpu_kernel void @bfe_i32_constant_fold_test_18(i32 addrspace(1)* %out) #0 {
375 %bfe_i32 = call i32 @llvm.amdgcn.sbfe.i32(i32 255, i32 31, i32 1)
376 store i32 %bfe_i32, i32 addrspace(1)* %out, align 4
380 ; GCN-LABEL: {{^}}bfe_sext_in_reg_i24:
381 ; GCN: buffer_load_dword [[LOAD:v[0-9]+]],
384 ; GCN: v_bfe_i32 [[BFE:v[0-9]+]], [[LOAD]], 0, 24
385 ; GCN: buffer_store_dword [[BFE]],
386 define amdgpu_kernel void @bfe_sext_in_reg_i24(i32 addrspace(1)* %out, i32 addrspace(1)* %in) #0 {
387 %x = load i32, i32 addrspace(1)* %in, align 4
388 %bfe = call i32 @llvm.amdgcn.sbfe.i32(i32 %x, i32 0, i32 24)
389 %shl = shl i32 %bfe, 8
390 %ashr = ashr i32 %shl, 8
391 store i32 %ashr, i32 addrspace(1)* %out, align 4
395 ; GCN-LABEL: @simplify_demanded_bfe_sdiv
396 ; GCN: buffer_load_dword [[LOAD:v[0-9]+]]
397 ; GCN: v_bfe_i32 [[BFE:v[0-9]+]], [[LOAD]], 1, 16
398 ; GCN: v_lshrrev_b32_e32 [[TMP0:v[0-9]+]], 31, [[BFE]]
399 ; GCN: v_add_{{[iu]}}32_e32 [[TMP1:v[0-9]+]], vcc, [[TMP0]], [[BFE]]
400 ; GCN: v_ashrrev_i32_e32 [[TMP2:v[0-9]+]], 1, [[TMP1]]
401 ; GCN: buffer_store_dword [[TMP2]]
402 define amdgpu_kernel void @simplify_demanded_bfe_sdiv(i32 addrspace(1)* %out, i32 addrspace(1)* %in) #0 {
403 %src = load i32, i32 addrspace(1)* %in, align 4
404 %bfe = call i32 @llvm.amdgcn.sbfe.i32(i32 %src, i32 1, i32 16)
405 %div = sdiv i32 %bfe, 2
406 store i32 %div, i32 addrspace(1)* %out, align 4
410 ; GCN-LABEL: {{^}}bfe_0_width:
411 ; GCN-NOT: {{[^@]}}bfe
413 define amdgpu_kernel void @bfe_0_width(i32 addrspace(1)* %out, i32 addrspace(1)* %ptr) #0 {
414 %load = load i32, i32 addrspace(1)* %ptr, align 4
415 %bfe = call i32 @llvm.amdgcn.sbfe.i32(i32 %load, i32 8, i32 0)
416 store i32 %bfe, i32 addrspace(1)* %out, align 4
420 ; GCN-LABEL: {{^}}bfe_8_bfe_8:
422 ; GCN-NOT: {{[^@]}}bfe
424 define amdgpu_kernel void @bfe_8_bfe_8(i32 addrspace(1)* %out, i32 addrspace(1)* %ptr) #0 {
425 %load = load i32, i32 addrspace(1)* %ptr, align 4
426 %bfe0 = call i32 @llvm.amdgcn.sbfe.i32(i32 %load, i32 0, i32 8)
427 %bfe1 = call i32 @llvm.amdgcn.sbfe.i32(i32 %bfe0, i32 0, i32 8)
428 store i32 %bfe1, i32 addrspace(1)* %out, align 4
432 ; GCN-LABEL: {{^}}bfe_8_bfe_16:
433 ; GCN: v_bfe_i32 v{{[0-9]+}}, v{{[0-9]+}}, 0, 8
435 define amdgpu_kernel void @bfe_8_bfe_16(i32 addrspace(1)* %out, i32 addrspace(1)* %ptr) #0 {
436 %load = load i32, i32 addrspace(1)* %ptr, align 4
437 %bfe0 = call i32 @llvm.amdgcn.sbfe.i32(i32 %load, i32 0, i32 8)
438 %bfe1 = call i32 @llvm.amdgcn.sbfe.i32(i32 %bfe0, i32 0, i32 16)
439 store i32 %bfe1, i32 addrspace(1)* %out, align 4
443 ; This really should be folded into 1
444 ; GCN-LABEL: {{^}}bfe_16_bfe_8:
445 ; GCN: v_bfe_i32 v{{[0-9]+}}, v{{[0-9]+}}, 0, 8
446 ; GCN-NOT: {{[^@]}}bfe
448 define amdgpu_kernel void @bfe_16_bfe_8(i32 addrspace(1)* %out, i32 addrspace(1)* %ptr) #0 {
449 %load = load i32, i32 addrspace(1)* %ptr, align 4
450 %bfe0 = call i32 @llvm.amdgcn.sbfe.i32(i32 %load, i32 0, i32 16)
451 %bfe1 = call i32 @llvm.amdgcn.sbfe.i32(i32 %bfe0, i32 0, i32 8)
452 store i32 %bfe1, i32 addrspace(1)* %out, align 4
456 ; Make sure there isn't a redundant BFE
457 ; GCN-LABEL: {{^}}sext_in_reg_i8_to_i32_bfe:
458 ; GCN: s_sext_i32_i8 s{{[0-9]+}}, s{{[0-9]+}}
459 ; GCN-NOT: {{[^@]}}bfe
461 define amdgpu_kernel void @sext_in_reg_i8_to_i32_bfe(i32 addrspace(1)* %out, i32 %a, i32 %b) #0 {
462 %c = add i32 %a, %b ; add to prevent folding into extload
463 %bfe = call i32 @llvm.amdgcn.sbfe.i32(i32 %c, i32 0, i32 8)
464 %shl = shl i32 %bfe, 24
465 %ashr = ashr i32 %shl, 24
466 store i32 %ashr, i32 addrspace(1)* %out, align 4
470 ; GCN-LABEL: {{^}}sext_in_reg_i8_to_i32_bfe_wrong:
471 define amdgpu_kernel void @sext_in_reg_i8_to_i32_bfe_wrong(i32 addrspace(1)* %out, i32 %a, i32 %b) #0 {
472 %c = add i32 %a, %b ; add to prevent folding into extload
473 %bfe = call i32 @llvm.amdgcn.sbfe.i32(i32 %c, i32 8, i32 0)
474 %shl = shl i32 %bfe, 24
475 %ashr = ashr i32 %shl, 24
476 store i32 %ashr, i32 addrspace(1)* %out, align 4
480 ; GCN-LABEL: {{^}}sextload_i8_to_i32_bfe:
481 ; GCN: buffer_load_sbyte
482 ; GCN-NOT: {{[^@]}}bfe
484 define amdgpu_kernel void @sextload_i8_to_i32_bfe(i32 addrspace(1)* %out, i8 addrspace(1)* %ptr) #0 {
485 %load = load i8, i8 addrspace(1)* %ptr, align 1
486 %sext = sext i8 %load to i32
487 %bfe = call i32 @llvm.amdgcn.sbfe.i32(i32 %sext, i32 0, i32 8)
488 %shl = shl i32 %bfe, 24
489 %ashr = ashr i32 %shl, 24
490 store i32 %ashr, i32 addrspace(1)* %out, align 4
495 ; GCN-LABEL: {{^}}sextload_i8_to_i32_bfe_0:{{.*$}}
496 ; GCN-NOT: {{[^@]}}bfe
498 define amdgpu_kernel void @sextload_i8_to_i32_bfe_0(i32 addrspace(1)* %out, i8 addrspace(1)* %ptr) #0 {
499 %load = load i8, i8 addrspace(1)* %ptr, align 1
500 %sext = sext i8 %load to i32
501 %bfe = call i32 @llvm.amdgcn.sbfe.i32(i32 %sext, i32 8, i32 0)
502 %shl = shl i32 %bfe, 24
503 %ashr = ashr i32 %shl, 24
504 store i32 %ashr, i32 addrspace(1)* %out, align 4
508 ; GCN-LABEL: {{^}}sext_in_reg_i1_bfe_offset_0:
511 ; GCN: v_bfe_i32 v{{[0-9]+}}, v{{[0-9]+}}, 0, 1
513 define amdgpu_kernel void @sext_in_reg_i1_bfe_offset_0(i32 addrspace(1)* %out, i32 addrspace(1)* %in) #0 {
514 %x = load i32, i32 addrspace(1)* %in, align 4
515 %shl = shl i32 %x, 31
516 %shr = ashr i32 %shl, 31
517 %bfe = call i32 @llvm.amdgcn.sbfe.i32(i32 %shr, i32 0, i32 1)
518 store i32 %bfe, i32 addrspace(1)* %out, align 4
522 ; GCN-LABEL: {{^}}sext_in_reg_i1_bfe_offset_1:
523 ; GCN: buffer_load_dword
526 ; GCN: v_bfe_i32 v{{[0-9]+}}, v{{[0-9]+}}, 1, 1
528 define amdgpu_kernel void @sext_in_reg_i1_bfe_offset_1(i32 addrspace(1)* %out, i32 addrspace(1)* %in) #0 {
529 %x = load i32, i32 addrspace(1)* %in, align 4
530 %shl = shl i32 %x, 30
531 %shr = ashr i32 %shl, 30
532 %bfe = call i32 @llvm.amdgcn.sbfe.i32(i32 %shr, i32 1, i32 1)
533 store i32 %bfe, i32 addrspace(1)* %out, align 4
537 ; GCN-LABEL: {{^}}sext_in_reg_i2_bfe_offset_1:
538 ; GCN: buffer_load_dword
541 ; GCN: v_bfe_i32 v{{[0-9]+}}, v{{[0-9]+}}, 0, 2
542 ; GCN: v_bfe_i32 v{{[0-9]+}}, v{{[0-9]+}}, 1, 2
544 define amdgpu_kernel void @sext_in_reg_i2_bfe_offset_1(i32 addrspace(1)* %out, i32 addrspace(1)* %in) #0 {
545 %x = load i32, i32 addrspace(1)* %in, align 4
546 %shl = shl i32 %x, 30
547 %shr = ashr i32 %shl, 30
548 %bfe = call i32 @llvm.amdgcn.sbfe.i32(i32 %shr, i32 1, i32 2)
549 store i32 %bfe, i32 addrspace(1)* %out, align 4
553 declare i32 @llvm.amdgcn.sbfe.i32(i32, i32, i32) #1
555 attributes #0 = { nounwind }
556 attributes #1 = { nounwind readnone }