1 ; RUN: llc -amdgpu-scalarize-global-loads=false -march=amdgcn -mcpu=gfx900 -mattr=-flat-for-global -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GFX9,GCN %s
2 ; RUN: llc -amdgpu-scalarize-global-loads=false -march=amdgcn -mcpu=tonga -mattr=-flat-for-global -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=VI,CIVI,GCN %s
3 ; RUN: llc -amdgpu-scalarize-global-loads=false -march=amdgcn -mcpu=bonaire -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=CI,CIVI,GCN %s
5 ; GCN-LABEL: {{^}}s_abs_v2i16:
6 ; GFX9: s_load_dword [[VAL:s[0-9]+]]
7 ; GFX9: v_pk_sub_i16 [[SUB:v[0-9]+]], 0, [[VAL]]
8 ; GFX9: v_pk_max_i16 [[MAX:v[0-9]+]], [[VAL]], [[SUB]]
9 ; GFX9: v_pk_add_u16 [[ADD:v[0-9]+]], [[MAX]], 2
11 ; VI: s_lshr_b32 s{{[0-9]+}}, s{{[0-9]+}}, 16
22 ; CI-DAG: v_sub_i32_e32
25 ; CI-DAG: v_add_i32_e32
26 ; CI-DAG: v_lshlrev_b32_e32 v{{[0-9]+}}, 16
28 ; CI: v_and_b32_e32 v{{[0-9]+}}, 0xffff,
30 define amdgpu_kernel void @s_abs_v2i16(<2 x i16> addrspace(1)* %out, <2 x i16> %val) #0 {
31 %neg = sub <2 x i16> zeroinitializer, %val
32 %cond = icmp sgt <2 x i16> %val, %neg
33 %res = select <2 x i1> %cond, <2 x i16> %val, <2 x i16> %neg
34 %res2 = add <2 x i16> %res, <i16 2, i16 2>
35 store <2 x i16> %res2, <2 x i16> addrspace(1)* %out, align 4
39 ; GCN-LABEL: {{^}}v_abs_v2i16:
40 ; GFX9: global_load_dword [[VAL:v[0-9]+]]
41 ; GFX9: v_pk_sub_i16 [[SUB:v[0-9]+]], 0, [[VAL]]
42 ; GFX9: v_pk_max_i16 [[MAX:v[0-9]+]], [[VAL]], [[SUB]]
43 ; GFX9: v_pk_add_u16 [[ADD:v[0-9]+]], [[MAX]], 2
45 ; VI: v_mov_b32_e32 [[TWO:v[0-9]+]], 2
46 ; VI: v_lshrrev_b32_e32 v{{[0-9]+}}, 16,
47 ; VI: v_sub_u16_e32 v{{[0-9]+}}, 0, v{{[0-9]+}}
48 ; VI: v_sub_u16_e32 v{{[0-9]+}}, 0, v{{[0-9]+}}
49 ; VI: v_max_i16_e32 v{{[0-9]+}}, v{{[0-9]+}}, v{{[0-9]+}}
50 ; VI: v_max_i16_e32 v{{[0-9]+}}, v{{[0-9]+}}, v{{[0-9]+}}
51 ; VI: v_add_u16_e32 v{{[0-9]+}}, 2, v{{[0-9]+}}
52 ; VI: v_add_u16_sdwa v{{[0-9]+}}, v{{[0-9]+}}, [[TWO]] dst_sel:WORD_1 dst_unused:UNUSED_PAD src0_sel:DWORD src1_sel:DWORD
55 define amdgpu_kernel void @v_abs_v2i16(<2 x i16> addrspace(1)* %out, <2 x i16> addrspace(1)* %src) #0 {
56 %tid = call i32 @llvm.amdgcn.workitem.id.x()
57 %gep.in = getelementptr inbounds <2 x i16>, <2 x i16> addrspace(1)* %src, i32 %tid
58 %gep.out = getelementptr inbounds <2 x i16>, <2 x i16> addrspace(1)* %out, i32 %tid
59 %val = load <2 x i16>, <2 x i16> addrspace(1)* %gep.in, align 4
60 %neg = sub <2 x i16> zeroinitializer, %val
61 %cond = icmp sgt <2 x i16> %val, %neg
62 %res = select <2 x i1> %cond, <2 x i16> %val, <2 x i16> %neg
63 %res2 = add <2 x i16> %res, <i16 2, i16 2>
64 store <2 x i16> %res2, <2 x i16> addrspace(1)* %gep.out, align 4
68 ; GCN-LABEL: {{^}}s_abs_v2i16_2:
69 ; GFX9: s_load_dword [[VAL:s[0-9]+]]
70 ; GFX9: v_pk_sub_i16 [[SUB:v[0-9]+]], 0, [[VAL]]
71 ; GFX9: v_pk_max_i16 [[MAX:v[0-9]+]], [[VAL]], [[SUB]]
72 ; GFX9: v_pk_add_u16 [[ADD:v[0-9]+]], [[MAX]], 2
73 define amdgpu_kernel void @s_abs_v2i16_2(<2 x i16> addrspace(1)* %out, <2 x i16> %val) #0 {
74 %z0 = insertelement <2 x i16> undef, i16 0, i16 0
75 %z1 = insertelement <2 x i16> %z0, i16 0, i16 1
76 %t0 = insertelement <2 x i16> undef, i16 2, i16 0
77 %t1 = insertelement <2 x i16> %t0, i16 2, i16 1
78 %neg = sub <2 x i16> %z1, %val
79 %cond = icmp sgt <2 x i16> %val, %neg
80 %res = select <2 x i1> %cond, <2 x i16> %val, <2 x i16> %neg
81 %res2 = add <2 x i16> %res, %t1
82 store <2 x i16> %res2, <2 x i16> addrspace(1)* %out, align 4
86 ; GCN-LABEL: {{^}}v_abs_v2i16_2:
87 ; GFX9: buffer_load_dword [[VAL:v[0-9]+]]
88 ; GFX9: v_pk_sub_i16 [[SUB:v[0-9]+]], 0, [[VAL]]
89 ; GFX9: v_pk_max_i16 [[MAX:v[0-9]+]], [[VAL]], [[SUB]]
90 ; GFX9: v_pk_add_u16 [[ADD:v[0-9]+]], [[MAX]], 2
91 define amdgpu_kernel void @v_abs_v2i16_2(<2 x i16> addrspace(1)* %out, <2 x i16> addrspace(1)* %src) #0 {
92 %z0 = insertelement <2 x i16> undef, i16 0, i16 0
93 %z1 = insertelement <2 x i16> %z0, i16 0, i16 1
94 %t0 = insertelement <2 x i16> undef, i16 2, i16 0
95 %t1 = insertelement <2 x i16> %t0, i16 2, i16 1
96 %val = load <2 x i16>, <2 x i16> addrspace(1)* %src, align 4
97 %neg = sub <2 x i16> %z1, %val
98 %cond = icmp sgt <2 x i16> %val, %neg
99 %res = select <2 x i1> %cond, <2 x i16> %val, <2 x i16> %neg
100 %res2 = add <2 x i16> %res, %t1
101 store <2 x i16> %res2, <2 x i16> addrspace(1)* %out, align 4
105 ; GCN-LABEL: {{^}}s_abs_v4i16:
106 ; GFX9: s_load_dword [[VAL0:s[0-9]+]]
107 ; GFX9: s_load_dword [[VAL1:s[0-9]+]]
108 ; GFX9-DAG: v_pk_sub_i16 [[SUB0:v[0-9]+]], 0, [[VAL0]]
109 ; GFX9-DAG: v_pk_max_i16 [[MAX0:v[0-9]+]], [[VAL0]], [[SUB0]]
110 ; GFX9-DAG: v_pk_add_u16 [[ADD0:v[0-9]+]], [[MAX0]], 2
112 ; GFX9-DAG: v_pk_sub_i16 [[SUB1:v[0-9]+]], 0, [[VAL1]]
113 ; GFX9-DAG: v_pk_max_i16 [[MAX1:v[0-9]+]], [[VAL1]], [[SUB1]]
114 ; GFX9-DAG: v_pk_add_u16 [[ADD1:v[0-9]+]], [[MAX1]], 2
115 define amdgpu_kernel void @s_abs_v4i16(<4 x i16> addrspace(1)* %out, <4 x i16> %val) #0 {
116 %z0 = insertelement <4 x i16> undef, i16 0, i16 0
117 %z1 = insertelement <4 x i16> %z0, i16 0, i16 1
118 %z2 = insertelement <4 x i16> %z1, i16 0, i16 2
119 %z3 = insertelement <4 x i16> %z2, i16 0, i16 3
120 %t0 = insertelement <4 x i16> undef, i16 2, i16 0
121 %t1 = insertelement <4 x i16> %t0, i16 2, i16 1
122 %t2 = insertelement <4 x i16> %t1, i16 2, i16 2
123 %t3 = insertelement <4 x i16> %t2, i16 2, i16 3
124 %neg = sub <4 x i16> %z3, %val
125 %cond = icmp sgt <4 x i16> %val, %neg
126 %res = select <4 x i1> %cond, <4 x i16> %val, <4 x i16> %neg
127 %res2 = add <4 x i16> %res, %t3
128 store <4 x i16> %res2, <4 x i16> addrspace(1)* %out, align 4
132 ; GCN-LABEL: {{^}}v_abs_v4i16:
133 ; GFX9: buffer_load_dwordx2 v{{\[}}[[VAL0:[0-9]+]]:[[VAL1:[0-9]+]]{{\]}}
135 ; GFX9-DAG: v_pk_sub_i16 [[SUB0:v[0-9]+]], 0, v[[VAL0]]
136 ; GFX9-DAG: v_pk_max_i16 [[MAX0:v[0-9]+]], v[[VAL0]], [[SUB0]]
137 ; GFX9-DAG: v_pk_add_u16 [[ADD0:v[0-9]+]], [[MAX0]], 2
139 ; GFX9-DAG: v_pk_sub_i16 [[SUB1:v[0-9]+]], 0, v[[VAL1]]
140 ; GFX9-DAG: v_pk_max_i16 [[MAX1:v[0-9]+]], v[[VAL1]], [[SUB1]]
141 ; GFX9-DAG: v_pk_add_u16 [[ADD1:v[0-9]+]], [[MAX1]], 2
142 define amdgpu_kernel void @v_abs_v4i16(<4 x i16> addrspace(1)* %out, <4 x i16> addrspace(1)* %src) #0 {
143 %z0 = insertelement <4 x i16> undef, i16 0, i16 0
144 %z1 = insertelement <4 x i16> %z0, i16 0, i16 1
145 %z2 = insertelement <4 x i16> %z1, i16 0, i16 2
146 %z3 = insertelement <4 x i16> %z2, i16 0, i16 3
147 %t0 = insertelement <4 x i16> undef, i16 2, i16 0
148 %t1 = insertelement <4 x i16> %t0, i16 2, i16 1
149 %t2 = insertelement <4 x i16> %t1, i16 2, i16 2
150 %t3 = insertelement <4 x i16> %t2, i16 2, i16 3
151 %val = load <4 x i16>, <4 x i16> addrspace(1)* %src, align 4
152 %neg = sub <4 x i16> %z3, %val
153 %cond = icmp sgt <4 x i16> %val, %neg
154 %res = select <4 x i1> %cond, <4 x i16> %val, <4 x i16> %neg
155 %res2 = add <4 x i16> %res, %t3
156 store <4 x i16> %res2, <4 x i16> addrspace(1)* %out, align 4
160 ; GCN-LABEL: {{^}}s_min_max_v2i16:
163 define amdgpu_kernel void @s_min_max_v2i16(<2 x i16> addrspace(1)* %out0, <2 x i16> addrspace(1)* %out1, <2 x i16> %val0, <2 x i16> %val1) #0 {
164 %cond0 = icmp sgt <2 x i16> %val0, %val1
165 %sel0 = select <2 x i1> %cond0, <2 x i16> %val0, <2 x i16> %val1
166 %sel1 = select <2 x i1> %cond0, <2 x i16> %val1, <2 x i16> %val0
168 store volatile <2 x i16> %sel0, <2 x i16> addrspace(1)* %out0, align 4
169 store volatile <2 x i16> %sel1, <2 x i16> addrspace(1)* %out1, align 4
173 ; GCN-LABEL: {{^}}v_min_max_v2i16:
176 define amdgpu_kernel void @v_min_max_v2i16(<2 x i16> addrspace(1)* %out0, <2 x i16> addrspace(1)* %out1, <2 x i16> addrspace(1)* %ptr0, <2 x i16> addrspace(1)* %ptr1) #0 {
177 %val0 = load volatile <2 x i16>, <2 x i16> addrspace(1)* %ptr0
178 %val1 = load volatile <2 x i16>, <2 x i16> addrspace(1)* %ptr1
180 %cond0 = icmp sgt <2 x i16> %val0, %val1
181 %sel0 = select <2 x i1> %cond0, <2 x i16> %val0, <2 x i16> %val1
182 %sel1 = select <2 x i1> %cond0, <2 x i16> %val1, <2 x i16> %val0
184 store volatile <2 x i16> %sel0, <2 x i16> addrspace(1)* %out0, align 4
185 store volatile <2 x i16> %sel1, <2 x i16> addrspace(1)* %out1, align 4
189 ; GCN-LABEL: {{^}}s_min_max_v4i16:
194 define amdgpu_kernel void @s_min_max_v4i16(<4 x i16> addrspace(1)* %out0, <4 x i16> addrspace(1)* %out1, <4 x i16> %val0, <4 x i16> %val1) #0 {
195 %cond0 = icmp sgt <4 x i16> %val0, %val1
196 %sel0 = select <4 x i1> %cond0, <4 x i16> %val0, <4 x i16> %val1
197 %sel1 = select <4 x i1> %cond0, <4 x i16> %val1, <4 x i16> %val0
199 store volatile <4 x i16> %sel0, <4 x i16> addrspace(1)* %out0, align 4
200 store volatile <4 x i16> %sel1, <4 x i16> addrspace(1)* %out1, align 4
204 ; GCN-LABEL: {{^}}v_min_max_v2i16_user:
205 define amdgpu_kernel void @v_min_max_v2i16_user(<2 x i16> addrspace(1)* %out0, <2 x i16> addrspace(1)* %out1, <2 x i16> addrspace(1)* %ptr0, <2 x i16> addrspace(1)* %ptr1) #0 {
206 %val0 = load volatile <2 x i16>, <2 x i16> addrspace(1)* %ptr0
207 %val1 = load volatile <2 x i16>, <2 x i16> addrspace(1)* %ptr1
209 %cond0 = icmp sgt <2 x i16> %val0, %val1
210 %sel0 = select <2 x i1> %cond0, <2 x i16> %val0, <2 x i16> %val1
211 %sel1 = select <2 x i1> %cond0, <2 x i16> %val1, <2 x i16> %val0
213 store volatile <2 x i16> %sel0, <2 x i16> addrspace(1)* %out0, align 4
214 store volatile <2 x i16> %sel1, <2 x i16> addrspace(1)* %out1, align 4
215 store volatile <2 x i1> %cond0, <2 x i1> addrspace(1)* undef
219 ; GCN-LABEL: {{^}}u_min_max_v2i16:
220 ; GFX9: v_pk_max_u16 v{{[0-9]+}}, s{{[0-9]+}}, v{{[0-9]+}}
221 ; GFX9: v_pk_min_u16 v{{[0-9]+}}, s{{[0-9]+}}, v{{[0-9]+}}
222 define amdgpu_kernel void @u_min_max_v2i16(<2 x i16> addrspace(1)* %out0, <2 x i16> addrspace(1)* %out1, <2 x i16> %val0, <2 x i16> %val1) nounwind {
223 %cond0 = icmp ugt <2 x i16> %val0, %val1
224 %sel0 = select <2 x i1> %cond0, <2 x i16> %val0, <2 x i16> %val1
225 %sel1 = select <2 x i1> %cond0, <2 x i16> %val1, <2 x i16> %val0
227 store volatile <2 x i16> %sel0, <2 x i16> addrspace(1)* %out0, align 4
228 store volatile <2 x i16> %sel1, <2 x i16> addrspace(1)* %out1, align 4
232 declare i32 @llvm.amdgcn.workitem.id.x() #1
234 attributes #0 = { nounwind }
235 attributes #1 = { nounwind readnone }