1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx940 -verify-machineinstrs < %s | FileCheck -check-prefixes=GFX940 %s
3 ; RUN: opt -mtriple=amdgcn-amd-amdhsa -S -passes=atomic-expand < %s | FileCheck --check-prefix=OPT %s
5 define i32 @global_agent_monotonic_idempotent_or(ptr addrspace(1) %in) {
6 ; GFX940-LABEL: global_agent_monotonic_idempotent_or:
7 ; GFX940: ; %bb.0: ; %entry
8 ; GFX940-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
9 ; GFX940-NEXT: global_load_dword v0, v[0:1], off sc1
10 ; GFX940-NEXT: s_waitcnt vmcnt(0)
11 ; GFX940-NEXT: s_setpc_b64 s[30:31]
12 ; OPT-LABEL: @global_agent_monotonic_idempotent_or(
14 ; OPT-NEXT: [[VAL:%.*]] = load atomic i32, ptr addrspace(1) [[IN:%.*]] syncscope("agent-one-as") monotonic, align 4
15 ; OPT-NEXT: ret i32 [[VAL]]
18 %val = atomicrmw or ptr addrspace(1) %in, i32 0 syncscope("agent-one-as") monotonic, align 4
22 define i32 @global_agent_acquire_idempotent_or(ptr addrspace(1) %in) {
23 ; GFX940-LABEL: global_agent_acquire_idempotent_or:
24 ; GFX940: ; %bb.0: ; %entry
25 ; GFX940-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
26 ; GFX940-NEXT: global_load_dword v0, v[0:1], off sc1
27 ; GFX940-NEXT: s_waitcnt vmcnt(0)
28 ; GFX940-NEXT: buffer_inv sc1
29 ; GFX940-NEXT: s_setpc_b64 s[30:31]
30 ; OPT-LABEL: @global_agent_acquire_idempotent_or(
32 ; OPT-NEXT: [[VAL:%.*]] = load atomic i32, ptr addrspace(1) [[IN:%.*]] syncscope("agent-one-as") acquire, align 4
33 ; OPT-NEXT: ret i32 [[VAL]]
36 %val = atomicrmw or ptr addrspace(1) %in, i32 0 syncscope("agent-one-as") acquire, align 4
40 define i32 @global_agent_release_idempotent_or(ptr addrspace(1) %in) {
41 ; GFX940-LABEL: global_agent_release_idempotent_or:
42 ; GFX940: ; %bb.0: ; %entry
43 ; GFX940-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
44 ; GFX940-NEXT: v_mov_b32_e32 v2, 0
45 ; GFX940-NEXT: buffer_wbl2 sc1
46 ; GFX940-NEXT: global_atomic_or v0, v[0:1], v2, off sc0
47 ; GFX940-NEXT: s_waitcnt vmcnt(0)
48 ; GFX940-NEXT: s_setpc_b64 s[30:31]
49 ; OPT-LABEL: @global_agent_release_idempotent_or(
51 ; OPT-NEXT: [[VAL:%.*]] = atomicrmw or ptr addrspace(1) [[IN:%.*]], i32 0 syncscope("agent-one-as") release, align 4
52 ; OPT-NEXT: ret i32 [[VAL]]
55 %val = atomicrmw or ptr addrspace(1) %in, i32 0 syncscope("agent-one-as") release, align 4
59 define i32 @global_agent_acquire_release_idempotent_or(ptr addrspace(1) %in) {
60 ; GFX940-LABEL: global_agent_acquire_release_idempotent_or:
61 ; GFX940: ; %bb.0: ; %entry
62 ; GFX940-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
63 ; GFX940-NEXT: v_mov_b32_e32 v2, 0
64 ; GFX940-NEXT: buffer_wbl2 sc1
65 ; GFX940-NEXT: global_atomic_or v0, v[0:1], v2, off sc0
66 ; GFX940-NEXT: s_waitcnt vmcnt(0)
67 ; GFX940-NEXT: buffer_inv sc1
68 ; GFX940-NEXT: s_setpc_b64 s[30:31]
69 ; OPT-LABEL: @global_agent_acquire_release_idempotent_or(
71 ; OPT-NEXT: [[VAL:%.*]] = atomicrmw or ptr addrspace(1) [[IN:%.*]], i32 0 syncscope("agent-one-as") acq_rel, align 4
72 ; OPT-NEXT: ret i32 [[VAL]]
75 %val = atomicrmw or ptr addrspace(1) %in, i32 0 syncscope("agent-one-as") acq_rel, align 4
79 define i32 @global_agent_acquire_release_idempotent_or__no_fine_grained(ptr addrspace(1) %in) {
80 ; GFX940-LABEL: global_agent_acquire_release_idempotent_or__no_fine_grained:
81 ; GFX940: ; %bb.0: ; %entry
82 ; GFX940-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
83 ; GFX940-NEXT: v_mov_b32_e32 v2, 0
84 ; GFX940-NEXT: buffer_wbl2 sc1
85 ; GFX940-NEXT: global_atomic_or v0, v[0:1], v2, off sc0
86 ; GFX940-NEXT: s_waitcnt vmcnt(0)
87 ; GFX940-NEXT: buffer_inv sc1
88 ; GFX940-NEXT: s_setpc_b64 s[30:31]
89 ; OPT-LABEL: @global_agent_acquire_release_idempotent_or__no_fine_grained(
91 ; OPT-NEXT: [[VAL:%.*]] = atomicrmw or ptr addrspace(1) [[IN:%.*]], i32 0 syncscope("agent-one-as") acq_rel, align 4, !amdgpu.no.fine.grained.memory [[META0:![0-9]+]]
92 ; OPT-NEXT: ret i32 [[VAL]]
95 %val = atomicrmw or ptr addrspace(1) %in, i32 0 syncscope("agent-one-as") acq_rel, align 4, !amdgpu.no.fine.grained.memory !0
99 define i32 @global_agent_seq_cst_idempotent_or(ptr addrspace(1) %in) {
100 ; GFX940-LABEL: global_agent_seq_cst_idempotent_or:
101 ; GFX940: ; %bb.0: ; %entry
102 ; GFX940-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
103 ; GFX940-NEXT: v_mov_b32_e32 v2, 0
104 ; GFX940-NEXT: buffer_wbl2 sc1
105 ; GFX940-NEXT: global_atomic_or v0, v[0:1], v2, off sc0
106 ; GFX940-NEXT: s_waitcnt vmcnt(0)
107 ; GFX940-NEXT: buffer_inv sc1
108 ; GFX940-NEXT: s_setpc_b64 s[30:31]
109 ; OPT-LABEL: @global_agent_seq_cst_idempotent_or(
111 ; OPT-NEXT: [[VAL:%.*]] = atomicrmw or ptr addrspace(1) [[IN:%.*]], i32 0 syncscope("agent-one-as") seq_cst, align 4
112 ; OPT-NEXT: ret i32 [[VAL]]
115 %val = atomicrmw or ptr addrspace(1) %in, i32 0 syncscope("agent-one-as") seq_cst, align 4
119 define i32 @global_agent_monotonic_idempotent_add(ptr addrspace(1) %in) {
120 ; GFX940-LABEL: global_agent_monotonic_idempotent_add:
121 ; GFX940: ; %bb.0: ; %entry
122 ; GFX940-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
123 ; GFX940-NEXT: global_load_dword v0, v[0:1], off sc0
124 ; GFX940-NEXT: s_waitcnt vmcnt(0)
125 ; GFX940-NEXT: s_setpc_b64 s[30:31]
126 ; OPT-LABEL: @global_agent_monotonic_idempotent_add(
128 ; OPT-NEXT: [[VAL:%.*]] = load atomic i32, ptr addrspace(1) [[IN:%.*]] syncscope("workgroup") monotonic, align 4
129 ; OPT-NEXT: ret i32 [[VAL]]
132 %val = atomicrmw add ptr addrspace(1) %in, i32 0 syncscope("workgroup") monotonic, align 4
136 define i32 @global_agent_monotonic_idempotent_add__no_fine_grained(ptr addrspace(1) %in) {
137 ; GFX940-LABEL: global_agent_monotonic_idempotent_add__no_fine_grained:
138 ; GFX940: ; %bb.0: ; %entry
139 ; GFX940-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
140 ; GFX940-NEXT: global_load_dword v0, v[0:1], off sc0
141 ; GFX940-NEXT: s_waitcnt vmcnt(0)
142 ; GFX940-NEXT: s_setpc_b64 s[30:31]
143 ; OPT-LABEL: @global_agent_monotonic_idempotent_add__no_fine_grained(
145 ; OPT-NEXT: [[VAL:%.*]] = load atomic i32, ptr addrspace(1) [[IN:%.*]] syncscope("workgroup") monotonic, align 4, !amdgpu.no.fine.grained.memory [[META0]]
146 ; OPT-NEXT: ret i32 [[VAL]]
149 %val = atomicrmw add ptr addrspace(1) %in, i32 0 syncscope("workgroup") monotonic, align 4, !amdgpu.no.fine.grained.memory !0
153 define i32 @global_agent_monotonic_idempotent_sub(ptr addrspace(1) %in) {
154 ; GFX940-LABEL: global_agent_monotonic_idempotent_sub:
155 ; GFX940: ; %bb.0: ; %entry
156 ; GFX940-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
157 ; GFX940-NEXT: global_load_dword v0, v[0:1], off
158 ; GFX940-NEXT: s_waitcnt vmcnt(0)
159 ; GFX940-NEXT: s_setpc_b64 s[30:31]
160 ; OPT-LABEL: @global_agent_monotonic_idempotent_sub(
162 ; OPT-NEXT: [[VAL:%.*]] = load atomic i32, ptr addrspace(1) [[IN:%.*]] syncscope("wavefront") monotonic, align 4
163 ; OPT-NEXT: ret i32 [[VAL]]
166 %val = atomicrmw sub ptr addrspace(1) %in, i32 0 syncscope("wavefront") monotonic, align 4
170 define i32 @global_agent_monotonic_idempotent_sub__no_fine_grained(ptr addrspace(1) %in) {
171 ; GFX940-LABEL: global_agent_monotonic_idempotent_sub__no_fine_grained:
172 ; GFX940: ; %bb.0: ; %entry
173 ; GFX940-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
174 ; GFX940-NEXT: global_load_dword v0, v[0:1], off
175 ; GFX940-NEXT: s_waitcnt vmcnt(0)
176 ; GFX940-NEXT: s_setpc_b64 s[30:31]
177 ; OPT-LABEL: @global_agent_monotonic_idempotent_sub__no_fine_grained(
179 ; OPT-NEXT: [[VAL:%.*]] = load atomic i32, ptr addrspace(1) [[IN:%.*]] syncscope("wavefront") monotonic, align 4, !amdgpu.no.fine.grained.memory [[META0]]
180 ; OPT-NEXT: ret i32 [[VAL]]
183 %val = atomicrmw sub ptr addrspace(1) %in, i32 0 syncscope("wavefront") monotonic, align 4, !amdgpu.no.fine.grained.memory !0
187 define i32 @global_system_monotonic_idempotent_xor(ptr addrspace(1) %in) {
188 ; GFX940-LABEL: global_system_monotonic_idempotent_xor:
189 ; GFX940: ; %bb.0: ; %entry
190 ; GFX940-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
191 ; GFX940-NEXT: global_load_dword v0, v[0:1], off sc0 sc1
192 ; GFX940-NEXT: s_waitcnt vmcnt(0)
193 ; GFX940-NEXT: s_setpc_b64 s[30:31]
194 ; OPT-LABEL: @global_system_monotonic_idempotent_xor(
196 ; OPT-NEXT: [[VAL:%.*]] = load atomic i32, ptr addrspace(1) [[IN:%.*]] monotonic, align 4
197 ; OPT-NEXT: ret i32 [[VAL]]
200 %val = atomicrmw xor ptr addrspace(1) %in, i32 0 monotonic, align 4
204 define i32 @global_system_monotonic_idempotent_xor__no_fine_grained(ptr addrspace(1) %in) {
205 ; GFX940-LABEL: global_system_monotonic_idempotent_xor__no_fine_grained:
206 ; GFX940: ; %bb.0: ; %entry
207 ; GFX940-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
208 ; GFX940-NEXT: global_load_dword v0, v[0:1], off sc0 sc1
209 ; GFX940-NEXT: s_waitcnt vmcnt(0)
210 ; GFX940-NEXT: s_setpc_b64 s[30:31]
211 ; OPT-LABEL: @global_system_monotonic_idempotent_xor__no_fine_grained(
213 ; OPT-NEXT: [[VAL:%.*]] = load atomic i32, ptr addrspace(1) [[IN:%.*]] monotonic, align 4, !amdgpu.no.fine.grained.memory [[META0]]
214 ; OPT-NEXT: ret i32 [[VAL]]
217 %val = atomicrmw xor ptr addrspace(1) %in, i32 0 monotonic, align 4, !amdgpu.no.fine.grained.memory !0
221 define i32 @global_agent_monotonic_idempotent_and(ptr addrspace(1) %in) {
222 ; GFX940-LABEL: global_agent_monotonic_idempotent_and:
223 ; GFX940: ; %bb.0: ; %entry
224 ; GFX940-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
225 ; GFX940-NEXT: global_load_dword v0, v[0:1], off
226 ; GFX940-NEXT: s_waitcnt vmcnt(0)
227 ; GFX940-NEXT: s_setpc_b64 s[30:31]
228 ; OPT-LABEL: @global_agent_monotonic_idempotent_and(
230 ; OPT-NEXT: [[VAL:%.*]] = load atomic i32, ptr addrspace(1) [[IN:%.*]] syncscope("singlethread") monotonic, align 4
231 ; OPT-NEXT: ret i32 [[VAL]]
234 %val = atomicrmw and ptr addrspace(1) %in, i32 -1 syncscope("singlethread") monotonic, align 4
238 define i32 @global_agent_monotonic_idempotent_and_no_fined_grain(ptr addrspace(1) %in) {
239 ; GFX940-LABEL: global_agent_monotonic_idempotent_and_no_fined_grain:
240 ; GFX940: ; %bb.0: ; %entry
241 ; GFX940-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
242 ; GFX940-NEXT: global_load_dword v0, v[0:1], off
243 ; GFX940-NEXT: s_waitcnt vmcnt(0)
244 ; GFX940-NEXT: s_setpc_b64 s[30:31]
245 ; OPT-LABEL: @global_agent_monotonic_idempotent_and_no_fined_grain(
247 ; OPT-NEXT: [[VAL:%.*]] = load atomic i32, ptr addrspace(1) [[IN:%.*]] syncscope("singlethread") monotonic, align 4, !amdgpu.no.fine.grained.memory [[META0]]
248 ; OPT-NEXT: ret i32 [[VAL]]
251 %val = atomicrmw and ptr addrspace(1) %in, i32 -1 syncscope("singlethread") monotonic, align 4, !amdgpu.no.fine.grained.memory !0