1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -march=amdgcn -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefix=GCN %s
3 ; RUN: llc -march=amdgcn -mcpu=gfx902 -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefix=GFX9 %s
5 define amdgpu_kernel void @add1(ptr addrspace(1) nocapture %arg) {
8 ; GCN-NEXT: s_load_dwordx2 s[0:1], s[0:1], 0x9
9 ; GCN-NEXT: s_mov_b32 s3, 0xf000
10 ; GCN-NEXT: s_mov_b32 s2, 0
11 ; GCN-NEXT: v_lshlrev_b32_e32 v2, 2, v0
12 ; GCN-NEXT: v_mov_b32_e32 v3, 0
13 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
14 ; GCN-NEXT: buffer_load_dword v4, v[2:3], s[0:3], 0 addr64
15 ; GCN-NEXT: v_cmp_gt_u32_e32 vcc, v0, v1
16 ; GCN-NEXT: s_waitcnt vmcnt(0)
17 ; GCN-NEXT: v_addc_u32_e32 v0, vcc, 0, v4, vcc
18 ; GCN-NEXT: buffer_store_dword v0, v[2:3], s[0:3], 0 addr64
22 ; GFX9: ; %bb.0: ; %bb
23 ; GFX9-NEXT: s_load_dwordx2 s[0:1], s[0:1], 0x24
24 ; GFX9-NEXT: v_lshlrev_b32_e32 v2, 2, v0
25 ; GFX9-NEXT: v_cmp_gt_u32_e32 vcc, v0, v1
26 ; GFX9-NEXT: s_waitcnt lgkmcnt(0)
27 ; GFX9-NEXT: global_load_dword v3, v2, s[0:1]
28 ; GFX9-NEXT: s_waitcnt vmcnt(0)
29 ; GFX9-NEXT: v_addc_co_u32_e32 v0, vcc, 0, v3, vcc
30 ; GFX9-NEXT: global_store_dword v2, v0, s[0:1]
33 %x = tail call i32 @llvm.amdgcn.workitem.id.x()
34 %y = tail call i32 @llvm.amdgcn.workitem.id.y()
35 %gep = getelementptr inbounds i32, ptr addrspace(1) %arg, i32 %x
36 %v = load i32, ptr addrspace(1) %gep, align 4
37 %cmp = icmp ugt i32 %x, %y
38 %ext = zext i1 %cmp to i32
39 %add = add i32 %v, %ext
40 store i32 %add, ptr addrspace(1) %gep, align 4
44 define i16 @add1_i16(ptr addrspace(1) nocapture %arg, ptr addrspace(1) nocapture %dst) {
45 ; GCN-LABEL: add1_i16:
47 ; GCN-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
48 ; GCN-NEXT: v_and_b32_e32 v2, 0x3ff, v31
49 ; GCN-NEXT: s_mov_b32 s6, 0
50 ; GCN-NEXT: v_lshlrev_b32_e32 v3, 2, v2
51 ; GCN-NEXT: v_add_i32_e32 v0, vcc, v0, v3
52 ; GCN-NEXT: v_addc_u32_e32 v1, vcc, 0, v1, vcc
53 ; GCN-NEXT: s_mov_b32 s7, 0xf000
54 ; GCN-NEXT: s_mov_b32 s4, s6
55 ; GCN-NEXT: s_mov_b32 s5, s6
56 ; GCN-NEXT: buffer_load_dword v0, v[0:1], s[4:7], 0 addr64
57 ; GCN-NEXT: v_bfe_u32 v1, v31, 10, 10
58 ; GCN-NEXT: v_cmp_gt_u32_e32 vcc, v2, v1
59 ; GCN-NEXT: s_waitcnt vmcnt(0)
60 ; GCN-NEXT: v_addc_u32_e32 v0, vcc, 0, v0, vcc
61 ; GCN-NEXT: s_setpc_b64 s[30:31]
63 ; GFX9-LABEL: add1_i16:
64 ; GFX9: ; %bb.0: ; %bb
65 ; GFX9-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
66 ; GFX9-NEXT: v_and_b32_e32 v2, 0x3ff, v31
67 ; GFX9-NEXT: v_lshlrev_b32_e32 v3, 2, v2
68 ; GFX9-NEXT: v_add_co_u32_e32 v0, vcc, v0, v3
69 ; GFX9-NEXT: v_addc_co_u32_e32 v1, vcc, 0, v1, vcc
70 ; GFX9-NEXT: global_load_dword v0, v[0:1], off
71 ; GFX9-NEXT: v_bfe_u32 v1, v31, 10, 10
72 ; GFX9-NEXT: v_cmp_gt_u32_e32 vcc, v2, v1
73 ; GFX9-NEXT: s_waitcnt vmcnt(0)
74 ; GFX9-NEXT: v_addc_co_u32_e32 v0, vcc, 0, v0, vcc
75 ; GFX9-NEXT: s_setpc_b64 s[30:31]
77 %x = tail call i32 @llvm.amdgcn.workitem.id.x()
78 %y = tail call i32 @llvm.amdgcn.workitem.id.y()
79 %gep = getelementptr inbounds i32, ptr addrspace(1) %arg, i32 %x
80 %v = load i32, ptr addrspace(1) %gep, align 4
81 %cmp = icmp ugt i32 %x, %y
82 %ext = zext i1 %cmp to i32
83 %add = add i32 %v, %ext
84 %trunc = trunc i32 %add to i16
88 define amdgpu_kernel void @sub1(ptr addrspace(1) nocapture %arg) {
91 ; GCN-NEXT: s_load_dwordx2 s[0:1], s[0:1], 0x9
92 ; GCN-NEXT: s_mov_b32 s3, 0xf000
93 ; GCN-NEXT: s_mov_b32 s2, 0
94 ; GCN-NEXT: v_lshlrev_b32_e32 v2, 2, v0
95 ; GCN-NEXT: v_mov_b32_e32 v3, 0
96 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
97 ; GCN-NEXT: buffer_load_dword v4, v[2:3], s[0:3], 0 addr64
98 ; GCN-NEXT: v_cmp_gt_u32_e32 vcc, v0, v1
99 ; GCN-NEXT: s_waitcnt vmcnt(0)
100 ; GCN-NEXT: v_subbrev_u32_e32 v0, vcc, 0, v4, vcc
101 ; GCN-NEXT: buffer_store_dword v0, v[2:3], s[0:3], 0 addr64
105 ; GFX9: ; %bb.0: ; %bb
106 ; GFX9-NEXT: s_load_dwordx2 s[0:1], s[0:1], 0x24
107 ; GFX9-NEXT: v_lshlrev_b32_e32 v2, 2, v0
108 ; GFX9-NEXT: v_cmp_gt_u32_e32 vcc, v0, v1
109 ; GFX9-NEXT: s_waitcnt lgkmcnt(0)
110 ; GFX9-NEXT: global_load_dword v3, v2, s[0:1]
111 ; GFX9-NEXT: s_waitcnt vmcnt(0)
112 ; GFX9-NEXT: v_subbrev_co_u32_e32 v0, vcc, 0, v3, vcc
113 ; GFX9-NEXT: global_store_dword v2, v0, s[0:1]
114 ; GFX9-NEXT: s_endpgm
116 %x = tail call i32 @llvm.amdgcn.workitem.id.x()
117 %y = tail call i32 @llvm.amdgcn.workitem.id.y()
118 %gep = getelementptr inbounds i32, ptr addrspace(1) %arg, i32 %x
119 %v = load i32, ptr addrspace(1) %gep, align 4
120 %cmp = icmp ugt i32 %x, %y
121 %ext = sext i1 %cmp to i32
122 %add = add i32 %v, %ext
123 store i32 %add, ptr addrspace(1) %gep, align 4
127 define amdgpu_kernel void @add_adde(ptr addrspace(1) nocapture %arg, i32 %a) {
128 ; GCN-LABEL: add_adde:
129 ; GCN: ; %bb.0: ; %bb
130 ; GCN-NEXT: s_load_dwordx2 s[4:5], s[0:1], 0x9
131 ; GCN-NEXT: s_load_dword s0, s[0:1], 0xb
132 ; GCN-NEXT: s_mov_b32 s7, 0xf000
133 ; GCN-NEXT: s_mov_b32 s6, 0
134 ; GCN-NEXT: v_lshlrev_b32_e32 v2, 2, v0
135 ; GCN-NEXT: v_mov_b32_e32 v3, 0
136 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
137 ; GCN-NEXT: buffer_load_dword v4, v[2:3], s[4:7], 0 addr64
138 ; GCN-NEXT: v_mov_b32_e32 v5, s0
139 ; GCN-NEXT: v_cmp_gt_u32_e32 vcc, v0, v1
140 ; GCN-NEXT: s_waitcnt vmcnt(0)
141 ; GCN-NEXT: v_addc_u32_e32 v0, vcc, v5, v4, vcc
142 ; GCN-NEXT: buffer_store_dword v0, v[2:3], s[4:7], 0 addr64
145 ; GFX9-LABEL: add_adde:
146 ; GFX9: ; %bb.0: ; %bb
147 ; GFX9-NEXT: s_load_dwordx2 s[2:3], s[0:1], 0x24
148 ; GFX9-NEXT: s_load_dword s4, s[0:1], 0x2c
149 ; GFX9-NEXT: v_lshlrev_b32_e32 v2, 2, v0
150 ; GFX9-NEXT: v_cmp_gt_u32_e32 vcc, v0, v1
151 ; GFX9-NEXT: s_waitcnt lgkmcnt(0)
152 ; GFX9-NEXT: global_load_dword v3, v2, s[2:3]
153 ; GFX9-NEXT: v_mov_b32_e32 v4, s4
154 ; GFX9-NEXT: s_waitcnt vmcnt(0)
155 ; GFX9-NEXT: v_addc_co_u32_e32 v0, vcc, v4, v3, vcc
156 ; GFX9-NEXT: global_store_dword v2, v0, s[2:3]
157 ; GFX9-NEXT: s_endpgm
159 %x = tail call i32 @llvm.amdgcn.workitem.id.x()
160 %y = tail call i32 @llvm.amdgcn.workitem.id.y()
161 %gep = getelementptr inbounds i32, ptr addrspace(1) %arg, i32 %x
162 %v = load i32, ptr addrspace(1) %gep, align 4
163 %cmp = icmp ugt i32 %x, %y
164 %ext = zext i1 %cmp to i32
165 %adde = add i32 %v, %ext
166 %add2 = add i32 %adde, %a
167 store i32 %add2, ptr addrspace(1) %gep, align 4
171 define amdgpu_kernel void @adde_add(ptr addrspace(1) nocapture %arg, i32 %a) {
172 ; GCN-LABEL: adde_add:
173 ; GCN: ; %bb.0: ; %bb
174 ; GCN-NEXT: s_load_dwordx2 s[4:5], s[0:1], 0x9
175 ; GCN-NEXT: s_load_dword s0, s[0:1], 0xb
176 ; GCN-NEXT: s_mov_b32 s7, 0xf000
177 ; GCN-NEXT: s_mov_b32 s6, 0
178 ; GCN-NEXT: v_lshlrev_b32_e32 v2, 2, v0
179 ; GCN-NEXT: v_mov_b32_e32 v3, 0
180 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
181 ; GCN-NEXT: buffer_load_dword v4, v[2:3], s[4:7], 0 addr64
182 ; GCN-NEXT: v_mov_b32_e32 v5, s0
183 ; GCN-NEXT: v_cmp_gt_u32_e32 vcc, v0, v1
184 ; GCN-NEXT: s_waitcnt vmcnt(0)
185 ; GCN-NEXT: v_addc_u32_e32 v0, vcc, v4, v5, vcc
186 ; GCN-NEXT: buffer_store_dword v0, v[2:3], s[4:7], 0 addr64
189 ; GFX9-LABEL: adde_add:
190 ; GFX9: ; %bb.0: ; %bb
191 ; GFX9-NEXT: s_load_dwordx2 s[2:3], s[0:1], 0x24
192 ; GFX9-NEXT: s_load_dword s4, s[0:1], 0x2c
193 ; GFX9-NEXT: v_lshlrev_b32_e32 v2, 2, v0
194 ; GFX9-NEXT: v_cmp_gt_u32_e32 vcc, v0, v1
195 ; GFX9-NEXT: s_waitcnt lgkmcnt(0)
196 ; GFX9-NEXT: global_load_dword v3, v2, s[2:3]
197 ; GFX9-NEXT: v_mov_b32_e32 v4, s4
198 ; GFX9-NEXT: s_waitcnt vmcnt(0)
199 ; GFX9-NEXT: v_addc_co_u32_e32 v0, vcc, v3, v4, vcc
200 ; GFX9-NEXT: global_store_dword v2, v0, s[2:3]
201 ; GFX9-NEXT: s_endpgm
203 %x = tail call i32 @llvm.amdgcn.workitem.id.x()
204 %y = tail call i32 @llvm.amdgcn.workitem.id.y()
205 %gep = getelementptr inbounds i32, ptr addrspace(1) %arg, i32 %x
206 %v = load i32, ptr addrspace(1) %gep, align 4
207 %cmp = icmp ugt i32 %x, %y
208 %ext = zext i1 %cmp to i32
209 %add = add i32 %v, %a
210 %adde = add i32 %add, %ext
211 store i32 %adde, ptr addrspace(1) %gep, align 4
215 define amdgpu_kernel void @sub_sube(ptr addrspace(1) nocapture %arg, i32 %a) {
216 ; GCN-LABEL: sub_sube:
217 ; GCN: ; %bb.0: ; %bb
218 ; GCN-NEXT: s_load_dwordx2 s[4:5], s[0:1], 0x9
219 ; GCN-NEXT: s_load_dword s0, s[0:1], 0xb
220 ; GCN-NEXT: s_mov_b32 s7, 0xf000
221 ; GCN-NEXT: s_mov_b32 s6, 0
222 ; GCN-NEXT: v_lshlrev_b32_e32 v2, 2, v0
223 ; GCN-NEXT: v_mov_b32_e32 v3, 0
224 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
225 ; GCN-NEXT: buffer_load_dword v4, v[2:3], s[4:7], 0 addr64
226 ; GCN-NEXT: v_mov_b32_e32 v5, s0
227 ; GCN-NEXT: v_cmp_gt_u32_e32 vcc, v0, v1
228 ; GCN-NEXT: s_waitcnt vmcnt(0)
229 ; GCN-NEXT: v_subb_u32_e32 v0, vcc, v4, v5, vcc
230 ; GCN-NEXT: buffer_store_dword v0, v[2:3], s[4:7], 0 addr64
233 ; GFX9-LABEL: sub_sube:
234 ; GFX9: ; %bb.0: ; %bb
235 ; GFX9-NEXT: s_load_dwordx2 s[2:3], s[0:1], 0x24
236 ; GFX9-NEXT: s_load_dword s4, s[0:1], 0x2c
237 ; GFX9-NEXT: v_lshlrev_b32_e32 v2, 2, v0
238 ; GFX9-NEXT: v_cmp_gt_u32_e32 vcc, v0, v1
239 ; GFX9-NEXT: s_waitcnt lgkmcnt(0)
240 ; GFX9-NEXT: global_load_dword v3, v2, s[2:3]
241 ; GFX9-NEXT: v_mov_b32_e32 v4, s4
242 ; GFX9-NEXT: s_waitcnt vmcnt(0)
243 ; GFX9-NEXT: v_subb_co_u32_e32 v0, vcc, v3, v4, vcc
244 ; GFX9-NEXT: global_store_dword v2, v0, s[2:3]
245 ; GFX9-NEXT: s_endpgm
247 %x = tail call i32 @llvm.amdgcn.workitem.id.x()
248 %y = tail call i32 @llvm.amdgcn.workitem.id.y()
249 %gep = getelementptr inbounds i32, ptr addrspace(1) %arg, i32 %x
250 %v = load i32, ptr addrspace(1) %gep, align 4
251 %cmp = icmp ugt i32 %x, %y
252 %ext = sext i1 %cmp to i32
253 %adde = add i32 %v, %ext
254 %sub = sub i32 %adde, %a
255 store i32 %sub, ptr addrspace(1) %gep, align 4
259 define amdgpu_kernel void @sub_sube_commuted(ptr addrspace(1) nocapture %arg, i32 %a) {
260 ; GCN-LABEL: sub_sube_commuted:
261 ; GCN: ; %bb.0: ; %bb
262 ; GCN-NEXT: s_load_dwordx2 s[4:5], s[0:1], 0x9
263 ; GCN-NEXT: s_load_dword s0, s[0:1], 0xb
264 ; GCN-NEXT: s_mov_b32 s7, 0xf000
265 ; GCN-NEXT: s_mov_b32 s6, 0
266 ; GCN-NEXT: v_lshlrev_b32_e32 v2, 2, v0
267 ; GCN-NEXT: v_mov_b32_e32 v3, 0
268 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
269 ; GCN-NEXT: buffer_load_dword v4, v[2:3], s[4:7], 0 addr64
270 ; GCN-NEXT: v_cmp_gt_u32_e32 vcc, v0, v1
271 ; GCN-NEXT: s_waitcnt vmcnt(0)
272 ; GCN-NEXT: v_subbrev_u32_e32 v0, vcc, 0, v4, vcc
273 ; GCN-NEXT: v_sub_i32_e32 v0, vcc, s0, v0
274 ; GCN-NEXT: v_add_i32_e32 v0, vcc, 0x64, v0
275 ; GCN-NEXT: buffer_store_dword v0, v[2:3], s[4:7], 0 addr64
278 ; GFX9-LABEL: sub_sube_commuted:
279 ; GFX9: ; %bb.0: ; %bb
280 ; GFX9-NEXT: s_load_dwordx2 s[2:3], s[0:1], 0x24
281 ; GFX9-NEXT: s_load_dword s4, s[0:1], 0x2c
282 ; GFX9-NEXT: v_lshlrev_b32_e32 v2, 2, v0
283 ; GFX9-NEXT: v_cmp_gt_u32_e32 vcc, v0, v1
284 ; GFX9-NEXT: s_waitcnt lgkmcnt(0)
285 ; GFX9-NEXT: global_load_dword v3, v2, s[2:3]
286 ; GFX9-NEXT: s_waitcnt vmcnt(0)
287 ; GFX9-NEXT: v_subbrev_co_u32_e32 v0, vcc, 0, v3, vcc
288 ; GFX9-NEXT: v_sub_u32_e32 v0, s4, v0
289 ; GFX9-NEXT: v_add_u32_e32 v0, 0x64, v0
290 ; GFX9-NEXT: global_store_dword v2, v0, s[2:3]
291 ; GFX9-NEXT: s_endpgm
293 %x = tail call i32 @llvm.amdgcn.workitem.id.x()
294 %y = tail call i32 @llvm.amdgcn.workitem.id.y()
295 %gep = getelementptr inbounds i32, ptr addrspace(1) %arg, i32 %x
296 %v = load i32, ptr addrspace(1) %gep, align 4
297 %cmp = icmp ugt i32 %x, %y
298 %ext = sext i1 %cmp to i32
299 %adde = add i32 %v, %ext
300 %sub = sub i32 %adde, %a
301 %sub2 = sub i32 100, %sub
302 store i32 %sub2, ptr addrspace(1) %gep, align 4
306 define amdgpu_kernel void @sube_sub(ptr addrspace(1) nocapture %arg, i32 %a) {
307 ; GCN-LABEL: sube_sub:
308 ; GCN: ; %bb.0: ; %bb
309 ; GCN-NEXT: s_load_dwordx2 s[4:5], s[0:1], 0x9
310 ; GCN-NEXT: s_load_dword s0, s[0:1], 0xb
311 ; GCN-NEXT: s_mov_b32 s7, 0xf000
312 ; GCN-NEXT: s_mov_b32 s6, 0
313 ; GCN-NEXT: v_lshlrev_b32_e32 v2, 2, v0
314 ; GCN-NEXT: v_mov_b32_e32 v3, 0
315 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
316 ; GCN-NEXT: buffer_load_dword v4, v[2:3], s[4:7], 0 addr64
317 ; GCN-NEXT: v_mov_b32_e32 v5, s0
318 ; GCN-NEXT: v_cmp_gt_u32_e32 vcc, v0, v1
319 ; GCN-NEXT: s_waitcnt vmcnt(0)
320 ; GCN-NEXT: v_subb_u32_e32 v0, vcc, v4, v5, vcc
321 ; GCN-NEXT: buffer_store_dword v0, v[2:3], s[4:7], 0 addr64
324 ; GFX9-LABEL: sube_sub:
325 ; GFX9: ; %bb.0: ; %bb
326 ; GFX9-NEXT: s_load_dwordx2 s[2:3], s[0:1], 0x24
327 ; GFX9-NEXT: s_load_dword s4, s[0:1], 0x2c
328 ; GFX9-NEXT: v_lshlrev_b32_e32 v2, 2, v0
329 ; GFX9-NEXT: v_cmp_gt_u32_e32 vcc, v0, v1
330 ; GFX9-NEXT: s_waitcnt lgkmcnt(0)
331 ; GFX9-NEXT: global_load_dword v3, v2, s[2:3]
332 ; GFX9-NEXT: v_mov_b32_e32 v4, s4
333 ; GFX9-NEXT: s_waitcnt vmcnt(0)
334 ; GFX9-NEXT: v_subb_co_u32_e32 v0, vcc, v3, v4, vcc
335 ; GFX9-NEXT: global_store_dword v2, v0, s[2:3]
336 ; GFX9-NEXT: s_endpgm
338 %x = tail call i32 @llvm.amdgcn.workitem.id.x()
339 %y = tail call i32 @llvm.amdgcn.workitem.id.y()
340 %gep = getelementptr inbounds i32, ptr addrspace(1) %arg, i32 %x
341 %v = load i32, ptr addrspace(1) %gep, align 4
342 %cmp = icmp ugt i32 %x, %y
343 %ext = sext i1 %cmp to i32
344 %sub = sub i32 %v, %a
345 %adde = add i32 %sub, %ext
346 store i32 %adde, ptr addrspace(1) %gep, align 4
350 define amdgpu_kernel void @zext_flclass(ptr addrspace(1) nocapture %arg, float %x) {
351 ; GCN-LABEL: zext_flclass:
352 ; GCN: ; %bb.0: ; %bb
353 ; GCN-NEXT: s_load_dwordx2 s[4:5], s[0:1], 0x9
354 ; GCN-NEXT: s_load_dword s0, s[0:1], 0xb
355 ; GCN-NEXT: s_mov_b32 s7, 0xf000
356 ; GCN-NEXT: s_mov_b32 s6, 0
357 ; GCN-NEXT: v_lshlrev_b32_e32 v0, 2, v0
358 ; GCN-NEXT: v_mov_b32_e32 v1, 0
359 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
360 ; GCN-NEXT: buffer_load_dword v2, v[0:1], s[4:7], 0 addr64
361 ; GCN-NEXT: v_mov_b32_e32 v3, 0x260
362 ; GCN-NEXT: v_cmp_class_f32_e32 vcc, s0, v3
363 ; GCN-NEXT: s_waitcnt vmcnt(0)
364 ; GCN-NEXT: v_addc_u32_e32 v2, vcc, 0, v2, vcc
365 ; GCN-NEXT: buffer_store_dword v2, v[0:1], s[4:7], 0 addr64
368 ; GFX9-LABEL: zext_flclass:
369 ; GFX9: ; %bb.0: ; %bb
370 ; GFX9-NEXT: s_load_dwordx2 s[2:3], s[0:1], 0x24
371 ; GFX9-NEXT: s_load_dword s4, s[0:1], 0x2c
372 ; GFX9-NEXT: v_lshlrev_b32_e32 v0, 2, v0
373 ; GFX9-NEXT: v_mov_b32_e32 v2, 0x260
374 ; GFX9-NEXT: s_waitcnt lgkmcnt(0)
375 ; GFX9-NEXT: global_load_dword v1, v0, s[2:3]
376 ; GFX9-NEXT: v_cmp_class_f32_e32 vcc, s4, v2
377 ; GFX9-NEXT: s_waitcnt vmcnt(0)
378 ; GFX9-NEXT: v_addc_co_u32_e32 v1, vcc, 0, v1, vcc
379 ; GFX9-NEXT: global_store_dword v0, v1, s[2:3]
380 ; GFX9-NEXT: s_endpgm
382 %id = tail call i32 @llvm.amdgcn.workitem.id.x()
383 %gep = getelementptr inbounds i32, ptr addrspace(1) %arg, i32 %id
384 %v = load i32, ptr addrspace(1) %gep, align 4
385 %cmp = tail call zeroext i1 @llvm.amdgcn.class.f32(float %x, i32 608)
386 %ext = zext i1 %cmp to i32
387 %add = add i32 %v, %ext
388 store i32 %add, ptr addrspace(1) %gep, align 4
392 define amdgpu_kernel void @sext_flclass(ptr addrspace(1) nocapture %arg, float %x) {
393 ; GCN-LABEL: sext_flclass:
394 ; GCN: ; %bb.0: ; %bb
395 ; GCN-NEXT: s_load_dwordx2 s[4:5], s[0:1], 0x9
396 ; GCN-NEXT: s_load_dword s0, s[0:1], 0xb
397 ; GCN-NEXT: s_mov_b32 s7, 0xf000
398 ; GCN-NEXT: s_mov_b32 s6, 0
399 ; GCN-NEXT: v_lshlrev_b32_e32 v0, 2, v0
400 ; GCN-NEXT: v_mov_b32_e32 v1, 0
401 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
402 ; GCN-NEXT: buffer_load_dword v2, v[0:1], s[4:7], 0 addr64
403 ; GCN-NEXT: v_mov_b32_e32 v3, 0x260
404 ; GCN-NEXT: v_cmp_class_f32_e32 vcc, s0, v3
405 ; GCN-NEXT: s_waitcnt vmcnt(0)
406 ; GCN-NEXT: v_subbrev_u32_e32 v2, vcc, 0, v2, vcc
407 ; GCN-NEXT: buffer_store_dword v2, v[0:1], s[4:7], 0 addr64
410 ; GFX9-LABEL: sext_flclass:
411 ; GFX9: ; %bb.0: ; %bb
412 ; GFX9-NEXT: s_load_dwordx2 s[2:3], s[0:1], 0x24
413 ; GFX9-NEXT: s_load_dword s4, s[0:1], 0x2c
414 ; GFX9-NEXT: v_lshlrev_b32_e32 v0, 2, v0
415 ; GFX9-NEXT: v_mov_b32_e32 v2, 0x260
416 ; GFX9-NEXT: s_waitcnt lgkmcnt(0)
417 ; GFX9-NEXT: global_load_dword v1, v0, s[2:3]
418 ; GFX9-NEXT: v_cmp_class_f32_e32 vcc, s4, v2
419 ; GFX9-NEXT: s_waitcnt vmcnt(0)
420 ; GFX9-NEXT: v_subbrev_co_u32_e32 v1, vcc, 0, v1, vcc
421 ; GFX9-NEXT: global_store_dword v0, v1, s[2:3]
422 ; GFX9-NEXT: s_endpgm
424 %id = tail call i32 @llvm.amdgcn.workitem.id.x()
425 %gep = getelementptr inbounds i32, ptr addrspace(1) %arg, i32 %id
426 %v = load i32, ptr addrspace(1) %gep, align 4
427 %cmp = tail call zeroext i1 @llvm.amdgcn.class.f32(float %x, i32 608)
428 %ext = sext i1 %cmp to i32
429 %add = add i32 %v, %ext
430 store i32 %add, ptr addrspace(1) %gep, align 4
434 define amdgpu_kernel void @add_and(ptr addrspace(1) nocapture %arg) {
435 ; GCN-LABEL: add_and:
436 ; GCN: ; %bb.0: ; %bb
437 ; GCN-NEXT: s_load_dwordx2 s[0:1], s[0:1], 0x9
438 ; GCN-NEXT: s_mov_b32 s3, 0xf000
439 ; GCN-NEXT: s_mov_b32 s2, 0
440 ; GCN-NEXT: v_lshlrev_b32_e32 v2, 2, v0
441 ; GCN-NEXT: v_mov_b32_e32 v3, 0
442 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
443 ; GCN-NEXT: buffer_load_dword v4, v[2:3], s[0:3], 0 addr64
444 ; GCN-NEXT: v_max_u32_e32 v1, 1, v1
445 ; GCN-NEXT: v_cmp_lt_u32_e32 vcc, v1, v0
446 ; GCN-NEXT: s_waitcnt vmcnt(0)
447 ; GCN-NEXT: v_addc_u32_e32 v0, vcc, 0, v4, vcc
448 ; GCN-NEXT: buffer_store_dword v0, v[2:3], s[0:3], 0 addr64
451 ; GFX9-LABEL: add_and:
452 ; GFX9: ; %bb.0: ; %bb
453 ; GFX9-NEXT: s_load_dwordx2 s[0:1], s[0:1], 0x24
454 ; GFX9-NEXT: v_lshlrev_b32_e32 v2, 2, v0
455 ; GFX9-NEXT: v_max_u32_e32 v1, 1, v1
456 ; GFX9-NEXT: v_cmp_lt_u32_e32 vcc, v1, v0
457 ; GFX9-NEXT: s_waitcnt lgkmcnt(0)
458 ; GFX9-NEXT: global_load_dword v3, v2, s[0:1]
459 ; GFX9-NEXT: s_waitcnt vmcnt(0)
460 ; GFX9-NEXT: v_addc_co_u32_e32 v0, vcc, 0, v3, vcc
461 ; GFX9-NEXT: global_store_dword v2, v0, s[0:1]
462 ; GFX9-NEXT: s_endpgm
464 %x = tail call i32 @llvm.amdgcn.workitem.id.x()
465 %y = tail call i32 @llvm.amdgcn.workitem.id.y()
466 %gep = getelementptr inbounds i32, ptr addrspace(1) %arg, i32 %x
467 %v = load i32, ptr addrspace(1) %gep, align 4
468 %cmp1 = icmp ugt i32 %x, %y
469 %cmp2 = icmp ugt i32 %x, 1
470 %cmp = and i1 %cmp1, %cmp2
471 %ext = zext i1 %cmp to i32
472 %add = add i32 %v, %ext
473 store i32 %add, ptr addrspace(1) %gep, align 4
477 ; sub x, sext (setcc) => addcarry x, 0, setcc
478 define amdgpu_kernel void @cmp_sub_sext(ptr addrspace(1) nocapture %arg) {
479 ; GCN-LABEL: cmp_sub_sext:
480 ; GCN: ; %bb.0: ; %bb
481 ; GCN-NEXT: s_load_dwordx2 s[0:1], s[0:1], 0x9
482 ; GCN-NEXT: s_mov_b32 s3, 0xf000
483 ; GCN-NEXT: s_mov_b32 s2, 0
484 ; GCN-NEXT: v_lshlrev_b32_e32 v2, 2, v0
485 ; GCN-NEXT: v_mov_b32_e32 v3, 0
486 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
487 ; GCN-NEXT: buffer_load_dword v4, v[2:3], s[0:3], 0 addr64
488 ; GCN-NEXT: v_cmp_gt_u32_e32 vcc, v0, v1
489 ; GCN-NEXT: s_waitcnt vmcnt(0)
490 ; GCN-NEXT: v_addc_u32_e32 v0, vcc, 0, v4, vcc
491 ; GCN-NEXT: buffer_store_dword v0, v[2:3], s[0:3], 0 addr64
494 ; GFX9-LABEL: cmp_sub_sext:
495 ; GFX9: ; %bb.0: ; %bb
496 ; GFX9-NEXT: s_load_dwordx2 s[0:1], s[0:1], 0x24
497 ; GFX9-NEXT: v_lshlrev_b32_e32 v2, 2, v0
498 ; GFX9-NEXT: v_cmp_gt_u32_e32 vcc, v0, v1
499 ; GFX9-NEXT: s_waitcnt lgkmcnt(0)
500 ; GFX9-NEXT: global_load_dword v3, v2, s[0:1]
501 ; GFX9-NEXT: s_waitcnt vmcnt(0)
502 ; GFX9-NEXT: v_addc_co_u32_e32 v0, vcc, 0, v3, vcc
503 ; GFX9-NEXT: global_store_dword v2, v0, s[0:1]
504 ; GFX9-NEXT: s_endpgm
506 %x = tail call i32 @llvm.amdgcn.workitem.id.x()
507 %y = tail call i32 @llvm.amdgcn.workitem.id.y()
508 %gep = getelementptr inbounds i32, ptr addrspace(1) %arg, i32 %x
509 %v = load i32, ptr addrspace(1) %gep, align 4
510 %cmp = icmp ugt i32 %x, %y
511 %ext = sext i1 %cmp to i32
512 %add = sub i32 %v, %ext
513 store i32 %add, ptr addrspace(1) %gep, align 4
517 ; sub x, zext (setcc) => subcarry x, 0, setcc
518 define amdgpu_kernel void @cmp_sub_zext(ptr addrspace(1) nocapture %arg) {
519 ; GCN-LABEL: cmp_sub_zext:
520 ; GCN: ; %bb.0: ; %bb
521 ; GCN-NEXT: s_load_dwordx2 s[0:1], s[0:1], 0x9
522 ; GCN-NEXT: s_mov_b32 s3, 0xf000
523 ; GCN-NEXT: s_mov_b32 s2, 0
524 ; GCN-NEXT: v_lshlrev_b32_e32 v2, 2, v0
525 ; GCN-NEXT: v_mov_b32_e32 v3, 0
526 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
527 ; GCN-NEXT: buffer_load_dword v4, v[2:3], s[0:3], 0 addr64
528 ; GCN-NEXT: v_cmp_gt_u32_e32 vcc, v0, v1
529 ; GCN-NEXT: s_waitcnt vmcnt(0)
530 ; GCN-NEXT: v_subbrev_u32_e32 v0, vcc, 0, v4, vcc
531 ; GCN-NEXT: buffer_store_dword v0, v[2:3], s[0:3], 0 addr64
534 ; GFX9-LABEL: cmp_sub_zext:
535 ; GFX9: ; %bb.0: ; %bb
536 ; GFX9-NEXT: s_load_dwordx2 s[0:1], s[0:1], 0x24
537 ; GFX9-NEXT: v_lshlrev_b32_e32 v2, 2, v0
538 ; GFX9-NEXT: v_cmp_gt_u32_e32 vcc, v0, v1
539 ; GFX9-NEXT: s_waitcnt lgkmcnt(0)
540 ; GFX9-NEXT: global_load_dword v3, v2, s[0:1]
541 ; GFX9-NEXT: s_waitcnt vmcnt(0)
542 ; GFX9-NEXT: v_subbrev_co_u32_e32 v0, vcc, 0, v3, vcc
543 ; GFX9-NEXT: global_store_dword v2, v0, s[0:1]
544 ; GFX9-NEXT: s_endpgm
546 %x = tail call i32 @llvm.amdgcn.workitem.id.x()
547 %y = tail call i32 @llvm.amdgcn.workitem.id.y()
548 %gep = getelementptr inbounds i32, ptr addrspace(1) %arg, i32 %x
549 %v = load i32, ptr addrspace(1) %gep, align 4
550 %cmp = icmp ugt i32 %x, %y
551 %ext = zext i1 %cmp to i32
552 %add = sub i32 %v, %ext
553 store i32 %add, ptr addrspace(1) %gep, align 4
557 define amdgpu_kernel void @sub_addcarry(ptr addrspace(1) nocapture %arg, i32 %a) {
558 ; GCN-LABEL: sub_addcarry:
559 ; GCN: ; %bb.0: ; %bb
560 ; GCN-NEXT: s_load_dwordx2 s[4:5], s[0:1], 0x9
561 ; GCN-NEXT: s_load_dword s0, s[0:1], 0xb
562 ; GCN-NEXT: s_mov_b32 s7, 0xf000
563 ; GCN-NEXT: s_mov_b32 s6, 0
564 ; GCN-NEXT: v_lshlrev_b32_e32 v2, 2, v0
565 ; GCN-NEXT: v_mov_b32_e32 v3, 0
566 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
567 ; GCN-NEXT: buffer_load_dword v4, v[2:3], s[4:7], 0 addr64
568 ; GCN-NEXT: v_cmp_gt_u32_e32 vcc, v0, v1
569 ; GCN-NEXT: s_waitcnt vmcnt(0)
570 ; GCN-NEXT: v_addc_u32_e32 v0, vcc, 0, v4, vcc
571 ; GCN-NEXT: v_subrev_i32_e32 v0, vcc, s0, v0
572 ; GCN-NEXT: buffer_store_dword v0, v[2:3], s[4:7], 0 addr64
575 ; GFX9-LABEL: sub_addcarry:
576 ; GFX9: ; %bb.0: ; %bb
577 ; GFX9-NEXT: s_load_dwordx2 s[2:3], s[0:1], 0x24
578 ; GFX9-NEXT: s_load_dword s4, s[0:1], 0x2c
579 ; GFX9-NEXT: v_lshlrev_b32_e32 v2, 2, v0
580 ; GFX9-NEXT: v_cmp_gt_u32_e32 vcc, v0, v1
581 ; GFX9-NEXT: s_waitcnt lgkmcnt(0)
582 ; GFX9-NEXT: global_load_dword v3, v2, s[2:3]
583 ; GFX9-NEXT: s_waitcnt vmcnt(0)
584 ; GFX9-NEXT: v_addc_co_u32_e32 v0, vcc, 0, v3, vcc
585 ; GFX9-NEXT: v_subrev_u32_e32 v0, s4, v0
586 ; GFX9-NEXT: global_store_dword v2, v0, s[2:3]
587 ; GFX9-NEXT: s_endpgm
589 %x = tail call i32 @llvm.amdgcn.workitem.id.x()
590 %y = tail call i32 @llvm.amdgcn.workitem.id.y()
591 %gep = getelementptr inbounds i32, ptr addrspace(1) %arg, i32 %x
592 %v = load i32, ptr addrspace(1) %gep, align 4
593 %cmp = icmp ugt i32 %x, %y
594 %ext = zext i1 %cmp to i32
595 %adde = add i32 %v, %ext
596 %add2 = sub i32 %adde, %a
597 store i32 %add2, ptr addrspace(1) %gep, align 4
601 define amdgpu_kernel void @sub_subcarry(ptr addrspace(1) nocapture %arg, i32 %a) {
602 ; GCN-LABEL: sub_subcarry:
603 ; GCN: ; %bb.0: ; %bb
604 ; GCN-NEXT: s_load_dwordx2 s[4:5], s[0:1], 0x9
605 ; GCN-NEXT: s_load_dword s0, s[0:1], 0xb
606 ; GCN-NEXT: s_mov_b32 s7, 0xf000
607 ; GCN-NEXT: s_mov_b32 s6, 0
608 ; GCN-NEXT: v_lshlrev_b32_e32 v2, 2, v0
609 ; GCN-NEXT: v_mov_b32_e32 v3, 0
610 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
611 ; GCN-NEXT: buffer_load_dword v4, v[2:3], s[4:7], 0 addr64
612 ; GCN-NEXT: v_mov_b32_e32 v5, s0
613 ; GCN-NEXT: v_cmp_gt_u32_e32 vcc, v0, v1
614 ; GCN-NEXT: s_waitcnt vmcnt(0)
615 ; GCN-NEXT: v_subb_u32_e32 v0, vcc, v4, v5, vcc
616 ; GCN-NEXT: buffer_store_dword v0, v[2:3], s[4:7], 0 addr64
619 ; GFX9-LABEL: sub_subcarry:
620 ; GFX9: ; %bb.0: ; %bb
621 ; GFX9-NEXT: s_load_dwordx2 s[2:3], s[0:1], 0x24
622 ; GFX9-NEXT: s_load_dword s4, s[0:1], 0x2c
623 ; GFX9-NEXT: v_lshlrev_b32_e32 v2, 2, v0
624 ; GFX9-NEXT: v_cmp_gt_u32_e32 vcc, v0, v1
625 ; GFX9-NEXT: s_waitcnt lgkmcnt(0)
626 ; GFX9-NEXT: global_load_dword v3, v2, s[2:3]
627 ; GFX9-NEXT: v_mov_b32_e32 v4, s4
628 ; GFX9-NEXT: s_waitcnt vmcnt(0)
629 ; GFX9-NEXT: v_subb_co_u32_e32 v0, vcc, v3, v4, vcc
630 ; GFX9-NEXT: global_store_dword v2, v0, s[2:3]
631 ; GFX9-NEXT: s_endpgm
633 %x = tail call i32 @llvm.amdgcn.workitem.id.x()
634 %y = tail call i32 @llvm.amdgcn.workitem.id.y()
635 %gep = getelementptr inbounds i32, ptr addrspace(1) %arg, i32 %x
636 %v = load i32, ptr addrspace(1) %gep, align 4
637 %cmp = icmp ugt i32 %x, %y
638 %ext = zext i1 %cmp to i32
639 %adde = sub i32 %v, %ext
640 %add2 = sub i32 %adde, %a
641 store i32 %add2, ptr addrspace(1) %gep, align 4
645 ; Check case where sub is commuted with zext
646 define amdgpu_kernel void @sub_zext_setcc_commute(ptr addrspace(1) nocapture %arg, i32 %a, i32%b) {
647 ; GCN-LABEL: sub_zext_setcc_commute:
648 ; GCN: ; %bb.0: ; %bb
649 ; GCN-NEXT: s_load_dwordx4 s[0:3], s[0:1], 0x9
650 ; GCN-NEXT: s_mov_b32 s7, 0xf000
651 ; GCN-NEXT: s_mov_b32 s6, 0
652 ; GCN-NEXT: v_lshlrev_b32_e32 v2, 2, v0
653 ; GCN-NEXT: v_mov_b32_e32 v3, 0
654 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
655 ; GCN-NEXT: s_mov_b64 s[4:5], s[0:1]
656 ; GCN-NEXT: buffer_load_dword v4, v[2:3], s[4:7], 0 addr64
657 ; GCN-NEXT: v_cmp_gt_u32_e32 vcc, v0, v1
658 ; GCN-NEXT: v_cndmask_b32_e64 v0, 0, 1, vcc
659 ; GCN-NEXT: s_waitcnt vmcnt(0)
660 ; GCN-NEXT: v_sub_i32_e32 v0, vcc, v0, v4
661 ; GCN-NEXT: v_add_i32_e32 v0, vcc, s2, v0
662 ; GCN-NEXT: v_subrev_i32_e32 v0, vcc, s3, v0
663 ; GCN-NEXT: buffer_store_dword v0, v[2:3], s[4:7], 0 addr64
666 ; GFX9-LABEL: sub_zext_setcc_commute:
667 ; GFX9: ; %bb.0: ; %bb
668 ; GFX9-NEXT: s_load_dwordx4 s[0:3], s[0:1], 0x24
669 ; GFX9-NEXT: v_lshlrev_b32_e32 v2, 2, v0
670 ; GFX9-NEXT: v_cmp_gt_u32_e32 vcc, v0, v1
671 ; GFX9-NEXT: v_cndmask_b32_e64 v0, 0, 1, vcc
672 ; GFX9-NEXT: s_waitcnt lgkmcnt(0)
673 ; GFX9-NEXT: global_load_dword v3, v2, s[0:1]
674 ; GFX9-NEXT: s_waitcnt vmcnt(0)
675 ; GFX9-NEXT: v_sub_u32_e32 v0, v0, v3
676 ; GFX9-NEXT: v_add_u32_e32 v0, s2, v0
677 ; GFX9-NEXT: v_subrev_u32_e32 v0, s3, v0
678 ; GFX9-NEXT: global_store_dword v2, v0, s[0:1]
679 ; GFX9-NEXT: s_endpgm
681 %x = tail call i32 @llvm.amdgcn.workitem.id.x()
682 %y = tail call i32 @llvm.amdgcn.workitem.id.y()
683 %gep = getelementptr inbounds i32, ptr addrspace(1) %arg, i32 %x
684 %v = load i32, ptr addrspace(1) %gep, align 4
685 %cmp = icmp ugt i32 %x, %y
686 %ext = zext i1 %cmp to i32
687 %adde = sub i32 %v, %ext
688 %sub = sub i32 %a, %adde
689 %sub2 = sub i32 %sub, %b
690 store i32 %sub2, ptr addrspace(1) %gep, align 4
694 ; Check case where sub is commuted with sext
695 define amdgpu_kernel void @sub_sext_setcc_commute(ptr addrspace(1) nocapture %arg, i32 %a, i32%b) {
696 ; GCN-LABEL: sub_sext_setcc_commute:
697 ; GCN: ; %bb.0: ; %bb
698 ; GCN-NEXT: s_load_dwordx4 s[0:3], s[0:1], 0x9
699 ; GCN-NEXT: s_mov_b32 s7, 0xf000
700 ; GCN-NEXT: s_mov_b32 s6, 0
701 ; GCN-NEXT: v_lshlrev_b32_e32 v2, 2, v0
702 ; GCN-NEXT: v_mov_b32_e32 v3, 0
703 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
704 ; GCN-NEXT: s_mov_b64 s[4:5], s[0:1]
705 ; GCN-NEXT: buffer_load_dword v4, v[2:3], s[4:7], 0 addr64
706 ; GCN-NEXT: v_cmp_gt_u32_e32 vcc, v0, v1
707 ; GCN-NEXT: v_cndmask_b32_e64 v0, 0, -1, vcc
708 ; GCN-NEXT: s_waitcnt vmcnt(0)
709 ; GCN-NEXT: v_sub_i32_e32 v0, vcc, v0, v4
710 ; GCN-NEXT: v_add_i32_e32 v0, vcc, s2, v0
711 ; GCN-NEXT: v_subrev_i32_e32 v0, vcc, s3, v0
712 ; GCN-NEXT: buffer_store_dword v0, v[2:3], s[4:7], 0 addr64
715 ; GFX9-LABEL: sub_sext_setcc_commute:
716 ; GFX9: ; %bb.0: ; %bb
717 ; GFX9-NEXT: s_load_dwordx4 s[0:3], s[0:1], 0x24
718 ; GFX9-NEXT: v_lshlrev_b32_e32 v2, 2, v0
719 ; GFX9-NEXT: v_cmp_gt_u32_e32 vcc, v0, v1
720 ; GFX9-NEXT: v_cndmask_b32_e64 v0, 0, -1, vcc
721 ; GFX9-NEXT: s_waitcnt lgkmcnt(0)
722 ; GFX9-NEXT: global_load_dword v3, v2, s[0:1]
723 ; GFX9-NEXT: s_waitcnt vmcnt(0)
724 ; GFX9-NEXT: v_sub_u32_e32 v0, v0, v3
725 ; GFX9-NEXT: v_add_u32_e32 v0, s2, v0
726 ; GFX9-NEXT: v_subrev_u32_e32 v0, s3, v0
727 ; GFX9-NEXT: global_store_dword v2, v0, s[0:1]
728 ; GFX9-NEXT: s_endpgm
730 %x = tail call i32 @llvm.amdgcn.workitem.id.x()
731 %y = tail call i32 @llvm.amdgcn.workitem.id.y()
732 %gep = getelementptr inbounds i32, ptr addrspace(1) %arg, i32 %x
733 %v = load i32, ptr addrspace(1) %gep, align 4
734 %cmp = icmp ugt i32 %x, %y
735 %ext = sext i1 %cmp to i32
736 %adde = sub i32 %v, %ext
737 %sub = sub i32 %a, %adde
738 %sub2 = sub i32 %sub, %b
739 store i32 %sub2, ptr addrspace(1) %gep, align 4
743 declare i1 @llvm.amdgcn.class.f32(float, i32) #0
745 declare i32 @llvm.amdgcn.workitem.id.x() #0
747 declare i32 @llvm.amdgcn.workitem.id.y() #0
749 attributes #0 = { nounwind readnone speculatable }