1 ; RUN: llc -amdgpu-scalarize-global-loads=false -march=amdgcn -mcpu=tahiti -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefix=GCN -check-prefix=SI %s
2 ; RUN: llc -amdgpu-scalarize-global-loads=false -march=amdgcn -mcpu=fiji -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefix=GCN -check-prefix=VI %s
3 ; RUN: llc -amdgpu-scalarize-global-loads=false -march=r600 -mcpu=cypress < %s | FileCheck -enable-var-scope -check-prefix=EG %s
5 declare i32 @llvm.amdgcn.workitem.id.x() nounwind readnone
7 define amdgpu_kernel void @trunc_i64_to_i32_store(i32 addrspace(1)* %out, [8 x i32], i64 %in) {
8 ; GCN-LABEL: {{^}}trunc_i64_to_i32_store:
9 ; GCN: s_load_dword [[SLOAD:s[0-9]+]], s[0:1],
10 ; GCN: v_mov_b32_e32 [[VLOAD:v[0-9]+]], [[SLOAD]]
11 ; SI: buffer_store_dword [[VLOAD]]
12 ; VI: flat_store_dword v[{{[0-9:]+}}], [[VLOAD]]
14 ; EG-LABEL: {{^}}trunc_i64_to_i32_store:
15 ; EG: MEM_RAT_CACHELESS STORE_RAW T0.X, T1.X, 1
19 %result = trunc i64 %in to i32 store i32 %result, i32 addrspace(1)* %out, align 4
23 ; GCN-LABEL: {{^}}trunc_load_shl_i64:
24 ; GCN-DAG: s_load_dwordx2
25 ; GCN-DAG: s_load_dword [[SREG:s[0-9]+]],
26 ; GCN: s_lshl_b32 [[SHL:s[0-9]+]], [[SREG]], 2
27 ; GCN: v_mov_b32_e32 [[VSHL:v[0-9]+]], [[SHL]]
28 ; SI: buffer_store_dword [[VSHL]]
29 ; VI: flat_store_dword v[{{[0-9:]+}}], [[VSHL]]
31 define amdgpu_kernel void @trunc_load_shl_i64(i32 addrspace(1)* %out, [8 x i32], i64 %a) {
33 %result = trunc i64 %b to i32
34 store i32 %result, i32 addrspace(1)* %out, align 4
38 ; GCN-LABEL: {{^}}trunc_shl_i64:
39 ; SI: s_load_dwordx2 s[[[LO_SREG:[0-9]+]]:{{[0-9]+\]}}, s{{\[[0-9]+:[0-9]+\]}}, 0xd
40 ; VI: s_load_dwordx2 s[[[LO_SREG:[0-9]+]]:{{[0-9]+\]}}, s{{\[[0-9]+:[0-9]+\]}}, 0x34
41 ; GCN: s_lshl_b64 s[[[LO_SHL:[0-9]+]]:{{[0-9]+\]}}, s[[[LO_SREG]]:{{[0-9]+\]}}, 2
42 ; GCN: s_add_u32 s[[LO_SREG2:[0-9]+]], s[[LO_SHL]],
43 ; GCN: v_mov_b32_e32 v[[LO_VREG:[0-9]+]], s[[LO_SREG2]]
44 ; SI: buffer_store_dword v[[LO_VREG]],
45 ; VI: flat_store_dword v[{{[0-9:]+}}], v[[LO_VREG]]
48 define amdgpu_kernel void @trunc_shl_i64(i64 addrspace(1)* %out2, i32 addrspace(1)* %out, i64 %a) {
49 %aa = add i64 %a, 234 ; Prevent shrinking store.
51 %result = trunc i64 %b to i32
52 store i32 %result, i32 addrspace(1)* %out, align 4
53 store i64 %b, i64 addrspace(1)* %out2, align 8 ; Prevent reducing ops to 32-bits
57 ; GCN-LABEL: {{^}}trunc_i32_to_i1:
58 ; GCN: v_and_b32_e32 [[VREG:v[0-9]+]], 1, v{{[0-9]+}}
59 define amdgpu_kernel void @trunc_i32_to_i1(i32 addrspace(1)* %out, i32 addrspace(1)* %ptr) {
60 %a = load i32, i32 addrspace(1)* %ptr, align 4
61 %trunc = trunc i32 %a to i1
62 %result = select i1 %trunc, i32 1, i32 0
63 store i32 %result, i32 addrspace(1)* %out, align 4
67 ; GCN-LABEL: {{^}}trunc_i8_to_i1:
68 ; GCN: v_and_b32_e32 [[VREG:v[0-9]+]], 1, v{{[0-9]+}}
69 define amdgpu_kernel void @trunc_i8_to_i1(i8 addrspace(1)* %out, i8 addrspace(1)* %ptr) {
70 %a = load i8, i8 addrspace(1)* %ptr, align 4
71 %trunc = trunc i8 %a to i1
72 %result = select i1 %trunc, i8 1, i8 0
73 store i8 %result, i8 addrspace(1)* %out, align 4
77 ; GCN-LABEL: {{^}}sgpr_trunc_i16_to_i1:
78 ; GCN: s_and_b32 s{{[0-9]+}}, s{{[0-9]+}}, 1
79 define amdgpu_kernel void @sgpr_trunc_i16_to_i1(i16 addrspace(1)* %out, i16 %a) {
80 %trunc = trunc i16 %a to i1
81 %result = select i1 %trunc, i16 1, i16 0
82 store i16 %result, i16 addrspace(1)* %out, align 4
86 ; GCN-LABEL: {{^}}sgpr_trunc_i32_to_i1:
87 ; GCN: s_and_b32 s{{[0-9]+}}, s{{[0-9]+}}, 1
88 define amdgpu_kernel void @sgpr_trunc_i32_to_i1(i32 addrspace(1)* %out, i32 %a) {
89 %trunc = trunc i32 %a to i1
90 %result = select i1 %trunc, i32 1, i32 0
91 store i32 %result, i32 addrspace(1)* %out, align 4
95 ; GCN-LABEL: {{^}}s_trunc_i64_to_i1:
96 ; SI: s_load_dwordx2 s[[[SLO:[0-9]+]]:{{[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0x13
97 ; VI: s_load_dwordx2 s[[[SLO:[0-9]+]]:{{[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0x4c
98 ; GCN: s_bitcmp1_b32 s[[SLO]], 0
99 ; SI: s_cselect_b64 s[[[VLO:[0-9]+]]:[[VHI:[0-9]+]]], -1, 0
100 ; SI: v_cndmask_b32_e64 {{v[0-9]+}}, -12, 63, s[[[VLO]]:[[VHI]]]
101 ; VI: s_cselect_b32 {{s[0-9]+}}, 63, -12
102 define amdgpu_kernel void @s_trunc_i64_to_i1(i32 addrspace(1)* %out, [8 x i32], i64 %x) {
103 %trunc = trunc i64 %x to i1
104 %sel = select i1 %trunc, i32 63, i32 -12
105 store i32 %sel, i32 addrspace(1)* %out
109 ; GCN-LABEL: {{^}}v_trunc_i64_to_i1:
110 ; SI: buffer_load_dwordx2 v[[[VLO:[0-9]+]]:{{[0-9]+\]}}
111 ; VI: flat_load_dwordx2 v[[[VLO:[0-9]+]]:{{[0-9]+\]}}
112 ; GCN: v_and_b32_e32 [[MASKED:v[0-9]+]], 1, v[[VLO]]
113 ; GCN: v_cmp_eq_u32_e32 vcc, 1, [[MASKED]]
114 ; GCN: v_cndmask_b32_e64 {{v[0-9]+}}, -12, 63, vcc
115 define amdgpu_kernel void @v_trunc_i64_to_i1(i32 addrspace(1)* %out, i64 addrspace(1)* %in) {
116 %tid = call i32 @llvm.amdgcn.workitem.id.x() nounwind readnone
117 %gep = getelementptr i64, i64 addrspace(1)* %in, i32 %tid
118 %out.gep = getelementptr i32, i32 addrspace(1)* %out, i32 %tid
119 %x = load i64, i64 addrspace(1)* %gep
121 %trunc = trunc i64 %x to i1
122 %sel = select i1 %trunc, i32 63, i32 -12
123 store i32 %sel, i32 addrspace(1)* %out.gep