1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -march=amdgcn -mcpu=tahiti -verify-machineinstrs < %s | FileCheck -check-prefix=GCN %s
3 ; XUN: llc -march=amdgcn -mcpu=fiji -verify-machineinstrs < %s | FileCheck --check-prefixes=GCN,VI %s
5 ; FIXME: broken on VI because flat instructions need to be emitted
6 ; instead of addr64 equivalent of the _OFFSET variants.
8 ; Check that moving the pointer out of the resource descriptor to
9 ; vaddr works for atomics.
11 declare i32 @llvm.amdgcn.workitem.id.x() #1
13 define amdgpu_kernel void @atomic_max_i32(ptr addrspace(1) %out, ptr addrspace(1) %in, ptr addrspace(1) %x, i32 %y) #0 {
14 ; GCN-LABEL: atomic_max_i32:
16 ; GCN-NEXT: s_load_dwordx4 s[4:7], s[0:1], 0x9
17 ; GCN-NEXT: s_mov_b32 s11, 0xf000
18 ; GCN-NEXT: s_mov_b32 s10, 0
19 ; GCN-NEXT: v_lshlrev_b32_e32 v1, 3, v0
20 ; GCN-NEXT: v_mov_b32_e32 v2, 0
21 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
22 ; GCN-NEXT: s_mov_b64 s[8:9], s[6:7]
23 ; GCN-NEXT: buffer_load_dwordx2 v[1:2], v[1:2], s[8:11], 0 addr64 glc
24 ; GCN-NEXT: s_waitcnt vmcnt(0)
25 ; GCN-NEXT: v_cmp_ne_u32_e32 vcc, 1, v0
26 ; GCN-NEXT: s_and_saveexec_b64 s[2:3], vcc
27 ; GCN-NEXT: s_cbranch_execz .LBB0_4
28 ; GCN-NEXT: ; %bb.1: ; %atomic
29 ; GCN-NEXT: s_mov_b32 s8, s10
30 ; GCN-NEXT: s_mov_b32 s9, s10
31 ; GCN-NEXT: buffer_load_dword v4, v[1:2], s[8:11], 0 addr64 offset:400
32 ; GCN-NEXT: s_load_dword s2, s[0:1], 0xf
33 ; GCN-NEXT: s_mov_b64 s[0:1], 0
34 ; GCN-NEXT: .LBB0_2: ; %atomicrmw.start
35 ; GCN-NEXT: ; =>This Inner Loop Header: Depth=1
36 ; GCN-NEXT: s_waitcnt vmcnt(0) lgkmcnt(0)
37 ; GCN-NEXT: v_max_i32_e32 v3, s2, v4
38 ; GCN-NEXT: s_waitcnt expcnt(0)
39 ; GCN-NEXT: v_mov_b32_e32 v6, v4
40 ; GCN-NEXT: v_mov_b32_e32 v5, v3
41 ; GCN-NEXT: s_waitcnt vmcnt(0) lgkmcnt(0)
42 ; GCN-NEXT: buffer_atomic_cmpswap v[5:6], v[1:2], s[8:11], 0 addr64 offset:400 glc
43 ; GCN-NEXT: s_waitcnt vmcnt(0)
44 ; GCN-NEXT: buffer_wbinvl1
45 ; GCN-NEXT: v_cmp_eq_u32_e32 vcc, v5, v4
46 ; GCN-NEXT: s_or_b64 s[0:1], vcc, s[0:1]
47 ; GCN-NEXT: v_mov_b32_e32 v4, v5
48 ; GCN-NEXT: s_andn2_b64 exec, exec, s[0:1]
49 ; GCN-NEXT: s_cbranch_execnz .LBB0_2
50 ; GCN-NEXT: ; %bb.3: ; %atomicrmw.end
51 ; GCN-NEXT: s_or_b64 exec, exec, s[0:1]
52 ; GCN-NEXT: s_mov_b32 s7, 0xf000
53 ; GCN-NEXT: s_mov_b32 s6, -1
54 ; GCN-NEXT: buffer_store_dword v5, off, s[4:7], 0
55 ; GCN-NEXT: .LBB0_4: ; %exit
57 %tid = call i32 @llvm.amdgcn.workitem.id.x()
58 %tid.gep = getelementptr ptr addrspace(1), ptr addrspace(1) %in, i32 %tid
59 %ptr = load volatile ptr addrspace(1), ptr addrspace(1) %tid.gep
60 %xor = xor i32 %tid, 1
61 %cmp = icmp ne i32 %xor, 0
62 br i1 %cmp, label %atomic, label %exit
65 %gep = getelementptr i32, ptr addrspace(1) %ptr, i32 100
66 %ret = atomicrmw max ptr addrspace(1) %gep, i32 %y seq_cst
67 store i32 %ret, ptr addrspace(1) %out
74 define amdgpu_kernel void @atomic_max_i32_noret(ptr addrspace(1) %out, ptr addrspace(1) %in, ptr addrspace(1) %x, i32 %y) #0 {
75 ; GCN-LABEL: atomic_max_i32_noret:
77 ; GCN-NEXT: s_load_dwordx2 s[4:5], s[0:1], 0xb
78 ; GCN-NEXT: s_mov_b32 s7, 0xf000
79 ; GCN-NEXT: s_mov_b32 s6, 0
80 ; GCN-NEXT: v_lshlrev_b32_e32 v1, 3, v0
81 ; GCN-NEXT: v_mov_b32_e32 v2, 0
82 ; GCN-NEXT: s_waitcnt lgkmcnt(0)
83 ; GCN-NEXT: buffer_load_dwordx2 v[1:2], v[1:2], s[4:7], 0 addr64 glc
84 ; GCN-NEXT: s_waitcnt vmcnt(0)
85 ; GCN-NEXT: v_cmp_ne_u32_e32 vcc, 1, v0
86 ; GCN-NEXT: s_and_saveexec_b64 s[2:3], vcc
87 ; GCN-NEXT: s_cbranch_execz .LBB1_3
88 ; GCN-NEXT: ; %bb.1: ; %atomic
89 ; GCN-NEXT: s_mov_b32 s4, s6
90 ; GCN-NEXT: s_mov_b32 s5, s6
91 ; GCN-NEXT: buffer_load_dword v4, v[1:2], s[4:7], 0 addr64 offset:400
92 ; GCN-NEXT: s_load_dword s2, s[0:1], 0xf
93 ; GCN-NEXT: s_mov_b64 s[0:1], 0
94 ; GCN-NEXT: .LBB1_2: ; %atomicrmw.start
95 ; GCN-NEXT: ; =>This Inner Loop Header: Depth=1
96 ; GCN-NEXT: s_waitcnt vmcnt(0) lgkmcnt(0)
97 ; GCN-NEXT: v_max_i32_e32 v3, s2, v4
98 ; GCN-NEXT: s_waitcnt expcnt(0)
99 ; GCN-NEXT: v_mov_b32_e32 v6, v4
100 ; GCN-NEXT: v_mov_b32_e32 v5, v3
101 ; GCN-NEXT: s_waitcnt vmcnt(0) lgkmcnt(0)
102 ; GCN-NEXT: buffer_atomic_cmpswap v[5:6], v[1:2], s[4:7], 0 addr64 offset:400 glc
103 ; GCN-NEXT: s_waitcnt vmcnt(0)
104 ; GCN-NEXT: buffer_wbinvl1
105 ; GCN-NEXT: v_cmp_eq_u32_e32 vcc, v5, v4
106 ; GCN-NEXT: s_or_b64 s[0:1], vcc, s[0:1]
107 ; GCN-NEXT: v_mov_b32_e32 v4, v5
108 ; GCN-NEXT: s_andn2_b64 exec, exec, s[0:1]
109 ; GCN-NEXT: s_cbranch_execnz .LBB1_2
110 ; GCN-NEXT: .LBB1_3: ; %exit
112 %tid = call i32 @llvm.amdgcn.workitem.id.x()
113 %tid.gep = getelementptr ptr addrspace(1), ptr addrspace(1) %in, i32 %tid
114 %ptr = load volatile ptr addrspace(1), ptr addrspace(1) %tid.gep
115 %xor = xor i32 %tid, 1
116 %cmp = icmp ne i32 %xor, 0
117 br i1 %cmp, label %atomic, label %exit
120 %gep = getelementptr i32, ptr addrspace(1) %ptr, i32 100
121 %ret = atomicrmw max ptr addrspace(1) %gep, i32 %y seq_cst
128 attributes #0 = { nounwind }
129 attributes #1 = { nounwind readnone }