1 ; RUN: llc -mtriple=amdgcn -mcpu=gfx900 -mattr=-flat-for-global -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GFX9,GCN %s
2 ; RUN: llc -mtriple=amdgcn -mcpu=tonga -mattr=-flat-for-global -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=VI,CIVI,GCN %s
3 ; RUN: llc -mtriple=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 op_sel_hi:[1,0]
11 ; CIVI: s_lshr_b32 s{{[0-9]+}}, s{{[0-9]+}}, 16
20 define amdgpu_kernel void @s_abs_v2i16(ptr addrspace(1) %out, <2 x i16> %val) #0 {
21 %neg = sub <2 x i16> zeroinitializer, %val
22 %cond = icmp sgt <2 x i16> %val, %neg
23 %res = select <2 x i1> %cond, <2 x i16> %val, <2 x i16> %neg
24 %res2 = add <2 x i16> %res, <i16 2, i16 2>
25 store <2 x i16> %res2, ptr addrspace(1) %out, align 4
29 ; GCN-LABEL: {{^}}v_abs_v2i16:
30 ; GFX9: global_load_dword [[VAL:v[0-9]+]]
31 ; GFX9: v_pk_sub_i16 [[SUB:v[0-9]+]], 0, [[VAL]]
32 ; GFX9: v_pk_max_i16 [[MAX:v[0-9]+]], [[VAL]], [[SUB]]
33 ; GFX9: v_pk_add_u16 [[ADD:v[0-9]+]], [[MAX]], 2 op_sel_hi:[1,0]
35 ; VI-DAG: v_mov_b32_e32 [[ZERO:v[0-9]+]], 0
36 ; VI-DAG: v_mov_b32_e32 [[TWO:v[0-9]+]], 2
37 ; VI-DAG: v_sub_u16_e32 v{{[0-9]+}}, 0, v{{[0-9]+}}
38 ; VI-DAG: v_sub_u16_sdwa v{{[0-9]+}}, [[ZERO]], v{{[0-9]+}}
39 ; VI-DAG: v_max_i16_e32 v{{[0-9]+}}, v{{[0-9]+}}, v{{[0-9]+}}
40 ; VI-DAG: v_max_i16_sdwa v{{[0-9]+}}, v{{[0-9]+}}, v{{[0-9]+}}
41 ; VI: v_add_u16_e32 v{{[0-9]+}}, 2, v{{[0-9]+}}
42 ; 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
46 ; CI: buffer_load_dword v
47 ; CI: v_lshrrev_b32_e32
48 ; CI-DAG: v_sub_i32_e32
56 define amdgpu_kernel void @v_abs_v2i16(ptr addrspace(1) %out, ptr addrspace(1) %src) #0 {
57 %tid = call i32 @llvm.amdgcn.workitem.id.x()
58 %gep.in = getelementptr inbounds <2 x i16>, ptr addrspace(1) %src, i32 %tid
59 %gep.out = getelementptr inbounds <2 x i16>, ptr addrspace(1) %out, i32 %tid
60 %val = load <2 x i16>, ptr addrspace(1) %gep.in, align 4
61 %neg = sub <2 x i16> zeroinitializer, %val
62 %cond = icmp sgt <2 x i16> %val, %neg
63 %res = select <2 x i1> %cond, <2 x i16> %val, <2 x i16> %neg
64 %res2 = add <2 x i16> %res, <i16 2, i16 2>
65 store <2 x i16> %res2, ptr addrspace(1) %gep.out, align 4
69 ; GCN-LABEL: {{^}}s_abs_v2i16_2:
70 ; GFX9: s_load_dword [[VAL:s[0-9]+]]
71 ; GFX9: v_pk_sub_i16 [[SUB:v[0-9]+]], 0, [[VAL]]
72 ; GFX9: v_pk_max_i16 [[MAX:v[0-9]+]], [[VAL]], [[SUB]]
73 ; GFX9: v_pk_add_u16 [[ADD:v[0-9]+]], [[MAX]], 2 op_sel_hi:[1,0]
74 define amdgpu_kernel void @s_abs_v2i16_2(ptr addrspace(1) %out, <2 x i16> %val) #0 {
75 %z0 = insertelement <2 x i16> undef, i16 0, i16 0
76 %z1 = insertelement <2 x i16> %z0, i16 0, i16 1
77 %t0 = insertelement <2 x i16> undef, i16 2, i16 0
78 %t1 = insertelement <2 x i16> %t0, i16 2, i16 1
79 %neg = sub <2 x i16> %z1, %val
80 %cond = icmp sgt <2 x i16> %val, %neg
81 %res = select <2 x i1> %cond, <2 x i16> %val, <2 x i16> %neg
82 %res2 = add <2 x i16> %res, %t1
83 store <2 x i16> %res2, ptr addrspace(1) %out, align 4
87 ; GCN-LABEL: {{^}}v_abs_v2i16_2:
88 ; GFX9: global_load_dword [[VAL:v[0-9]+]]
89 ; GFX9: v_pk_sub_i16 [[SUB:v[0-9]+]], 0, [[VAL]]
90 ; GFX9: v_pk_max_i16 [[MAX:v[0-9]+]], [[VAL]], [[SUB]]
91 ; GFX9: v_pk_add_u16 [[ADD:v[0-9]+]], [[MAX]], 2 op_sel_hi:[1,0]
92 define amdgpu_kernel void @v_abs_v2i16_2(ptr addrspace(1) %out, ptr addrspace(1) %src) #0 {
93 %z0 = insertelement <2 x i16> undef, i16 0, i16 0
94 %z1 = insertelement <2 x i16> %z0, i16 0, i16 1
95 %t0 = insertelement <2 x i16> undef, i16 2, i16 0
96 %t1 = insertelement <2 x i16> %t0, i16 2, i16 1
97 %tid = call i32 @llvm.amdgcn.workitem.id.x()
98 %gep.in = getelementptr inbounds <2 x i16>, ptr addrspace(1) %src, i32 %tid
99 %val = load <2 x i16>, ptr addrspace(1) %gep.in, align 4
100 %neg = sub <2 x i16> %z1, %val
101 %cond = icmp sgt <2 x i16> %val, %neg
102 %res = select <2 x i1> %cond, <2 x i16> %val, <2 x i16> %neg
103 %res2 = add <2 x i16> %res, %t1
104 store <2 x i16> %res2, ptr addrspace(1) %out, align 4
108 ; GCN-LABEL: {{^}}s_abs_v4i16:
109 ; GFX9: s_load_dwordx4 s[[[#LOAD:]]:{{[0-9]+}}], s[2:3], 0x24
110 ; GFX9-DAG: v_pk_sub_i16 [[SUB0:v[0-9]+]], 0, s[[#LOAD + 2]]
111 ; GFX9-DAG: v_pk_sub_i16 [[SUB1:v[0-9]+]], 0, s[[#LOAD + 3]]
112 ; GFX9-DAG: v_pk_max_i16 [[MAX0:v[0-9]+]], s[[#LOAD + 2]], [[SUB0]]
113 ; GFX9-DAG: v_pk_max_i16 [[MAX1:v[0-9]+]], s[[#LOAD + 3]], [[SUB1]]
114 ; GFX9-DAG: v_pk_add_u16 [[ADD0:v[0-9]+]], [[MAX0]], 2 op_sel_hi:[1,0]
115 ; GFX9-DAG: v_pk_add_u16 [[ADD1:v[0-9]+]], [[MAX1]], 2 op_sel_hi:[1,0]
116 define amdgpu_kernel void @s_abs_v4i16(ptr addrspace(1) %out, <4 x i16> %val) #0 {
117 %z0 = insertelement <4 x i16> undef, i16 0, i16 0
118 %z1 = insertelement <4 x i16> %z0, i16 0, i16 1
119 %z2 = insertelement <4 x i16> %z1, i16 0, i16 2
120 %z3 = insertelement <4 x i16> %z2, i16 0, i16 3
121 %t0 = insertelement <4 x i16> undef, i16 2, i16 0
122 %t1 = insertelement <4 x i16> %t0, i16 2, i16 1
123 %t2 = insertelement <4 x i16> %t1, i16 2, i16 2
124 %t3 = insertelement <4 x i16> %t2, i16 2, i16 3
125 %neg = sub <4 x i16> %z3, %val
126 %cond = icmp sgt <4 x i16> %val, %neg
127 %res = select <4 x i1> %cond, <4 x i16> %val, <4 x i16> %neg
128 %res2 = add <4 x i16> %res, %t3
129 store <4 x i16> %res2, ptr addrspace(1) %out, align 4
133 ; GCN-LABEL: {{^}}v_abs_v4i16:
134 ; GFX9: global_load_dwordx2 v[[[VAL0:[0-9]+]]:[[VAL1:[0-9]+]]]
136 ; GFX9-DAG: v_pk_sub_i16 [[SUB0:v[0-9]+]], 0, v[[VAL0]]
137 ; GFX9-DAG: v_pk_max_i16 [[MAX0:v[0-9]+]], v[[VAL0]], [[SUB0]]
138 ; GFX9-DAG: v_pk_add_u16 [[ADD0:v[0-9]+]], [[MAX0]], 2 op_sel_hi:[1,0]
140 ; GFX9-DAG: v_pk_sub_i16 [[SUB1:v[0-9]+]], 0, v[[VAL1]]
141 ; GFX9-DAG: v_pk_max_i16 [[MAX1:v[0-9]+]], v[[VAL1]], [[SUB1]]
142 ; GFX9-DAG: v_pk_add_u16 [[ADD1:v[0-9]+]], [[MAX1]], 2 op_sel_hi:[1,0]
143 define amdgpu_kernel void @v_abs_v4i16(ptr addrspace(1) %out, ptr addrspace(1) %src) #0 {
144 %z0 = insertelement <4 x i16> undef, i16 0, i16 0
145 %z1 = insertelement <4 x i16> %z0, i16 0, i16 1
146 %z2 = insertelement <4 x i16> %z1, i16 0, i16 2
147 %z3 = insertelement <4 x i16> %z2, i16 0, i16 3
148 %t0 = insertelement <4 x i16> undef, i16 2, i16 0
149 %t1 = insertelement <4 x i16> %t0, i16 2, i16 1
150 %t2 = insertelement <4 x i16> %t1, i16 2, i16 2
151 %t3 = insertelement <4 x i16> %t2, i16 2, i16 3
152 %tid = call i32 @llvm.amdgcn.workitem.id.x()
153 %gep.in = getelementptr inbounds <4 x i16>, ptr addrspace(1) %src, i32 %tid
154 %val = load <4 x i16>, ptr addrspace(1) %gep.in, align 4
155 %neg = sub <4 x i16> %z3, %val
156 %cond = icmp sgt <4 x i16> %val, %neg
157 %res = select <4 x i1> %cond, <4 x i16> %val, <4 x i16> %neg
158 %res2 = add <4 x i16> %res, %t3
159 store <4 x i16> %res2, ptr addrspace(1) %out, align 4
163 ; GCN-LABEL: {{^}}s_min_max_v2i16:
166 define amdgpu_kernel void @s_min_max_v2i16(ptr addrspace(1) %out0, ptr addrspace(1) %out1, <2 x i16> %val0, <2 x i16> %val1) #0 {
167 %cond0 = icmp sgt <2 x i16> %val0, %val1
168 %sel0 = select <2 x i1> %cond0, <2 x i16> %val0, <2 x i16> %val1
169 %sel1 = select <2 x i1> %cond0, <2 x i16> %val1, <2 x i16> %val0
171 store volatile <2 x i16> %sel0, ptr addrspace(1) %out0, align 4
172 store volatile <2 x i16> %sel1, ptr addrspace(1) %out1, align 4
176 ; GCN-LABEL: {{^}}v_min_max_v2i16:
179 define amdgpu_kernel void @v_min_max_v2i16(ptr addrspace(1) %out0, ptr addrspace(1) %out1, ptr addrspace(1) %ptr0, ptr addrspace(1) %ptr1) #0 {
180 %val0 = load volatile <2 x i16>, ptr addrspace(1) %ptr0
181 %val1 = load volatile <2 x i16>, ptr addrspace(1) %ptr1
183 %cond0 = icmp sgt <2 x i16> %val0, %val1
184 %sel0 = select <2 x i1> %cond0, <2 x i16> %val0, <2 x i16> %val1
185 %sel1 = select <2 x i1> %cond0, <2 x i16> %val1, <2 x i16> %val0
187 store volatile <2 x i16> %sel0, ptr addrspace(1) %out0, align 4
188 store volatile <2 x i16> %sel1, ptr addrspace(1) %out1, align 4
192 ; GCN-LABEL: {{^}}s_min_max_v4i16:
193 ; GFX9-DAG: v_pk_max_i16
194 ; GFX9-DAG: v_pk_min_i16
195 ; GFX9-DAG: v_pk_max_i16
196 ; GFX9-DAG: v_pk_min_i16
197 define amdgpu_kernel void @s_min_max_v4i16(ptr addrspace(1) %out0, ptr addrspace(1) %out1, <4 x i16> %val0, <4 x i16> %val1) #0 {
198 %cond0 = icmp sgt <4 x i16> %val0, %val1
199 %sel0 = select <4 x i1> %cond0, <4 x i16> %val0, <4 x i16> %val1
200 %sel1 = select <4 x i1> %cond0, <4 x i16> %val1, <4 x i16> %val0
202 store volatile <4 x i16> %sel0, ptr addrspace(1) %out0, align 4
203 store volatile <4 x i16> %sel1, ptr addrspace(1) %out1, align 4
207 ; GCN-LABEL: {{^}}v_min_max_v2i16_user:
208 define amdgpu_kernel void @v_min_max_v2i16_user(ptr addrspace(1) %out0, ptr addrspace(1) %out1, ptr addrspace(1) %ptr0, ptr addrspace(1) %ptr1) #0 {
209 %val0 = load volatile <2 x i16>, ptr addrspace(1) %ptr0
210 %val1 = load volatile <2 x i16>, ptr addrspace(1) %ptr1
212 %cond0 = icmp sgt <2 x i16> %val0, %val1
213 %sel0 = select <2 x i1> %cond0, <2 x i16> %val0, <2 x i16> %val1
214 %sel1 = select <2 x i1> %cond0, <2 x i16> %val1, <2 x i16> %val0
216 store volatile <2 x i16> %sel0, ptr addrspace(1) %out0, align 4
217 store volatile <2 x i16> %sel1, ptr addrspace(1) %out1, align 4
218 store volatile <2 x i1> %cond0, ptr addrspace(1) undef
222 ; GCN-LABEL: {{^}}u_min_max_v2i16:
223 ; GFX9: v_pk_max_u16 v{{[0-9]+}}, s{{[0-9]+}}, v{{[0-9]+}}
224 ; GFX9: v_pk_min_u16 v{{[0-9]+}}, s{{[0-9]+}}, v{{[0-9]+}}
225 define amdgpu_kernel void @u_min_max_v2i16(ptr addrspace(1) %out0, ptr addrspace(1) %out1, <2 x i16> %val0, <2 x i16> %val1) nounwind {
226 %cond0 = icmp ugt <2 x i16> %val0, %val1
227 %sel0 = select <2 x i1> %cond0, <2 x i16> %val0, <2 x i16> %val1
228 %sel1 = select <2 x i1> %cond0, <2 x i16> %val1, <2 x i16> %val0
230 store volatile <2 x i16> %sel0, ptr addrspace(1) %out0, align 4
231 store volatile <2 x i16> %sel1, ptr addrspace(1) %out1, align 4
235 declare i32 @llvm.amdgcn.workitem.id.x() #1
237 attributes #0 = { nounwind }
238 attributes #1 = { nounwind readnone }