1 ; RUN: llc -march=amdgcn -mcpu=gfx900 -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefix=GCN %s
3 ; GCN-LABEL: {{^}}select_and1:
4 ; GCN: s_cselect_b32 [[SEL:s[0-9]+]], s{{[0-9]+}},
5 ; GCN: v_mov_b32_e32 [[VSEL:v[0-9]+]], [[SEL]]
7 ; GCN: store_dword v{{[0-9]+}}, [[VSEL]], s{{\[[0-9]+:[0-9]+\]}}
8 define amdgpu_kernel void @select_and1(ptr addrspace(1) %p, i32 %x, i32 %y) {
9 %c = icmp slt i32 %x, 11
10 %s = select i1 %c, i32 0, i32 -1
12 store i32 %a, ptr addrspace(1) %p, align 4
16 ; GCN-LABEL: {{^}}select_and2:
17 ; GCN: s_cselect_b32 [[SEL:s[0-9]+]], s{{[0-9]+}},
18 ; GCN: v_mov_b32_e32 [[VSEL:v[0-9]+]], [[SEL]]
20 ; GCN: store_dword v{{[0-9]+}}, [[VSEL]], s{{\[[0-9]+:[0-9]+\]}}
21 define amdgpu_kernel void @select_and2(ptr addrspace(1) %p, i32 %x, i32 %y) {
22 %c = icmp slt i32 %x, 11
23 %s = select i1 %c, i32 0, i32 -1
25 store i32 %a, ptr addrspace(1) %p, align 4
29 ; GCN-LABEL: {{^}}select_and3:
30 ; GCN: s_cselect_b32 [[SEL:s[0-9]+]], s{{[0-9]+}},
31 ; GCN: v_mov_b32_e32 [[VSEL:v[0-9]+]], [[SEL]]
33 ; GCN: store_dword v{{[0-9]+}}, [[VSEL]], s{{\[[0-9]+:[0-9]+\]}}
34 define amdgpu_kernel void @select_and3(ptr addrspace(1) %p, i32 %x, i32 %y) {
35 %c = icmp slt i32 %x, 11
36 %s = select i1 %c, i32 -1, i32 0
38 store i32 %a, ptr addrspace(1) %p, align 4
42 ; GCN-LABEL: {{^}}select_and_v4:
43 ; GCN: s_cselect_b32 s[[SEL0:[0-9]+]], s{{[0-9]+}}, 0
44 ; GCN: s_cselect_b32 s[[SEL1:[0-9]+]], s{{[0-9]+}}, 0
45 ; GCN: s_cselect_b32 s[[SEL2:[0-9]+]], s{{[0-9]+}}, 0
46 ; GCN: s_cselect_b32 s[[SEL3:[0-9]+]], s{{[0-9]+}}, 0
47 ; GCN: v_mov_b32_e32 v[[V0:[0-9]+]], s[[SEL3]]
48 ; GCN: v_mov_b32_e32 v[[V1:[0-9]+]], s[[SEL2]]
49 ; GCN: v_mov_b32_e32 v[[V2:[0-9]+]], s[[SEL1]]
50 ; GCN: v_mov_b32_e32 v[[V3:[0-9]+]], s[[SEL0]]
52 ; GCN: global_store_dwordx4 v{{[0-9]+}}, v[[[V0]]:[[V3]]]
53 define amdgpu_kernel void @select_and_v4(ptr addrspace(1) %p, i32 %x, <4 x i32> %y) {
54 %c = icmp slt i32 %x, 11
55 %s = select i1 %c, <4 x i32> zeroinitializer, <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>
56 %a = and <4 x i32> %s, %y
57 store <4 x i32> %a, ptr addrspace(1) %p, align 32
61 ; GCN-LABEL: {{^}}select_or1:
62 ; GCN: s_cselect_b32 [[SEL:s[0-9]+]], s{{[0-9]+}},
63 ; GCN: v_mov_b32_e32 [[VSEL:v[0-9]+]], [[SEL]]
65 ; GCN: store_dword v{{[0-9]+}}, [[VSEL]], s{{\[[0-9]+:[0-9]+\]}}
66 define amdgpu_kernel void @select_or1(ptr addrspace(1) %p, i32 %x, i32 %y) {
67 %c = icmp slt i32 %x, 11
68 %s = select i1 %c, i32 0, i32 -1
70 store i32 %a, ptr addrspace(1) %p, align 4
74 ; GCN-LABEL: {{^}}select_or2:
75 ; GCN: s_cselect_b32 [[SEL:s[0-9]+]], s{{[0-9]+}},
76 ; GCN: v_mov_b32_e32 [[VSEL:v[0-9]+]], [[SEL]]
78 ; GCN: store_dword v{{[0-9]+}}, [[VSEL]], s{{\[[0-9]+:[0-9]+\]}}
79 define amdgpu_kernel void @select_or2(ptr addrspace(1) %p, i32 %x, i32 %y) {
80 %c = icmp slt i32 %x, 11
81 %s = select i1 %c, i32 0, i32 -1
83 store i32 %a, ptr addrspace(1) %p, align 4
87 ; GCN-LABEL: {{^}}select_or3:
88 ; GCN: s_cselect_b32 [[SEL:s[0-9]+]], s{{[0-9]+}},
89 ; GCN: v_mov_b32_e32 [[VSEL:v[0-9]+]], [[SEL]]
91 ; GCN: store_dword v{{[0-9]+}}, [[VSEL]], s{{\[[0-9]+:[0-9]+\]}}
92 define amdgpu_kernel void @select_or3(ptr addrspace(1) %p, i32 %x, i32 %y) {
93 %c = icmp slt i32 %x, 11
94 %s = select i1 %c, i32 -1, i32 0
96 store i32 %a, ptr addrspace(1) %p, align 4
100 ; GCN-LABEL: {{^}}select_or_v4:
101 ; GCN: s_cselect_b32 s[[SEL0:[0-9]+]], s{{[0-9]+}}, -1
102 ; GCN: s_cselect_b32 s[[SEL1:[0-9]+]], s{{[0-9]+}}, -1
103 ; GCN: s_cselect_b32 s[[SEL2:[0-9]+]], s{{[0-9]+}}, -1
104 ; GCN: s_cselect_b32 s[[SEL3:[0-9]+]], s{{[0-9]+}}, -1
106 ; GCN: v_mov_b32_e32 v[[V0:[0-9]+]], s[[SEL3]]
107 ; GCN: v_mov_b32_e32 v[[V1:[0-9]+]], s[[SEL2]]
108 ; GCN: v_mov_b32_e32 v[[V2:[0-9]+]], s[[SEL1]]
109 ; GCN: v_mov_b32_e32 v[[V3:[0-9]+]], s[[SEL0]]
110 ; GCN: global_store_dwordx4 v{{[0-9]+}}, v[[[V0]]:[[V3]]]
111 define amdgpu_kernel void @select_or_v4(ptr addrspace(1) %p, i32 %x, <4 x i32> %y) {
112 %c = icmp slt i32 %x, 11
113 %s = select i1 %c, <4 x i32> zeroinitializer, <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>
114 %a = or <4 x i32> %s, %y
115 store <4 x i32> %a, ptr addrspace(1) %p, align 32
119 ; GCN-LABEL: {{^}}sel_constants_sub_constant_sel_constants:
120 ; GCN: s_cselect_b32 s{{[0-9]+}}, 9, 2
121 define amdgpu_kernel void @sel_constants_sub_constant_sel_constants(ptr addrspace(1) %p, i1 %cond) {
122 %sel = select i1 %cond, i32 -4, i32 3
123 %bo = sub i32 5, %sel
124 store i32 %bo, ptr addrspace(1) %p, align 4
128 ; GCN-LABEL: {{^}}sel_constants_sub_constant_sel_constants_i16:
129 ; GCN: v_cndmask_b32_e64 v{{[0-9]+}}, 2, 9,
130 define amdgpu_kernel void @sel_constants_sub_constant_sel_constants_i16(ptr addrspace(1) %p, i1 %cond) {
131 %sel = select i1 %cond, i16 -4, i16 3
132 %bo = sub i16 5, %sel
133 store i16 %bo, ptr addrspace(1) %p, align 2
137 ; GCN-LABEL: {{^}}sel_constants_sub_constant_sel_constants_i16_neg:
138 ; GCN: v_mov_b32_e32 [[F:v[0-9]+]], 0xfffff449
139 ; GCN: v_cndmask_b32_e64 v{{[0-9]+}}, [[F]], -3,
140 define amdgpu_kernel void @sel_constants_sub_constant_sel_constants_i16_neg(ptr addrspace(1) %p, i1 %cond) {
141 %sel = select i1 %cond, i16 4, i16 3000
142 %bo = sub i16 1, %sel
143 store i16 %bo, ptr addrspace(1) %p, align 2
147 ; GCN-LABEL: {{^}}sel_constants_sub_constant_sel_constants_v2i16:
148 ; GCN-DAG: s_mov_b32 [[T:s[0-9]+]], 0x50009
149 ; GCN: s_cselect_b32 s{{[0-9]+}}, [[T]], 0x60002
150 define amdgpu_kernel void @sel_constants_sub_constant_sel_constants_v2i16(ptr addrspace(1) %p, i1 %cond) {
151 %sel = select i1 %cond, <2 x i16> <i16 -4, i16 2>, <2 x i16> <i16 3, i16 1>
152 %bo = sub <2 x i16> <i16 5, i16 7>, %sel
153 store <2 x i16> %bo, ptr addrspace(1) %p, align 4
157 ; GCN-LABEL: {{^}}sel_constants_sub_constant_sel_constants_v4i32:
158 ; GCN: s_cselect_b32 s[[SEL0:[0-9]+]], 7, 14
159 ; GCN: s_cselect_b32 s[[SEL1:[0-9]+]], 6, 10
160 ; GCN: s_cselect_b32 s[[SEL2:[0-9]+]], 5, 6
161 ; GCN: s_cselect_b32 s[[SEL3:[0-9]+]], 9, 2
162 ; GCN: v_mov_b32_e32 v[[V0:[0-9]+]], s[[SEL3]]
163 ; GCN: v_mov_b32_e32 v[[V1:[0-9]+]], s[[SEL2]]
164 ; GCN: v_mov_b32_e32 v[[V2:[0-9]+]], s[[SEL1]]
165 ; GCN: v_mov_b32_e32 v[[V3:[0-9]+]], s[[SEL0]]
166 ; GCN: global_store_dwordx4 v{{[0-9]+}}, v[[[V0]]:[[V3]]]
167 define amdgpu_kernel void @sel_constants_sub_constant_sel_constants_v4i32(ptr addrspace(1) %p, i1 %cond) {
168 %sel = select i1 %cond, <4 x i32> <i32 -4, i32 2, i32 3, i32 4>, <4 x i32> <i32 3, i32 1, i32 -1, i32 -3>
169 %bo = sub <4 x i32> <i32 5, i32 7, i32 9, i32 11>, %sel
170 store <4 x i32> %bo, ptr addrspace(1) %p, align 32
174 ; GCN-LABEL: {{^}}sdiv_constant_sel_constants_i64:
175 ; GCN: s_cselect_b32 s{{[0-9]+}}, 0, 5
176 define amdgpu_kernel void @sdiv_constant_sel_constants_i64(ptr addrspace(1) %p, i1 %cond) {
177 %sel = select i1 %cond, i64 121, i64 23
178 %bo = sdiv i64 120, %sel
179 store i64 %bo, ptr addrspace(1) %p, align 8
183 ; GCN-LABEL: {{^}}sdiv_constant_sel_constants_i32:
184 ; GCN: s_cselect_b32 s{{[0-9]+}}, 26, 8
185 define amdgpu_kernel void @sdiv_constant_sel_constants_i32(ptr addrspace(1) %p, i1 %cond) {
186 %sel = select i1 %cond, i32 7, i32 23
187 %bo = sdiv i32 184, %sel
188 store i32 %bo, ptr addrspace(1) %p, align 8
192 ; GCN-LABEL: {{^}}udiv_constant_sel_constants_i64:
193 ; GCN: s_cselect_b32 s{{[0-9]+}}, 0, 5
194 define amdgpu_kernel void @udiv_constant_sel_constants_i64(ptr addrspace(1) %p, i1 %cond) {
195 %sel = select i1 %cond, i64 -4, i64 23
196 %bo = udiv i64 120, %sel
197 store i64 %bo, ptr addrspace(1) %p, align 8
201 ; GCN-LABEL: {{^}}srem_constant_sel_constants:
202 ; GCN: s_cselect_b32 s{{[0-9]+}}, 33, 3
203 define amdgpu_kernel void @srem_constant_sel_constants(ptr addrspace(1) %p, i1 %cond) {
204 %sel = select i1 %cond, i64 34, i64 15
205 %bo = srem i64 33, %sel
206 store i64 %bo, ptr addrspace(1) %p, align 8
210 ; GCN-LABEL: {{^}}urem_constant_sel_constants:
211 ; GCN: s_cselect_b32 s{{[0-9]+}}, 33, 3
212 define amdgpu_kernel void @urem_constant_sel_constants(ptr addrspace(1) %p, i1 %cond) {
213 %sel = select i1 %cond, i64 34, i64 15
214 %bo = urem i64 33, %sel
215 store i64 %bo, ptr addrspace(1) %p, align 8
219 ; GCN-LABEL: {{^}}shl_constant_sel_constants:
220 ; GCN: s_cselect_b32 s{{[0-9]+}}, 4, 8
221 define amdgpu_kernel void @shl_constant_sel_constants(ptr addrspace(1) %p, i1 %cond) {
222 %sel = select i1 %cond, i32 2, i32 3
223 %bo = shl i32 1, %sel
224 store i32 %bo, ptr addrspace(1) %p, align 4
228 ; GCN-LABEL: {{^}}lshr_constant_sel_constants:
229 ; GCN: s_cselect_b32 s{{[0-9]+}}, 16, 8
230 define amdgpu_kernel void @lshr_constant_sel_constants(ptr addrspace(1) %p, i1 %cond) {
231 %sel = select i1 %cond, i32 2, i32 3
232 %bo = lshr i32 64, %sel
233 store i32 %bo, ptr addrspace(1) %p, align 4
237 ; GCN-LABEL: {{^}}ashr_constant_sel_constants:
238 ; GCN: s_cselect_b32 s{{[0-9]+}}, 32, 16
239 define amdgpu_kernel void @ashr_constant_sel_constants(ptr addrspace(1) %p, i1 %cond) {
240 %sel = select i1 %cond, i32 2, i32 3
241 %bo = ashr i32 128, %sel
242 store i32 %bo, ptr addrspace(1) %p, align 4
246 ; GCN-LABEL: {{^}}fsub_constant_sel_constants:
247 ; GCN: v_cndmask_b32_e64 v{{[0-9]+}}, -4.0, 1.0,
248 define amdgpu_kernel void @fsub_constant_sel_constants(ptr addrspace(1) %p, i1 %cond) {
249 %sel = select i1 %cond, float -2.0, float 3.0
250 %bo = fsub float -1.0, %sel
251 store float %bo, ptr addrspace(1) %p, align 4
255 ; GCN-LABEL: {{^}}fsub_constant_sel_constants_f16:
256 ; TODO: it shall be possible to fold constants with OpSel
257 ; GCN-DAG: v_mov_b32_e32 [[T:v[0-9]+]], 0x3c00
258 ; GCN-DAG: v_mov_b32_e32 [[F:v[0-9]+]], 0xc400
259 ; GCN: v_cndmask_b32_e32 v{{[0-9]+}}, [[F]], [[T]],
260 define amdgpu_kernel void @fsub_constant_sel_constants_f16(ptr addrspace(1) %p, i1 %cond) {
261 %sel = select i1 %cond, half -2.0, half 3.0
262 %bo = fsub half -1.0, %sel
263 store half %bo, ptr addrspace(1) %p, align 2
267 ; GCN-LABEL: {{^}}fsub_constant_sel_constants_v2f16:
268 ; GCN: s_cselect_b32 s{{[0-9]+}}, 0x45003c00, -2.0
269 define amdgpu_kernel void @fsub_constant_sel_constants_v2f16(ptr addrspace(1) %p, i1 %cond) {
270 %sel = select i1 %cond, <2 x half> <half -2.0, half -3.0>, <2 x half> <half -1.0, half 4.0>
271 %bo = fsub <2 x half> <half -1.0, half 2.0>, %sel
272 store <2 x half> %bo, ptr addrspace(1) %p, align 4
276 ; GCN-LABEL: {{^}}fsub_constant_sel_constants_v4f32:
277 ; GCN: s_mov_b32 [[T0:s[0-9]+]], 0x41500000
278 ; GCN: s_cselect_b32 s[[SEL0:[0-9]+]], [[T0]], 0x40c00000
279 ; GCN: s_cselect_b32 s[[SEL1:[0-9]+]], 0x41100000, 4.0
280 ; GCN: s_cselect_b32 s[[SEL2:[0-9]+]], 0x40a00000, 2.0
281 ; GCN: s_cselect_b32 s[[SEL3:[0-9]+]], 1.0, 0
282 ; GCN: v_mov_b32_e32 v[[V0:[0-9]+]], s[[SEL3]]
283 ; GCN: v_mov_b32_e32 v[[V1:[0-9]+]], s[[SEL2]]
284 ; GCN: v_mov_b32_e32 v[[V2:[0-9]+]], s[[SEL1]]
285 ; GCN: v_mov_b32_e32 v[[V3:[0-9]+]], s[[SEL0]]
286 ; GCN: global_store_dwordx4 v{{[0-9]+}}, v[[[V0]]:[[V3]]]
287 define amdgpu_kernel void @fsub_constant_sel_constants_v4f32(ptr addrspace(1) %p, i1 %cond) {
288 %sel = select i1 %cond, <4 x float> <float -2.0, float -3.0, float -4.0, float -5.0>, <4 x float> <float -1.0, float 0.0, float 1.0, float 2.0>
289 %bo = fsub <4 x float> <float -1.0, float 2.0, float 5.0, float 8.0>, %sel
290 store <4 x float> %bo, ptr addrspace(1) %p, align 32
294 ; GCN-LABEL: {{^}}fdiv_constant_sel_constants:
295 ; GCN: v_cndmask_b32_e64 v{{[0-9]+}}, 4.0, -2.0,
296 define amdgpu_kernel void @fdiv_constant_sel_constants(ptr addrspace(1) %p, i1 %cond) {
297 %sel = select i1 %cond, float -4.0, float 2.0
298 %bo = fdiv float 8.0, %sel
299 store float %bo, ptr addrspace(1) %p, align 4
303 ; GCN-LABEL: {{^}}frem_constant_sel_constants:
304 ; GCN: v_cndmask_b32_e64 v{{[0-9]+}}, 2.0, 1.0,
305 define amdgpu_kernel void @frem_constant_sel_constants(ptr addrspace(1) %p, i1 %cond) {
306 %sel = select i1 %cond, float -4.0, float 3.0
307 %bo = frem float 5.0, %sel
308 store float %bo, ptr addrspace(1) %p, align 4