1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx700 -verify-machineinstrs < %s | FileCheck --check-prefixes=GFX7 %s
3; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1010 -verify-machineinstrs < %s | FileCheck --check-prefixes=GFX10-WGP %s
4; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1010 -mattr=+cumode -verify-machineinstrs < %s | FileCheck --check-prefixes=GFX10-CU %s
5; RUN: llc -mtriple=amdgcn-amd-amdpal -mcpu=gfx700 -amdgcn-skip-cache-invalidations -verify-machineinstrs < %s | FileCheck --check-prefixes=SKIP-CACHE-INV %s
6; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx90a -verify-machineinstrs < %s | FileCheck -check-prefixes=GFX90A-NOTTGSPLIT %s
7; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx90a -mattr=+tgsplit -verify-machineinstrs < %s | FileCheck -check-prefixes=GFX90A-TGSPLIT %s
8
9define amdgpu_kernel void @flat_workgroup_unordered_load(
10; GFX7-LABEL: flat_workgroup_unordered_load:
11; GFX7:       ; %bb.0: ; %entry
12; GFX7-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
13; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
14; GFX7-NEXT:    v_mov_b32_e32 v0, s0
15; GFX7-NEXT:    v_mov_b32_e32 v1, s1
16; GFX7-NEXT:    flat_load_dword v0, v[0:1]
17; GFX7-NEXT:    v_mov_b32_e32 v2, s2
18; GFX7-NEXT:    v_mov_b32_e32 v3, s3
19; GFX7-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
20; GFX7-NEXT:    flat_store_dword v[2:3], v0
21; GFX7-NEXT:    s_endpgm
22;
23; GFX10-WGP-LABEL: flat_workgroup_unordered_load:
24; GFX10-WGP:       ; %bb.0: ; %entry
25; GFX10-WGP-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
26; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
27; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
28; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
29; GFX10-WGP-NEXT:    flat_load_dword v2, v[0:1]
30; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s2
31; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s3
32; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
33; GFX10-WGP-NEXT:    flat_store_dword v[0:1], v2
34; GFX10-WGP-NEXT:    s_endpgm
35;
36; GFX10-CU-LABEL: flat_workgroup_unordered_load:
37; GFX10-CU:       ; %bb.0: ; %entry
38; GFX10-CU-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
39; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
40; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
41; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
42; GFX10-CU-NEXT:    flat_load_dword v2, v[0:1]
43; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s2
44; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s3
45; GFX10-CU-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
46; GFX10-CU-NEXT:    flat_store_dword v[0:1], v2
47; GFX10-CU-NEXT:    s_endpgm
48;
49; SKIP-CACHE-INV-LABEL: flat_workgroup_unordered_load:
50; SKIP-CACHE-INV:       ; %bb.0: ; %entry
51; SKIP-CACHE-INV-NEXT:    s_load_dwordx4 s[0:3], s[0:1], 0x9
52; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
53; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s0
54; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s1
55; SKIP-CACHE-INV-NEXT:    flat_load_dword v0, v[0:1]
56; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s2
57; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s3
58; SKIP-CACHE-INV-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
59; SKIP-CACHE-INV-NEXT:    flat_store_dword v[2:3], v0
60; SKIP-CACHE-INV-NEXT:    s_endpgm
61;
62; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_unordered_load:
63; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
64; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
65; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
66; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v0, s0
67; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v1, s1
68; GFX90A-NOTTGSPLIT-NEXT:    flat_load_dword v0, v[0:1]
69; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
70; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v3, s3
71; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
72; GFX90A-NOTTGSPLIT-NEXT:    flat_store_dword v[2:3], v0
73; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
74;
75; GFX90A-TGSPLIT-LABEL: flat_workgroup_unordered_load:
76; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
77; GFX90A-TGSPLIT-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
78; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
79; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v0, s0
80; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v1, s1
81; GFX90A-TGSPLIT-NEXT:    flat_load_dword v0, v[0:1]
82; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
83; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v3, s3
84; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
85; GFX90A-TGSPLIT-NEXT:    flat_store_dword v[2:3], v0
86; GFX90A-TGSPLIT-NEXT:    s_endpgm
87    i32* %in, i32* %out) {
88entry:
89  %val = load atomic i32, i32* %in syncscope("workgroup") unordered, align 4
90  store i32 %val, i32* %out
91  ret void
92}
93
94define amdgpu_kernel void @flat_workgroup_monotonic_load(
95; GFX7-LABEL: flat_workgroup_monotonic_load:
96; GFX7:       ; %bb.0: ; %entry
97; GFX7-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
98; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
99; GFX7-NEXT:    v_mov_b32_e32 v0, s0
100; GFX7-NEXT:    v_mov_b32_e32 v1, s1
101; GFX7-NEXT:    flat_load_dword v0, v[0:1]
102; GFX7-NEXT:    v_mov_b32_e32 v2, s2
103; GFX7-NEXT:    v_mov_b32_e32 v3, s3
104; GFX7-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
105; GFX7-NEXT:    flat_store_dword v[2:3], v0
106; GFX7-NEXT:    s_endpgm
107;
108; GFX10-WGP-LABEL: flat_workgroup_monotonic_load:
109; GFX10-WGP:       ; %bb.0: ; %entry
110; GFX10-WGP-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
111; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
112; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
113; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
114; GFX10-WGP-NEXT:    flat_load_dword v2, v[0:1] glc
115; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s2
116; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s3
117; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
118; GFX10-WGP-NEXT:    flat_store_dword v[0:1], v2
119; GFX10-WGP-NEXT:    s_endpgm
120;
121; GFX10-CU-LABEL: flat_workgroup_monotonic_load:
122; GFX10-CU:       ; %bb.0: ; %entry
123; GFX10-CU-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
124; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
125; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
126; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
127; GFX10-CU-NEXT:    flat_load_dword v2, v[0:1]
128; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s2
129; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s3
130; GFX10-CU-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
131; GFX10-CU-NEXT:    flat_store_dword v[0:1], v2
132; GFX10-CU-NEXT:    s_endpgm
133;
134; SKIP-CACHE-INV-LABEL: flat_workgroup_monotonic_load:
135; SKIP-CACHE-INV:       ; %bb.0: ; %entry
136; SKIP-CACHE-INV-NEXT:    s_load_dwordx4 s[0:3], s[0:1], 0x9
137; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
138; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s0
139; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s1
140; SKIP-CACHE-INV-NEXT:    flat_load_dword v0, v[0:1]
141; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s2
142; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s3
143; SKIP-CACHE-INV-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
144; SKIP-CACHE-INV-NEXT:    flat_store_dword v[2:3], v0
145; SKIP-CACHE-INV-NEXT:    s_endpgm
146;
147; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_monotonic_load:
148; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
149; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
150; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
151; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v0, s0
152; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v1, s1
153; GFX90A-NOTTGSPLIT-NEXT:    flat_load_dword v0, v[0:1]
154; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
155; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v3, s3
156; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
157; GFX90A-NOTTGSPLIT-NEXT:    flat_store_dword v[2:3], v0
158; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
159;
160; GFX90A-TGSPLIT-LABEL: flat_workgroup_monotonic_load:
161; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
162; GFX90A-TGSPLIT-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
163; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
164; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v0, s0
165; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v1, s1
166; GFX90A-TGSPLIT-NEXT:    flat_load_dword v0, v[0:1] glc
167; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
168; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v3, s3
169; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
170; GFX90A-TGSPLIT-NEXT:    flat_store_dword v[2:3], v0
171; GFX90A-TGSPLIT-NEXT:    s_endpgm
172    i32* %in, i32* %out) {
173entry:
174  %val = load atomic i32, i32* %in syncscope("workgroup") monotonic, align 4
175  store i32 %val, i32* %out
176  ret void
177}
178
179define amdgpu_kernel void @flat_workgroup_acquire_load(
180; GFX7-LABEL: flat_workgroup_acquire_load:
181; GFX7:       ; %bb.0: ; %entry
182; GFX7-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
183; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
184; GFX7-NEXT:    v_mov_b32_e32 v0, s0
185; GFX7-NEXT:    v_mov_b32_e32 v1, s1
186; GFX7-NEXT:    flat_load_dword v0, v[0:1]
187; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
188; GFX7-NEXT:    v_mov_b32_e32 v2, s2
189; GFX7-NEXT:    v_mov_b32_e32 v3, s3
190; GFX7-NEXT:    s_waitcnt vmcnt(0)
191; GFX7-NEXT:    flat_store_dword v[2:3], v0
192; GFX7-NEXT:    s_endpgm
193;
194; GFX10-WGP-LABEL: flat_workgroup_acquire_load:
195; GFX10-WGP:       ; %bb.0: ; %entry
196; GFX10-WGP-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
197; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
198; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
199; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
200; GFX10-WGP-NEXT:    flat_load_dword v2, v[0:1] glc
201; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
202; GFX10-WGP-NEXT:    buffer_gl0_inv
203; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s2
204; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s3
205; GFX10-WGP-NEXT:    flat_store_dword v[0:1], v2
206; GFX10-WGP-NEXT:    s_endpgm
207;
208; GFX10-CU-LABEL: flat_workgroup_acquire_load:
209; GFX10-CU:       ; %bb.0: ; %entry
210; GFX10-CU-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
211; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
212; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
213; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
214; GFX10-CU-NEXT:    flat_load_dword v2, v[0:1]
215; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
216; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s2
217; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s3
218; GFX10-CU-NEXT:    s_waitcnt vmcnt(0)
219; GFX10-CU-NEXT:    flat_store_dword v[0:1], v2
220; GFX10-CU-NEXT:    s_endpgm
221;
222; SKIP-CACHE-INV-LABEL: flat_workgroup_acquire_load:
223; SKIP-CACHE-INV:       ; %bb.0: ; %entry
224; SKIP-CACHE-INV-NEXT:    s_load_dwordx4 s[0:3], s[0:1], 0x9
225; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
226; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s0
227; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s1
228; SKIP-CACHE-INV-NEXT:    flat_load_dword v0, v[0:1]
229; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
230; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s2
231; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s3
232; SKIP-CACHE-INV-NEXT:    s_waitcnt vmcnt(0)
233; SKIP-CACHE-INV-NEXT:    flat_store_dword v[2:3], v0
234; SKIP-CACHE-INV-NEXT:    s_endpgm
235;
236; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_acquire_load:
237; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
238; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
239; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
240; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v0, s0
241; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v1, s1
242; GFX90A-NOTTGSPLIT-NEXT:    flat_load_dword v0, v[0:1]
243; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
244; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
245; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v3, s3
246; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt vmcnt(0)
247; GFX90A-NOTTGSPLIT-NEXT:    flat_store_dword v[2:3], v0
248; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
249;
250; GFX90A-TGSPLIT-LABEL: flat_workgroup_acquire_load:
251; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
252; GFX90A-TGSPLIT-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
253; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
254; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v0, s0
255; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v1, s1
256; GFX90A-TGSPLIT-NEXT:    flat_load_dword v0, v[0:1] glc
257; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
258; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
259; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
260; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v3, s3
261; GFX90A-TGSPLIT-NEXT:    flat_store_dword v[2:3], v0
262; GFX90A-TGSPLIT-NEXT:    s_endpgm
263    i32* %in, i32* %out) {
264entry:
265  %val = load atomic i32, i32* %in syncscope("workgroup") acquire, align 4
266  store i32 %val, i32* %out
267  ret void
268}
269
270define amdgpu_kernel void @flat_workgroup_seq_cst_load(
271; GFX7-LABEL: flat_workgroup_seq_cst_load:
272; GFX7:       ; %bb.0: ; %entry
273; GFX7-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
274; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
275; GFX7-NEXT:    v_mov_b32_e32 v0, s0
276; GFX7-NEXT:    v_mov_b32_e32 v1, s1
277; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
278; GFX7-NEXT:    flat_load_dword v0, v[0:1]
279; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
280; GFX7-NEXT:    v_mov_b32_e32 v2, s2
281; GFX7-NEXT:    v_mov_b32_e32 v3, s3
282; GFX7-NEXT:    s_waitcnt vmcnt(0)
283; GFX7-NEXT:    flat_store_dword v[2:3], v0
284; GFX7-NEXT:    s_endpgm
285;
286; GFX10-WGP-LABEL: flat_workgroup_seq_cst_load:
287; GFX10-WGP:       ; %bb.0: ; %entry
288; GFX10-WGP-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
289; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
290; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
291; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
292; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
293; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
294; GFX10-WGP-NEXT:    flat_load_dword v2, v[0:1] glc
295; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
296; GFX10-WGP-NEXT:    buffer_gl0_inv
297; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s2
298; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s3
299; GFX10-WGP-NEXT:    flat_store_dword v[0:1], v2
300; GFX10-WGP-NEXT:    s_endpgm
301;
302; GFX10-CU-LABEL: flat_workgroup_seq_cst_load:
303; GFX10-CU:       ; %bb.0: ; %entry
304; GFX10-CU-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
305; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
306; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
307; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
308; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
309; GFX10-CU-NEXT:    flat_load_dword v2, v[0:1]
310; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
311; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s2
312; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s3
313; GFX10-CU-NEXT:    s_waitcnt vmcnt(0)
314; GFX10-CU-NEXT:    flat_store_dword v[0:1], v2
315; GFX10-CU-NEXT:    s_endpgm
316;
317; SKIP-CACHE-INV-LABEL: flat_workgroup_seq_cst_load:
318; SKIP-CACHE-INV:       ; %bb.0: ; %entry
319; SKIP-CACHE-INV-NEXT:    s_load_dwordx4 s[0:3], s[0:1], 0x9
320; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
321; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s0
322; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s1
323; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
324; SKIP-CACHE-INV-NEXT:    flat_load_dword v0, v[0:1]
325; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
326; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s2
327; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s3
328; SKIP-CACHE-INV-NEXT:    s_waitcnt vmcnt(0)
329; SKIP-CACHE-INV-NEXT:    flat_store_dword v[2:3], v0
330; SKIP-CACHE-INV-NEXT:    s_endpgm
331;
332; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_seq_cst_load:
333; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
334; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
335; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
336; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v0, s0
337; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v1, s1
338; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
339; GFX90A-NOTTGSPLIT-NEXT:    flat_load_dword v0, v[0:1]
340; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
341; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
342; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v3, s3
343; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt vmcnt(0)
344; GFX90A-NOTTGSPLIT-NEXT:    flat_store_dword v[2:3], v0
345; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
346;
347; GFX90A-TGSPLIT-LABEL: flat_workgroup_seq_cst_load:
348; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
349; GFX90A-TGSPLIT-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
350; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
351; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v0, s0
352; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v1, s1
353; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
354; GFX90A-TGSPLIT-NEXT:    flat_load_dword v0, v[0:1] glc
355; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
356; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
357; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
358; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v3, s3
359; GFX90A-TGSPLIT-NEXT:    flat_store_dword v[2:3], v0
360; GFX90A-TGSPLIT-NEXT:    s_endpgm
361    i32* %in, i32* %out) {
362entry:
363  %val = load atomic i32, i32* %in syncscope("workgroup") seq_cst, align 4
364  store i32 %val, i32* %out
365  ret void
366}
367
368define amdgpu_kernel void @flat_workgroup_unordered_store(
369; GFX7-LABEL: flat_workgroup_unordered_store:
370; GFX7:       ; %bb.0: ; %entry
371; GFX7-NEXT:    s_load_dword s2, s[4:5], 0x0
372; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x2
373; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
374; GFX7-NEXT:    v_mov_b32_e32 v2, s2
375; GFX7-NEXT:    v_mov_b32_e32 v0, s0
376; GFX7-NEXT:    v_mov_b32_e32 v1, s1
377; GFX7-NEXT:    flat_store_dword v[0:1], v2
378; GFX7-NEXT:    s_endpgm
379;
380; GFX10-WGP-LABEL: flat_workgroup_unordered_store:
381; GFX10-WGP:       ; %bb.0: ; %entry
382; GFX10-WGP-NEXT:    s_clause 0x1
383; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x8
384; GFX10-WGP-NEXT:    s_load_dword s2, s[4:5], 0x0
385; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
386; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
387; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
388; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
389; GFX10-WGP-NEXT:    flat_store_dword v[0:1], v2
390; GFX10-WGP-NEXT:    s_endpgm
391;
392; GFX10-CU-LABEL: flat_workgroup_unordered_store:
393; GFX10-CU:       ; %bb.0: ; %entry
394; GFX10-CU-NEXT:    s_clause 0x1
395; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x8
396; GFX10-CU-NEXT:    s_load_dword s2, s[4:5], 0x0
397; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
398; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
399; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
400; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
401; GFX10-CU-NEXT:    flat_store_dword v[0:1], v2
402; GFX10-CU-NEXT:    s_endpgm
403;
404; SKIP-CACHE-INV-LABEL: flat_workgroup_unordered_store:
405; SKIP-CACHE-INV:       ; %bb.0: ; %entry
406; SKIP-CACHE-INV-NEXT:    s_load_dword s2, s[0:1], 0x9
407; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
408; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
409; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s2
410; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s0
411; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s1
412; SKIP-CACHE-INV-NEXT:    flat_store_dword v[0:1], v2
413; SKIP-CACHE-INV-NEXT:    s_endpgm
414;
415; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_unordered_store:
416; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
417; GFX90A-NOTTGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x0
418; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x8
419; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
420; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
421; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
422; GFX90A-NOTTGSPLIT-NEXT:    flat_store_dword v[0:1], v2
423; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
424;
425; GFX90A-TGSPLIT-LABEL: flat_workgroup_unordered_store:
426; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
427; GFX90A-TGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x0
428; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x8
429; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
430; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
431; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
432; GFX90A-TGSPLIT-NEXT:    flat_store_dword v[0:1], v2
433; GFX90A-TGSPLIT-NEXT:    s_endpgm
434    i32 %in, i32* %out) {
435entry:
436  store atomic i32 %in, i32* %out syncscope("workgroup") unordered, align 4
437  ret void
438}
439
440define amdgpu_kernel void @flat_workgroup_monotonic_store(
441; GFX7-LABEL: flat_workgroup_monotonic_store:
442; GFX7:       ; %bb.0: ; %entry
443; GFX7-NEXT:    s_load_dword s2, s[4:5], 0x0
444; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x2
445; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
446; GFX7-NEXT:    v_mov_b32_e32 v2, s2
447; GFX7-NEXT:    v_mov_b32_e32 v0, s0
448; GFX7-NEXT:    v_mov_b32_e32 v1, s1
449; GFX7-NEXT:    flat_store_dword v[0:1], v2
450; GFX7-NEXT:    s_endpgm
451;
452; GFX10-WGP-LABEL: flat_workgroup_monotonic_store:
453; GFX10-WGP:       ; %bb.0: ; %entry
454; GFX10-WGP-NEXT:    s_clause 0x1
455; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x8
456; GFX10-WGP-NEXT:    s_load_dword s2, s[4:5], 0x0
457; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
458; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
459; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
460; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
461; GFX10-WGP-NEXT:    flat_store_dword v[0:1], v2
462; GFX10-WGP-NEXT:    s_endpgm
463;
464; GFX10-CU-LABEL: flat_workgroup_monotonic_store:
465; GFX10-CU:       ; %bb.0: ; %entry
466; GFX10-CU-NEXT:    s_clause 0x1
467; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x8
468; GFX10-CU-NEXT:    s_load_dword s2, s[4:5], 0x0
469; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
470; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
471; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
472; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
473; GFX10-CU-NEXT:    flat_store_dword v[0:1], v2
474; GFX10-CU-NEXT:    s_endpgm
475;
476; SKIP-CACHE-INV-LABEL: flat_workgroup_monotonic_store:
477; SKIP-CACHE-INV:       ; %bb.0: ; %entry
478; SKIP-CACHE-INV-NEXT:    s_load_dword s2, s[0:1], 0x9
479; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
480; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
481; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s2
482; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s0
483; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s1
484; SKIP-CACHE-INV-NEXT:    flat_store_dword v[0:1], v2
485; SKIP-CACHE-INV-NEXT:    s_endpgm
486;
487; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_monotonic_store:
488; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
489; GFX90A-NOTTGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x0
490; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x8
491; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
492; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
493; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
494; GFX90A-NOTTGSPLIT-NEXT:    flat_store_dword v[0:1], v2
495; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
496;
497; GFX90A-TGSPLIT-LABEL: flat_workgroup_monotonic_store:
498; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
499; GFX90A-TGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x0
500; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x8
501; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
502; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
503; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
504; GFX90A-TGSPLIT-NEXT:    flat_store_dword v[0:1], v2
505; GFX90A-TGSPLIT-NEXT:    s_endpgm
506    i32 %in, i32* %out) {
507entry:
508  store atomic i32 %in, i32* %out syncscope("workgroup") monotonic, align 4
509  ret void
510}
511
512define amdgpu_kernel void @flat_workgroup_release_store(
513; GFX7-LABEL: flat_workgroup_release_store:
514; GFX7:       ; %bb.0: ; %entry
515; GFX7-NEXT:    s_load_dword s2, s[4:5], 0x0
516; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x2
517; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
518; GFX7-NEXT:    v_mov_b32_e32 v2, s2
519; GFX7-NEXT:    v_mov_b32_e32 v0, s0
520; GFX7-NEXT:    v_mov_b32_e32 v1, s1
521; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
522; GFX7-NEXT:    flat_store_dword v[0:1], v2
523; GFX7-NEXT:    s_endpgm
524;
525; GFX10-WGP-LABEL: flat_workgroup_release_store:
526; GFX10-WGP:       ; %bb.0: ; %entry
527; GFX10-WGP-NEXT:    s_clause 0x1
528; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x8
529; GFX10-WGP-NEXT:    s_load_dword s2, s[4:5], 0x0
530; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
531; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
532; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
533; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
534; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
535; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
536; GFX10-WGP-NEXT:    flat_store_dword v[0:1], v2
537; GFX10-WGP-NEXT:    s_endpgm
538;
539; GFX10-CU-LABEL: flat_workgroup_release_store:
540; GFX10-CU:       ; %bb.0: ; %entry
541; GFX10-CU-NEXT:    s_clause 0x1
542; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x8
543; GFX10-CU-NEXT:    s_load_dword s2, s[4:5], 0x0
544; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
545; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
546; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
547; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
548; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
549; GFX10-CU-NEXT:    flat_store_dword v[0:1], v2
550; GFX10-CU-NEXT:    s_endpgm
551;
552; SKIP-CACHE-INV-LABEL: flat_workgroup_release_store:
553; SKIP-CACHE-INV:       ; %bb.0: ; %entry
554; SKIP-CACHE-INV-NEXT:    s_load_dword s2, s[0:1], 0x9
555; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
556; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
557; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s2
558; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s0
559; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s1
560; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
561; SKIP-CACHE-INV-NEXT:    flat_store_dword v[0:1], v2
562; SKIP-CACHE-INV-NEXT:    s_endpgm
563;
564; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_release_store:
565; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
566; GFX90A-NOTTGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x0
567; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x8
568; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
569; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
570; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
571; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
572; GFX90A-NOTTGSPLIT-NEXT:    flat_store_dword v[0:1], v2
573; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
574;
575; GFX90A-TGSPLIT-LABEL: flat_workgroup_release_store:
576; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
577; GFX90A-TGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x0
578; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x8
579; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
580; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
581; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
582; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
583; GFX90A-TGSPLIT-NEXT:    flat_store_dword v[0:1], v2
584; GFX90A-TGSPLIT-NEXT:    s_endpgm
585    i32 %in, i32* %out) {
586entry:
587  store atomic i32 %in, i32* %out syncscope("workgroup") release, align 4
588  ret void
589}
590
591define amdgpu_kernel void @flat_workgroup_seq_cst_store(
592; GFX7-LABEL: flat_workgroup_seq_cst_store:
593; GFX7:       ; %bb.0: ; %entry
594; GFX7-NEXT:    s_load_dword s2, s[4:5], 0x0
595; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x2
596; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
597; GFX7-NEXT:    v_mov_b32_e32 v2, s2
598; GFX7-NEXT:    v_mov_b32_e32 v0, s0
599; GFX7-NEXT:    v_mov_b32_e32 v1, s1
600; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
601; GFX7-NEXT:    flat_store_dword v[0:1], v2
602; GFX7-NEXT:    s_endpgm
603;
604; GFX10-WGP-LABEL: flat_workgroup_seq_cst_store:
605; GFX10-WGP:       ; %bb.0: ; %entry
606; GFX10-WGP-NEXT:    s_clause 0x1
607; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x8
608; GFX10-WGP-NEXT:    s_load_dword s2, s[4:5], 0x0
609; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
610; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
611; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
612; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
613; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
614; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
615; GFX10-WGP-NEXT:    flat_store_dword v[0:1], v2
616; GFX10-WGP-NEXT:    s_endpgm
617;
618; GFX10-CU-LABEL: flat_workgroup_seq_cst_store:
619; GFX10-CU:       ; %bb.0: ; %entry
620; GFX10-CU-NEXT:    s_clause 0x1
621; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x8
622; GFX10-CU-NEXT:    s_load_dword s2, s[4:5], 0x0
623; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
624; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
625; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
626; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
627; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
628; GFX10-CU-NEXT:    flat_store_dword v[0:1], v2
629; GFX10-CU-NEXT:    s_endpgm
630;
631; SKIP-CACHE-INV-LABEL: flat_workgroup_seq_cst_store:
632; SKIP-CACHE-INV:       ; %bb.0: ; %entry
633; SKIP-CACHE-INV-NEXT:    s_load_dword s2, s[0:1], 0x9
634; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
635; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
636; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s2
637; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s0
638; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s1
639; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
640; SKIP-CACHE-INV-NEXT:    flat_store_dword v[0:1], v2
641; SKIP-CACHE-INV-NEXT:    s_endpgm
642;
643; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_seq_cst_store:
644; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
645; GFX90A-NOTTGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x0
646; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x8
647; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
648; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
649; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
650; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
651; GFX90A-NOTTGSPLIT-NEXT:    flat_store_dword v[0:1], v2
652; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
653;
654; GFX90A-TGSPLIT-LABEL: flat_workgroup_seq_cst_store:
655; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
656; GFX90A-TGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x0
657; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x8
658; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
659; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
660; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
661; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
662; GFX90A-TGSPLIT-NEXT:    flat_store_dword v[0:1], v2
663; GFX90A-TGSPLIT-NEXT:    s_endpgm
664    i32 %in, i32* %out) {
665entry:
666  store atomic i32 %in, i32* %out syncscope("workgroup") seq_cst, align 4
667  ret void
668}
669
670define amdgpu_kernel void @flat_workgroup_monotonic_atomicrmw(
671; GFX7-LABEL: flat_workgroup_monotonic_atomicrmw:
672; GFX7:       ; %bb.0: ; %entry
673; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
674; GFX7-NEXT:    s_load_dword s2, s[4:5], 0x2
675; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
676; GFX7-NEXT:    v_mov_b32_e32 v0, s0
677; GFX7-NEXT:    v_mov_b32_e32 v1, s1
678; GFX7-NEXT:    v_mov_b32_e32 v2, s2
679; GFX7-NEXT:    flat_atomic_swap v[0:1], v2
680; GFX7-NEXT:    s_endpgm
681;
682; GFX10-WGP-LABEL: flat_workgroup_monotonic_atomicrmw:
683; GFX10-WGP:       ; %bb.0: ; %entry
684; GFX10-WGP-NEXT:    s_clause 0x1
685; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
686; GFX10-WGP-NEXT:    s_load_dword s2, s[4:5], 0x8
687; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
688; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
689; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
690; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
691; GFX10-WGP-NEXT:    flat_atomic_swap v[0:1], v2
692; GFX10-WGP-NEXT:    s_endpgm
693;
694; GFX10-CU-LABEL: flat_workgroup_monotonic_atomicrmw:
695; GFX10-CU:       ; %bb.0: ; %entry
696; GFX10-CU-NEXT:    s_clause 0x1
697; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
698; GFX10-CU-NEXT:    s_load_dword s2, s[4:5], 0x8
699; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
700; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
701; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
702; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
703; GFX10-CU-NEXT:    flat_atomic_swap v[0:1], v2
704; GFX10-CU-NEXT:    s_endpgm
705;
706; SKIP-CACHE-INV-LABEL: flat_workgroup_monotonic_atomicrmw:
707; SKIP-CACHE-INV:       ; %bb.0: ; %entry
708; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
709; SKIP-CACHE-INV-NEXT:    s_load_dword s0, s[0:1], 0xb
710; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
711; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
712; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
713; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
714; SKIP-CACHE-INV-NEXT:    flat_atomic_swap v[0:1], v2
715; SKIP-CACHE-INV-NEXT:    s_endpgm
716;
717; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_monotonic_atomicrmw:
718; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
719; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
720; GFX90A-NOTTGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x8
721; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
722; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
723; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
724; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_swap v[0:1], v2
725; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
726;
727; GFX90A-TGSPLIT-LABEL: flat_workgroup_monotonic_atomicrmw:
728; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
729; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
730; GFX90A-TGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x8
731; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
732; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
733; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
734; GFX90A-TGSPLIT-NEXT:    flat_atomic_swap v[0:1], v2
735; GFX90A-TGSPLIT-NEXT:    s_endpgm
736    i32* %out, i32 %in) {
737entry:
738  %val = atomicrmw volatile xchg i32* %out, i32 %in syncscope("workgroup") monotonic
739  ret void
740}
741
742define amdgpu_kernel void @flat_workgroup_acquire_atomicrmw(
743; GFX7-LABEL: flat_workgroup_acquire_atomicrmw:
744; GFX7:       ; %bb.0: ; %entry
745; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
746; GFX7-NEXT:    s_load_dword s2, s[4:5], 0x2
747; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
748; GFX7-NEXT:    v_mov_b32_e32 v0, s0
749; GFX7-NEXT:    v_mov_b32_e32 v1, s1
750; GFX7-NEXT:    v_mov_b32_e32 v2, s2
751; GFX7-NEXT:    flat_atomic_swap v[0:1], v2
752; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
753; GFX7-NEXT:    s_endpgm
754;
755; GFX10-WGP-LABEL: flat_workgroup_acquire_atomicrmw:
756; GFX10-WGP:       ; %bb.0: ; %entry
757; GFX10-WGP-NEXT:    s_clause 0x1
758; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
759; GFX10-WGP-NEXT:    s_load_dword s2, s[4:5], 0x8
760; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
761; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
762; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
763; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
764; GFX10-WGP-NEXT:    flat_atomic_swap v[0:1], v2
765; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
766; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
767; GFX10-WGP-NEXT:    buffer_gl0_inv
768; GFX10-WGP-NEXT:    s_endpgm
769;
770; GFX10-CU-LABEL: flat_workgroup_acquire_atomicrmw:
771; GFX10-CU:       ; %bb.0: ; %entry
772; GFX10-CU-NEXT:    s_clause 0x1
773; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
774; GFX10-CU-NEXT:    s_load_dword s2, s[4:5], 0x8
775; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
776; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
777; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
778; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
779; GFX10-CU-NEXT:    flat_atomic_swap v[0:1], v2
780; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
781; GFX10-CU-NEXT:    s_endpgm
782;
783; SKIP-CACHE-INV-LABEL: flat_workgroup_acquire_atomicrmw:
784; SKIP-CACHE-INV:       ; %bb.0: ; %entry
785; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
786; SKIP-CACHE-INV-NEXT:    s_load_dword s0, s[0:1], 0xb
787; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
788; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
789; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
790; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
791; SKIP-CACHE-INV-NEXT:    flat_atomic_swap v[0:1], v2
792; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
793; SKIP-CACHE-INV-NEXT:    s_endpgm
794;
795; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_acquire_atomicrmw:
796; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
797; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
798; GFX90A-NOTTGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x8
799; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
800; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
801; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
802; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_swap v[0:1], v2
803; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
804; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
805;
806; GFX90A-TGSPLIT-LABEL: flat_workgroup_acquire_atomicrmw:
807; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
808; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
809; GFX90A-TGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x8
810; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
811; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
812; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
813; GFX90A-TGSPLIT-NEXT:    flat_atomic_swap v[0:1], v2
814; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
815; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
816; GFX90A-TGSPLIT-NEXT:    s_endpgm
817    i32* %out, i32 %in) {
818entry:
819  %val = atomicrmw volatile xchg i32* %out, i32 %in syncscope("workgroup") acquire
820  ret void
821}
822
823define amdgpu_kernel void @flat_workgroup_release_atomicrmw(
824; GFX7-LABEL: flat_workgroup_release_atomicrmw:
825; GFX7:       ; %bb.0: ; %entry
826; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
827; GFX7-NEXT:    s_load_dword s2, s[4:5], 0x2
828; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
829; GFX7-NEXT:    v_mov_b32_e32 v0, s0
830; GFX7-NEXT:    v_mov_b32_e32 v1, s1
831; GFX7-NEXT:    v_mov_b32_e32 v2, s2
832; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
833; GFX7-NEXT:    flat_atomic_swap v[0:1], v2
834; GFX7-NEXT:    s_endpgm
835;
836; GFX10-WGP-LABEL: flat_workgroup_release_atomicrmw:
837; GFX10-WGP:       ; %bb.0: ; %entry
838; GFX10-WGP-NEXT:    s_clause 0x1
839; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
840; GFX10-WGP-NEXT:    s_load_dword s2, s[4:5], 0x8
841; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
842; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
843; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
844; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
845; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
846; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
847; GFX10-WGP-NEXT:    flat_atomic_swap v[0:1], v2
848; GFX10-WGP-NEXT:    s_endpgm
849;
850; GFX10-CU-LABEL: flat_workgroup_release_atomicrmw:
851; GFX10-CU:       ; %bb.0: ; %entry
852; GFX10-CU-NEXT:    s_clause 0x1
853; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
854; GFX10-CU-NEXT:    s_load_dword s2, s[4:5], 0x8
855; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
856; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
857; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
858; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
859; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
860; GFX10-CU-NEXT:    flat_atomic_swap v[0:1], v2
861; GFX10-CU-NEXT:    s_endpgm
862;
863; SKIP-CACHE-INV-LABEL: flat_workgroup_release_atomicrmw:
864; SKIP-CACHE-INV:       ; %bb.0: ; %entry
865; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
866; SKIP-CACHE-INV-NEXT:    s_load_dword s0, s[0:1], 0xb
867; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
868; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
869; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
870; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
871; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
872; SKIP-CACHE-INV-NEXT:    flat_atomic_swap v[0:1], v2
873; SKIP-CACHE-INV-NEXT:    s_endpgm
874;
875; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_release_atomicrmw:
876; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
877; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
878; GFX90A-NOTTGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x8
879; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
880; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
881; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
882; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
883; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_swap v[0:1], v2
884; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
885;
886; GFX90A-TGSPLIT-LABEL: flat_workgroup_release_atomicrmw:
887; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
888; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
889; GFX90A-TGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x8
890; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
891; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
892; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
893; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
894; GFX90A-TGSPLIT-NEXT:    flat_atomic_swap v[0:1], v2
895; GFX90A-TGSPLIT-NEXT:    s_endpgm
896    i32* %out, i32 %in) {
897entry:
898  %val = atomicrmw volatile xchg i32* %out, i32 %in syncscope("workgroup") release
899  ret void
900}
901
902define amdgpu_kernel void @flat_workgroup_acq_rel_atomicrmw(
903; GFX7-LABEL: flat_workgroup_acq_rel_atomicrmw:
904; GFX7:       ; %bb.0: ; %entry
905; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
906; GFX7-NEXT:    s_load_dword s2, s[4:5], 0x2
907; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
908; GFX7-NEXT:    v_mov_b32_e32 v0, s0
909; GFX7-NEXT:    v_mov_b32_e32 v1, s1
910; GFX7-NEXT:    v_mov_b32_e32 v2, s2
911; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
912; GFX7-NEXT:    flat_atomic_swap v[0:1], v2
913; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
914; GFX7-NEXT:    s_endpgm
915;
916; GFX10-WGP-LABEL: flat_workgroup_acq_rel_atomicrmw:
917; GFX10-WGP:       ; %bb.0: ; %entry
918; GFX10-WGP-NEXT:    s_clause 0x1
919; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
920; GFX10-WGP-NEXT:    s_load_dword s2, s[4:5], 0x8
921; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
922; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
923; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
924; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
925; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
926; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
927; GFX10-WGP-NEXT:    flat_atomic_swap v[0:1], v2
928; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
929; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
930; GFX10-WGP-NEXT:    buffer_gl0_inv
931; GFX10-WGP-NEXT:    s_endpgm
932;
933; GFX10-CU-LABEL: flat_workgroup_acq_rel_atomicrmw:
934; GFX10-CU:       ; %bb.0: ; %entry
935; GFX10-CU-NEXT:    s_clause 0x1
936; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
937; GFX10-CU-NEXT:    s_load_dword s2, s[4:5], 0x8
938; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
939; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
940; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
941; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
942; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
943; GFX10-CU-NEXT:    flat_atomic_swap v[0:1], v2
944; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
945; GFX10-CU-NEXT:    s_endpgm
946;
947; SKIP-CACHE-INV-LABEL: flat_workgroup_acq_rel_atomicrmw:
948; SKIP-CACHE-INV:       ; %bb.0: ; %entry
949; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
950; SKIP-CACHE-INV-NEXT:    s_load_dword s0, s[0:1], 0xb
951; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
952; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
953; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
954; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
955; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
956; SKIP-CACHE-INV-NEXT:    flat_atomic_swap v[0:1], v2
957; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
958; SKIP-CACHE-INV-NEXT:    s_endpgm
959;
960; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_acq_rel_atomicrmw:
961; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
962; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
963; GFX90A-NOTTGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x8
964; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
965; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
966; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
967; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
968; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_swap v[0:1], v2
969; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
970; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
971;
972; GFX90A-TGSPLIT-LABEL: flat_workgroup_acq_rel_atomicrmw:
973; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
974; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
975; GFX90A-TGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x8
976; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
977; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
978; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
979; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
980; GFX90A-TGSPLIT-NEXT:    flat_atomic_swap v[0:1], v2
981; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
982; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
983; GFX90A-TGSPLIT-NEXT:    s_endpgm
984    i32* %out, i32 %in) {
985entry:
986  %val = atomicrmw volatile xchg i32* %out, i32 %in syncscope("workgroup") acq_rel
987  ret void
988}
989
990define amdgpu_kernel void @flat_workgroup_seq_cst_atomicrmw(
991; GFX7-LABEL: flat_workgroup_seq_cst_atomicrmw:
992; GFX7:       ; %bb.0: ; %entry
993; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
994; GFX7-NEXT:    s_load_dword s2, s[4:5], 0x2
995; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
996; GFX7-NEXT:    v_mov_b32_e32 v0, s0
997; GFX7-NEXT:    v_mov_b32_e32 v1, s1
998; GFX7-NEXT:    v_mov_b32_e32 v2, s2
999; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
1000; GFX7-NEXT:    flat_atomic_swap v[0:1], v2
1001; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
1002; GFX7-NEXT:    s_endpgm
1003;
1004; GFX10-WGP-LABEL: flat_workgroup_seq_cst_atomicrmw:
1005; GFX10-WGP:       ; %bb.0: ; %entry
1006; GFX10-WGP-NEXT:    s_clause 0x1
1007; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1008; GFX10-WGP-NEXT:    s_load_dword s2, s[4:5], 0x8
1009; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
1010; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
1011; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
1012; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
1013; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
1014; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
1015; GFX10-WGP-NEXT:    flat_atomic_swap v[0:1], v2
1016; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
1017; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
1018; GFX10-WGP-NEXT:    buffer_gl0_inv
1019; GFX10-WGP-NEXT:    s_endpgm
1020;
1021; GFX10-CU-LABEL: flat_workgroup_seq_cst_atomicrmw:
1022; GFX10-CU:       ; %bb.0: ; %entry
1023; GFX10-CU-NEXT:    s_clause 0x1
1024; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1025; GFX10-CU-NEXT:    s_load_dword s2, s[4:5], 0x8
1026; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
1027; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
1028; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
1029; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
1030; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
1031; GFX10-CU-NEXT:    flat_atomic_swap v[0:1], v2
1032; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
1033; GFX10-CU-NEXT:    s_endpgm
1034;
1035; SKIP-CACHE-INV-LABEL: flat_workgroup_seq_cst_atomicrmw:
1036; SKIP-CACHE-INV:       ; %bb.0: ; %entry
1037; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
1038; SKIP-CACHE-INV-NEXT:    s_load_dword s0, s[0:1], 0xb
1039; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
1040; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
1041; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
1042; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
1043; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
1044; SKIP-CACHE-INV-NEXT:    flat_atomic_swap v[0:1], v2
1045; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
1046; SKIP-CACHE-INV-NEXT:    s_endpgm
1047;
1048; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_seq_cst_atomicrmw:
1049; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
1050; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1051; GFX90A-NOTTGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x8
1052; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
1053; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
1054; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
1055; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
1056; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_swap v[0:1], v2
1057; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
1058; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
1059;
1060; GFX90A-TGSPLIT-LABEL: flat_workgroup_seq_cst_atomicrmw:
1061; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
1062; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1063; GFX90A-TGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x8
1064; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
1065; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
1066; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
1067; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
1068; GFX90A-TGSPLIT-NEXT:    flat_atomic_swap v[0:1], v2
1069; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
1070; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
1071; GFX90A-TGSPLIT-NEXT:    s_endpgm
1072    i32* %out, i32 %in) {
1073entry:
1074  %val = atomicrmw volatile xchg i32* %out, i32 %in syncscope("workgroup") seq_cst
1075  ret void
1076}
1077
1078define amdgpu_kernel void @flat_workgroup_acquire_ret_atomicrmw(
1079; GFX7-LABEL: flat_workgroup_acquire_ret_atomicrmw:
1080; GFX7:       ; %bb.0: ; %entry
1081; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1082; GFX7-NEXT:    s_load_dword s2, s[4:5], 0x2
1083; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
1084; GFX7-NEXT:    v_mov_b32_e32 v0, s0
1085; GFX7-NEXT:    v_mov_b32_e32 v1, s1
1086; GFX7-NEXT:    v_mov_b32_e32 v2, s2
1087; GFX7-NEXT:    flat_atomic_swap v2, v[0:1], v2 glc
1088; GFX7-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
1089; GFX7-NEXT:    flat_store_dword v[0:1], v2
1090; GFX7-NEXT:    s_endpgm
1091;
1092; GFX10-WGP-LABEL: flat_workgroup_acquire_ret_atomicrmw:
1093; GFX10-WGP:       ; %bb.0: ; %entry
1094; GFX10-WGP-NEXT:    s_clause 0x1
1095; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1096; GFX10-WGP-NEXT:    s_load_dword s2, s[4:5], 0x8
1097; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
1098; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
1099; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
1100; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
1101; GFX10-WGP-NEXT:    flat_atomic_swap v2, v[0:1], v2 glc
1102; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
1103; GFX10-WGP-NEXT:    buffer_gl0_inv
1104; GFX10-WGP-NEXT:    flat_store_dword v[0:1], v2
1105; GFX10-WGP-NEXT:    s_endpgm
1106;
1107; GFX10-CU-LABEL: flat_workgroup_acquire_ret_atomicrmw:
1108; GFX10-CU:       ; %bb.0: ; %entry
1109; GFX10-CU-NEXT:    s_clause 0x1
1110; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1111; GFX10-CU-NEXT:    s_load_dword s2, s[4:5], 0x8
1112; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
1113; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
1114; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
1115; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
1116; GFX10-CU-NEXT:    flat_atomic_swap v2, v[0:1], v2 glc
1117; GFX10-CU-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
1118; GFX10-CU-NEXT:    flat_store_dword v[0:1], v2
1119; GFX10-CU-NEXT:    s_endpgm
1120;
1121; SKIP-CACHE-INV-LABEL: flat_workgroup_acquire_ret_atomicrmw:
1122; SKIP-CACHE-INV:       ; %bb.0: ; %entry
1123; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
1124; SKIP-CACHE-INV-NEXT:    s_load_dword s0, s[0:1], 0xb
1125; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
1126; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
1127; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
1128; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
1129; SKIP-CACHE-INV-NEXT:    flat_atomic_swap v2, v[0:1], v2 glc
1130; SKIP-CACHE-INV-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
1131; SKIP-CACHE-INV-NEXT:    flat_store_dword v[0:1], v2
1132; SKIP-CACHE-INV-NEXT:    s_endpgm
1133;
1134; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_acquire_ret_atomicrmw:
1135; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
1136; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1137; GFX90A-NOTTGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x8
1138; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
1139; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
1140; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
1141; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_swap v2, v[0:1], v2 glc
1142; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
1143; GFX90A-NOTTGSPLIT-NEXT:    flat_store_dword v[0:1], v2
1144; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
1145;
1146; GFX90A-TGSPLIT-LABEL: flat_workgroup_acquire_ret_atomicrmw:
1147; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
1148; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1149; GFX90A-TGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x8
1150; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
1151; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
1152; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
1153; GFX90A-TGSPLIT-NEXT:    flat_atomic_swap v2, v[0:1], v2 glc
1154; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
1155; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
1156; GFX90A-TGSPLIT-NEXT:    flat_store_dword v[0:1], v2
1157; GFX90A-TGSPLIT-NEXT:    s_endpgm
1158    i32* %out, i32 %in) {
1159entry:
1160  %val = atomicrmw volatile xchg i32* %out, i32 %in syncscope("workgroup") acquire
1161  store i32 %val, i32* %out, align 4
1162  ret void
1163}
1164
1165define amdgpu_kernel void @flat_workgroup_acq_rel_ret_atomicrmw(
1166; GFX7-LABEL: flat_workgroup_acq_rel_ret_atomicrmw:
1167; GFX7:       ; %bb.0: ; %entry
1168; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1169; GFX7-NEXT:    s_load_dword s2, s[4:5], 0x2
1170; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
1171; GFX7-NEXT:    v_mov_b32_e32 v0, s0
1172; GFX7-NEXT:    v_mov_b32_e32 v1, s1
1173; GFX7-NEXT:    v_mov_b32_e32 v2, s2
1174; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
1175; GFX7-NEXT:    flat_atomic_swap v2, v[0:1], v2 glc
1176; GFX7-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
1177; GFX7-NEXT:    flat_store_dword v[0:1], v2
1178; GFX7-NEXT:    s_endpgm
1179;
1180; GFX10-WGP-LABEL: flat_workgroup_acq_rel_ret_atomicrmw:
1181; GFX10-WGP:       ; %bb.0: ; %entry
1182; GFX10-WGP-NEXT:    s_clause 0x1
1183; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1184; GFX10-WGP-NEXT:    s_load_dword s2, s[4:5], 0x8
1185; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
1186; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
1187; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
1188; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
1189; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
1190; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
1191; GFX10-WGP-NEXT:    flat_atomic_swap v2, v[0:1], v2 glc
1192; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
1193; GFX10-WGP-NEXT:    buffer_gl0_inv
1194; GFX10-WGP-NEXT:    flat_store_dword v[0:1], v2
1195; GFX10-WGP-NEXT:    s_endpgm
1196;
1197; GFX10-CU-LABEL: flat_workgroup_acq_rel_ret_atomicrmw:
1198; GFX10-CU:       ; %bb.0: ; %entry
1199; GFX10-CU-NEXT:    s_clause 0x1
1200; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1201; GFX10-CU-NEXT:    s_load_dword s2, s[4:5], 0x8
1202; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
1203; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
1204; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
1205; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
1206; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
1207; GFX10-CU-NEXT:    flat_atomic_swap v2, v[0:1], v2 glc
1208; GFX10-CU-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
1209; GFX10-CU-NEXT:    flat_store_dword v[0:1], v2
1210; GFX10-CU-NEXT:    s_endpgm
1211;
1212; SKIP-CACHE-INV-LABEL: flat_workgroup_acq_rel_ret_atomicrmw:
1213; SKIP-CACHE-INV:       ; %bb.0: ; %entry
1214; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
1215; SKIP-CACHE-INV-NEXT:    s_load_dword s0, s[0:1], 0xb
1216; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
1217; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
1218; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
1219; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
1220; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
1221; SKIP-CACHE-INV-NEXT:    flat_atomic_swap v2, v[0:1], v2 glc
1222; SKIP-CACHE-INV-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
1223; SKIP-CACHE-INV-NEXT:    flat_store_dword v[0:1], v2
1224; SKIP-CACHE-INV-NEXT:    s_endpgm
1225;
1226; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_acq_rel_ret_atomicrmw:
1227; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
1228; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1229; GFX90A-NOTTGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x8
1230; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
1231; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
1232; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
1233; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
1234; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_swap v2, v[0:1], v2 glc
1235; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
1236; GFX90A-NOTTGSPLIT-NEXT:    flat_store_dword v[0:1], v2
1237; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
1238;
1239; GFX90A-TGSPLIT-LABEL: flat_workgroup_acq_rel_ret_atomicrmw:
1240; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
1241; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1242; GFX90A-TGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x8
1243; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
1244; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
1245; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
1246; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
1247; GFX90A-TGSPLIT-NEXT:    flat_atomic_swap v2, v[0:1], v2 glc
1248; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
1249; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
1250; GFX90A-TGSPLIT-NEXT:    flat_store_dword v[0:1], v2
1251; GFX90A-TGSPLIT-NEXT:    s_endpgm
1252    i32* %out, i32 %in) {
1253entry:
1254  %val = atomicrmw volatile xchg i32* %out, i32 %in syncscope("workgroup") acq_rel
1255  store i32 %val, i32* %out, align 4
1256  ret void
1257}
1258
1259define amdgpu_kernel void @flat_workgroup_seq_cst_ret_atomicrmw(
1260; GFX7-LABEL: flat_workgroup_seq_cst_ret_atomicrmw:
1261; GFX7:       ; %bb.0: ; %entry
1262; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1263; GFX7-NEXT:    s_load_dword s2, s[4:5], 0x2
1264; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
1265; GFX7-NEXT:    v_mov_b32_e32 v0, s0
1266; GFX7-NEXT:    v_mov_b32_e32 v1, s1
1267; GFX7-NEXT:    v_mov_b32_e32 v2, s2
1268; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
1269; GFX7-NEXT:    flat_atomic_swap v2, v[0:1], v2 glc
1270; GFX7-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
1271; GFX7-NEXT:    flat_store_dword v[0:1], v2
1272; GFX7-NEXT:    s_endpgm
1273;
1274; GFX10-WGP-LABEL: flat_workgroup_seq_cst_ret_atomicrmw:
1275; GFX10-WGP:       ; %bb.0: ; %entry
1276; GFX10-WGP-NEXT:    s_clause 0x1
1277; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1278; GFX10-WGP-NEXT:    s_load_dword s2, s[4:5], 0x8
1279; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
1280; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
1281; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
1282; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
1283; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
1284; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
1285; GFX10-WGP-NEXT:    flat_atomic_swap v2, v[0:1], v2 glc
1286; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
1287; GFX10-WGP-NEXT:    buffer_gl0_inv
1288; GFX10-WGP-NEXT:    flat_store_dword v[0:1], v2
1289; GFX10-WGP-NEXT:    s_endpgm
1290;
1291; GFX10-CU-LABEL: flat_workgroup_seq_cst_ret_atomicrmw:
1292; GFX10-CU:       ; %bb.0: ; %entry
1293; GFX10-CU-NEXT:    s_clause 0x1
1294; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1295; GFX10-CU-NEXT:    s_load_dword s2, s[4:5], 0x8
1296; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
1297; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
1298; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
1299; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
1300; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
1301; GFX10-CU-NEXT:    flat_atomic_swap v2, v[0:1], v2 glc
1302; GFX10-CU-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
1303; GFX10-CU-NEXT:    flat_store_dword v[0:1], v2
1304; GFX10-CU-NEXT:    s_endpgm
1305;
1306; SKIP-CACHE-INV-LABEL: flat_workgroup_seq_cst_ret_atomicrmw:
1307; SKIP-CACHE-INV:       ; %bb.0: ; %entry
1308; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
1309; SKIP-CACHE-INV-NEXT:    s_load_dword s0, s[0:1], 0xb
1310; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
1311; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
1312; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
1313; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
1314; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
1315; SKIP-CACHE-INV-NEXT:    flat_atomic_swap v2, v[0:1], v2 glc
1316; SKIP-CACHE-INV-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
1317; SKIP-CACHE-INV-NEXT:    flat_store_dword v[0:1], v2
1318; SKIP-CACHE-INV-NEXT:    s_endpgm
1319;
1320; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_seq_cst_ret_atomicrmw:
1321; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
1322; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1323; GFX90A-NOTTGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x8
1324; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
1325; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
1326; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
1327; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
1328; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_swap v2, v[0:1], v2 glc
1329; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
1330; GFX90A-NOTTGSPLIT-NEXT:    flat_store_dword v[0:1], v2
1331; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
1332;
1333; GFX90A-TGSPLIT-LABEL: flat_workgroup_seq_cst_ret_atomicrmw:
1334; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
1335; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1336; GFX90A-TGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x8
1337; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
1338; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
1339; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
1340; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
1341; GFX90A-TGSPLIT-NEXT:    flat_atomic_swap v2, v[0:1], v2 glc
1342; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
1343; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
1344; GFX90A-TGSPLIT-NEXT:    flat_store_dword v[0:1], v2
1345; GFX90A-TGSPLIT-NEXT:    s_endpgm
1346    i32* %out, i32 %in) {
1347entry:
1348  %val = atomicrmw volatile xchg i32* %out, i32 %in syncscope("workgroup") seq_cst
1349  store i32 %val, i32* %out, align 4
1350  ret void
1351}
1352
1353define amdgpu_kernel void @flat_workgroup_monotonic_monotonic_cmpxchg(
1354; GFX7-LABEL: flat_workgroup_monotonic_monotonic_cmpxchg:
1355; GFX7:       ; %bb.0: ; %entry
1356; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1357; GFX7-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x2
1358; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
1359; GFX7-NEXT:    s_add_u32 s0, s0, 16
1360; GFX7-NEXT:    s_addc_u32 s1, s1, 0
1361; GFX7-NEXT:    v_mov_b32_e32 v0, s0
1362; GFX7-NEXT:    v_mov_b32_e32 v2, s2
1363; GFX7-NEXT:    v_mov_b32_e32 v1, s1
1364; GFX7-NEXT:    v_mov_b32_e32 v3, s3
1365; GFX7-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
1366; GFX7-NEXT:    s_endpgm
1367;
1368; GFX10-WGP-LABEL: flat_workgroup_monotonic_monotonic_cmpxchg:
1369; GFX10-WGP:       ; %bb.0: ; %entry
1370; GFX10-WGP-NEXT:    s_clause 0x1
1371; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1372; GFX10-WGP-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
1373; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
1374; GFX10-WGP-NEXT:    s_add_u32 s0, s0, 16
1375; GFX10-WGP-NEXT:    s_addc_u32 s1, s1, 0
1376; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
1377; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
1378; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
1379; GFX10-WGP-NEXT:    v_mov_b32_e32 v3, s3
1380; GFX10-WGP-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
1381; GFX10-WGP-NEXT:    s_endpgm
1382;
1383; GFX10-CU-LABEL: flat_workgroup_monotonic_monotonic_cmpxchg:
1384; GFX10-CU:       ; %bb.0: ; %entry
1385; GFX10-CU-NEXT:    s_clause 0x1
1386; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1387; GFX10-CU-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
1388; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
1389; GFX10-CU-NEXT:    s_add_u32 s0, s0, 16
1390; GFX10-CU-NEXT:    s_addc_u32 s1, s1, 0
1391; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
1392; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
1393; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
1394; GFX10-CU-NEXT:    v_mov_b32_e32 v3, s3
1395; GFX10-CU-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
1396; GFX10-CU-NEXT:    s_endpgm
1397;
1398; SKIP-CACHE-INV-LABEL: flat_workgroup_monotonic_monotonic_cmpxchg:
1399; SKIP-CACHE-INV:       ; %bb.0: ; %entry
1400; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
1401; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
1402; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
1403; SKIP-CACHE-INV-NEXT:    s_add_u32 s2, s2, 16
1404; SKIP-CACHE-INV-NEXT:    s_addc_u32 s3, s3, 0
1405; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
1406; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s1
1407; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
1408; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
1409; SKIP-CACHE-INV-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
1410; SKIP-CACHE-INV-NEXT:    s_endpgm
1411;
1412; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_monotonic_monotonic_cmpxchg:
1413; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
1414; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1415; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
1416; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
1417; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
1418; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
1419; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
1420; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
1421;
1422; GFX90A-TGSPLIT-LABEL: flat_workgroup_monotonic_monotonic_cmpxchg:
1423; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
1424; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1425; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
1426; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
1427; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
1428; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
1429; GFX90A-TGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
1430; GFX90A-TGSPLIT-NEXT:    s_endpgm
1431    i32* %out, i32 %in, i32 %old) {
1432entry:
1433  %gep = getelementptr i32, i32* %out, i32 4
1434  %val = cmpxchg volatile i32* %gep, i32 %old, i32 %in syncscope("workgroup") monotonic monotonic
1435  ret void
1436}
1437
1438define amdgpu_kernel void @flat_workgroup_acquire_monotonic_cmpxchg(
1439; GFX7-LABEL: flat_workgroup_acquire_monotonic_cmpxchg:
1440; GFX7:       ; %bb.0: ; %entry
1441; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1442; GFX7-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x2
1443; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
1444; GFX7-NEXT:    s_add_u32 s0, s0, 16
1445; GFX7-NEXT:    s_addc_u32 s1, s1, 0
1446; GFX7-NEXT:    v_mov_b32_e32 v0, s0
1447; GFX7-NEXT:    v_mov_b32_e32 v2, s2
1448; GFX7-NEXT:    v_mov_b32_e32 v1, s1
1449; GFX7-NEXT:    v_mov_b32_e32 v3, s3
1450; GFX7-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
1451; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
1452; GFX7-NEXT:    s_endpgm
1453;
1454; GFX10-WGP-LABEL: flat_workgroup_acquire_monotonic_cmpxchg:
1455; GFX10-WGP:       ; %bb.0: ; %entry
1456; GFX10-WGP-NEXT:    s_clause 0x1
1457; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1458; GFX10-WGP-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
1459; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
1460; GFX10-WGP-NEXT:    s_add_u32 s0, s0, 16
1461; GFX10-WGP-NEXT:    s_addc_u32 s1, s1, 0
1462; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
1463; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
1464; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
1465; GFX10-WGP-NEXT:    v_mov_b32_e32 v3, s3
1466; GFX10-WGP-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
1467; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
1468; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
1469; GFX10-WGP-NEXT:    buffer_gl0_inv
1470; GFX10-WGP-NEXT:    s_endpgm
1471;
1472; GFX10-CU-LABEL: flat_workgroup_acquire_monotonic_cmpxchg:
1473; GFX10-CU:       ; %bb.0: ; %entry
1474; GFX10-CU-NEXT:    s_clause 0x1
1475; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1476; GFX10-CU-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
1477; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
1478; GFX10-CU-NEXT:    s_add_u32 s0, s0, 16
1479; GFX10-CU-NEXT:    s_addc_u32 s1, s1, 0
1480; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
1481; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
1482; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
1483; GFX10-CU-NEXT:    v_mov_b32_e32 v3, s3
1484; GFX10-CU-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
1485; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
1486; GFX10-CU-NEXT:    s_endpgm
1487;
1488; SKIP-CACHE-INV-LABEL: flat_workgroup_acquire_monotonic_cmpxchg:
1489; SKIP-CACHE-INV:       ; %bb.0: ; %entry
1490; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
1491; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
1492; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
1493; SKIP-CACHE-INV-NEXT:    s_add_u32 s2, s2, 16
1494; SKIP-CACHE-INV-NEXT:    s_addc_u32 s3, s3, 0
1495; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
1496; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s1
1497; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
1498; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
1499; SKIP-CACHE-INV-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
1500; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
1501; SKIP-CACHE-INV-NEXT:    s_endpgm
1502;
1503; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_acquire_monotonic_cmpxchg:
1504; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
1505; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1506; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
1507; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
1508; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
1509; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
1510; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
1511; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
1512; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
1513;
1514; GFX90A-TGSPLIT-LABEL: flat_workgroup_acquire_monotonic_cmpxchg:
1515; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
1516; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1517; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
1518; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
1519; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
1520; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
1521; GFX90A-TGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
1522; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
1523; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
1524; GFX90A-TGSPLIT-NEXT:    s_endpgm
1525    i32* %out, i32 %in, i32 %old) {
1526entry:
1527  %gep = getelementptr i32, i32* %out, i32 4
1528  %val = cmpxchg volatile i32* %gep, i32 %old, i32 %in syncscope("workgroup") acquire monotonic
1529  ret void
1530}
1531
1532define amdgpu_kernel void @flat_workgroup_release_monotonic_cmpxchg(
1533; GFX7-LABEL: flat_workgroup_release_monotonic_cmpxchg:
1534; GFX7:       ; %bb.0: ; %entry
1535; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1536; GFX7-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x2
1537; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
1538; GFX7-NEXT:    s_add_u32 s0, s0, 16
1539; GFX7-NEXT:    s_addc_u32 s1, s1, 0
1540; GFX7-NEXT:    v_mov_b32_e32 v0, s0
1541; GFX7-NEXT:    v_mov_b32_e32 v2, s2
1542; GFX7-NEXT:    v_mov_b32_e32 v1, s1
1543; GFX7-NEXT:    v_mov_b32_e32 v3, s3
1544; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
1545; GFX7-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
1546; GFX7-NEXT:    s_endpgm
1547;
1548; GFX10-WGP-LABEL: flat_workgroup_release_monotonic_cmpxchg:
1549; GFX10-WGP:       ; %bb.0: ; %entry
1550; GFX10-WGP-NEXT:    s_clause 0x1
1551; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1552; GFX10-WGP-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
1553; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
1554; GFX10-WGP-NEXT:    s_add_u32 s0, s0, 16
1555; GFX10-WGP-NEXT:    s_addc_u32 s1, s1, 0
1556; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
1557; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
1558; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
1559; GFX10-WGP-NEXT:    v_mov_b32_e32 v3, s3
1560; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
1561; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
1562; GFX10-WGP-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
1563; GFX10-WGP-NEXT:    s_endpgm
1564;
1565; GFX10-CU-LABEL: flat_workgroup_release_monotonic_cmpxchg:
1566; GFX10-CU:       ; %bb.0: ; %entry
1567; GFX10-CU-NEXT:    s_clause 0x1
1568; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1569; GFX10-CU-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
1570; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
1571; GFX10-CU-NEXT:    s_add_u32 s0, s0, 16
1572; GFX10-CU-NEXT:    s_addc_u32 s1, s1, 0
1573; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
1574; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
1575; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
1576; GFX10-CU-NEXT:    v_mov_b32_e32 v3, s3
1577; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
1578; GFX10-CU-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
1579; GFX10-CU-NEXT:    s_endpgm
1580;
1581; SKIP-CACHE-INV-LABEL: flat_workgroup_release_monotonic_cmpxchg:
1582; SKIP-CACHE-INV:       ; %bb.0: ; %entry
1583; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
1584; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
1585; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
1586; SKIP-CACHE-INV-NEXT:    s_add_u32 s2, s2, 16
1587; SKIP-CACHE-INV-NEXT:    s_addc_u32 s3, s3, 0
1588; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
1589; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s1
1590; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
1591; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
1592; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
1593; SKIP-CACHE-INV-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
1594; SKIP-CACHE-INV-NEXT:    s_endpgm
1595;
1596; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_release_monotonic_cmpxchg:
1597; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
1598; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1599; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
1600; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
1601; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
1602; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
1603; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
1604; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
1605; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
1606;
1607; GFX90A-TGSPLIT-LABEL: flat_workgroup_release_monotonic_cmpxchg:
1608; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
1609; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1610; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
1611; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
1612; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
1613; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
1614; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
1615; GFX90A-TGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
1616; GFX90A-TGSPLIT-NEXT:    s_endpgm
1617    i32* %out, i32 %in, i32 %old) {
1618entry:
1619  %gep = getelementptr i32, i32* %out, i32 4
1620  %val = cmpxchg volatile i32* %gep, i32 %old, i32 %in syncscope("workgroup") release monotonic
1621  ret void
1622}
1623
1624define amdgpu_kernel void @flat_workgroup_acq_rel_monotonic_cmpxchg(
1625; GFX7-LABEL: flat_workgroup_acq_rel_monotonic_cmpxchg:
1626; GFX7:       ; %bb.0: ; %entry
1627; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1628; GFX7-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x2
1629; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
1630; GFX7-NEXT:    s_add_u32 s0, s0, 16
1631; GFX7-NEXT:    s_addc_u32 s1, s1, 0
1632; GFX7-NEXT:    v_mov_b32_e32 v0, s0
1633; GFX7-NEXT:    v_mov_b32_e32 v2, s2
1634; GFX7-NEXT:    v_mov_b32_e32 v1, s1
1635; GFX7-NEXT:    v_mov_b32_e32 v3, s3
1636; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
1637; GFX7-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
1638; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
1639; GFX7-NEXT:    s_endpgm
1640;
1641; GFX10-WGP-LABEL: flat_workgroup_acq_rel_monotonic_cmpxchg:
1642; GFX10-WGP:       ; %bb.0: ; %entry
1643; GFX10-WGP-NEXT:    s_clause 0x1
1644; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1645; GFX10-WGP-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
1646; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
1647; GFX10-WGP-NEXT:    s_add_u32 s0, s0, 16
1648; GFX10-WGP-NEXT:    s_addc_u32 s1, s1, 0
1649; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
1650; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
1651; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
1652; GFX10-WGP-NEXT:    v_mov_b32_e32 v3, s3
1653; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
1654; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
1655; GFX10-WGP-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
1656; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
1657; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
1658; GFX10-WGP-NEXT:    buffer_gl0_inv
1659; GFX10-WGP-NEXT:    s_endpgm
1660;
1661; GFX10-CU-LABEL: flat_workgroup_acq_rel_monotonic_cmpxchg:
1662; GFX10-CU:       ; %bb.0: ; %entry
1663; GFX10-CU-NEXT:    s_clause 0x1
1664; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1665; GFX10-CU-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
1666; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
1667; GFX10-CU-NEXT:    s_add_u32 s0, s0, 16
1668; GFX10-CU-NEXT:    s_addc_u32 s1, s1, 0
1669; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
1670; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
1671; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
1672; GFX10-CU-NEXT:    v_mov_b32_e32 v3, s3
1673; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
1674; GFX10-CU-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
1675; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
1676; GFX10-CU-NEXT:    s_endpgm
1677;
1678; SKIP-CACHE-INV-LABEL: flat_workgroup_acq_rel_monotonic_cmpxchg:
1679; SKIP-CACHE-INV:       ; %bb.0: ; %entry
1680; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
1681; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
1682; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
1683; SKIP-CACHE-INV-NEXT:    s_add_u32 s2, s2, 16
1684; SKIP-CACHE-INV-NEXT:    s_addc_u32 s3, s3, 0
1685; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
1686; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s1
1687; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
1688; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
1689; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
1690; SKIP-CACHE-INV-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
1691; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
1692; SKIP-CACHE-INV-NEXT:    s_endpgm
1693;
1694; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_acq_rel_monotonic_cmpxchg:
1695; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
1696; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1697; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
1698; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
1699; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
1700; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
1701; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
1702; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
1703; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
1704; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
1705;
1706; GFX90A-TGSPLIT-LABEL: flat_workgroup_acq_rel_monotonic_cmpxchg:
1707; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
1708; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1709; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
1710; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
1711; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
1712; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
1713; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
1714; GFX90A-TGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
1715; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
1716; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
1717; GFX90A-TGSPLIT-NEXT:    s_endpgm
1718    i32* %out, i32 %in, i32 %old) {
1719entry:
1720  %gep = getelementptr i32, i32* %out, i32 4
1721  %val = cmpxchg volatile i32* %gep, i32 %old, i32 %in syncscope("workgroup") acq_rel monotonic
1722  ret void
1723}
1724
1725define amdgpu_kernel void @flat_workgroup_seq_cst_monotonic_cmpxchg(
1726; GFX7-LABEL: flat_workgroup_seq_cst_monotonic_cmpxchg:
1727; GFX7:       ; %bb.0: ; %entry
1728; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1729; GFX7-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x2
1730; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
1731; GFX7-NEXT:    s_add_u32 s0, s0, 16
1732; GFX7-NEXT:    s_addc_u32 s1, s1, 0
1733; GFX7-NEXT:    v_mov_b32_e32 v0, s0
1734; GFX7-NEXT:    v_mov_b32_e32 v2, s2
1735; GFX7-NEXT:    v_mov_b32_e32 v1, s1
1736; GFX7-NEXT:    v_mov_b32_e32 v3, s3
1737; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
1738; GFX7-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
1739; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
1740; GFX7-NEXT:    s_endpgm
1741;
1742; GFX10-WGP-LABEL: flat_workgroup_seq_cst_monotonic_cmpxchg:
1743; GFX10-WGP:       ; %bb.0: ; %entry
1744; GFX10-WGP-NEXT:    s_clause 0x1
1745; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1746; GFX10-WGP-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
1747; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
1748; GFX10-WGP-NEXT:    s_add_u32 s0, s0, 16
1749; GFX10-WGP-NEXT:    s_addc_u32 s1, s1, 0
1750; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
1751; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
1752; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
1753; GFX10-WGP-NEXT:    v_mov_b32_e32 v3, s3
1754; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
1755; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
1756; GFX10-WGP-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
1757; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
1758; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
1759; GFX10-WGP-NEXT:    buffer_gl0_inv
1760; GFX10-WGP-NEXT:    s_endpgm
1761;
1762; GFX10-CU-LABEL: flat_workgroup_seq_cst_monotonic_cmpxchg:
1763; GFX10-CU:       ; %bb.0: ; %entry
1764; GFX10-CU-NEXT:    s_clause 0x1
1765; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1766; GFX10-CU-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
1767; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
1768; GFX10-CU-NEXT:    s_add_u32 s0, s0, 16
1769; GFX10-CU-NEXT:    s_addc_u32 s1, s1, 0
1770; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
1771; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
1772; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
1773; GFX10-CU-NEXT:    v_mov_b32_e32 v3, s3
1774; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
1775; GFX10-CU-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
1776; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
1777; GFX10-CU-NEXT:    s_endpgm
1778;
1779; SKIP-CACHE-INV-LABEL: flat_workgroup_seq_cst_monotonic_cmpxchg:
1780; SKIP-CACHE-INV:       ; %bb.0: ; %entry
1781; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
1782; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
1783; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
1784; SKIP-CACHE-INV-NEXT:    s_add_u32 s2, s2, 16
1785; SKIP-CACHE-INV-NEXT:    s_addc_u32 s3, s3, 0
1786; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
1787; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s1
1788; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
1789; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
1790; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
1791; SKIP-CACHE-INV-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
1792; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
1793; SKIP-CACHE-INV-NEXT:    s_endpgm
1794;
1795; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_seq_cst_monotonic_cmpxchg:
1796; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
1797; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1798; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
1799; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
1800; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
1801; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
1802; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
1803; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
1804; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
1805; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
1806;
1807; GFX90A-TGSPLIT-LABEL: flat_workgroup_seq_cst_monotonic_cmpxchg:
1808; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
1809; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1810; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
1811; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
1812; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
1813; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
1814; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
1815; GFX90A-TGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
1816; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
1817; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
1818; GFX90A-TGSPLIT-NEXT:    s_endpgm
1819    i32* %out, i32 %in, i32 %old) {
1820entry:
1821  %gep = getelementptr i32, i32* %out, i32 4
1822  %val = cmpxchg volatile i32* %gep, i32 %old, i32 %in syncscope("workgroup") seq_cst monotonic
1823  ret void
1824}
1825
1826define amdgpu_kernel void @flat_workgroup_acquire_acquire_cmpxchg(
1827; GFX7-LABEL: flat_workgroup_acquire_acquire_cmpxchg:
1828; GFX7:       ; %bb.0: ; %entry
1829; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1830; GFX7-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x2
1831; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
1832; GFX7-NEXT:    s_add_u32 s0, s0, 16
1833; GFX7-NEXT:    s_addc_u32 s1, s1, 0
1834; GFX7-NEXT:    v_mov_b32_e32 v0, s0
1835; GFX7-NEXT:    v_mov_b32_e32 v2, s2
1836; GFX7-NEXT:    v_mov_b32_e32 v1, s1
1837; GFX7-NEXT:    v_mov_b32_e32 v3, s3
1838; GFX7-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
1839; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
1840; GFX7-NEXT:    s_endpgm
1841;
1842; GFX10-WGP-LABEL: flat_workgroup_acquire_acquire_cmpxchg:
1843; GFX10-WGP:       ; %bb.0: ; %entry
1844; GFX10-WGP-NEXT:    s_clause 0x1
1845; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1846; GFX10-WGP-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
1847; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
1848; GFX10-WGP-NEXT:    s_add_u32 s0, s0, 16
1849; GFX10-WGP-NEXT:    s_addc_u32 s1, s1, 0
1850; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
1851; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
1852; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
1853; GFX10-WGP-NEXT:    v_mov_b32_e32 v3, s3
1854; GFX10-WGP-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
1855; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
1856; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
1857; GFX10-WGP-NEXT:    buffer_gl0_inv
1858; GFX10-WGP-NEXT:    s_endpgm
1859;
1860; GFX10-CU-LABEL: flat_workgroup_acquire_acquire_cmpxchg:
1861; GFX10-CU:       ; %bb.0: ; %entry
1862; GFX10-CU-NEXT:    s_clause 0x1
1863; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1864; GFX10-CU-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
1865; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
1866; GFX10-CU-NEXT:    s_add_u32 s0, s0, 16
1867; GFX10-CU-NEXT:    s_addc_u32 s1, s1, 0
1868; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
1869; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
1870; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
1871; GFX10-CU-NEXT:    v_mov_b32_e32 v3, s3
1872; GFX10-CU-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
1873; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
1874; GFX10-CU-NEXT:    s_endpgm
1875;
1876; SKIP-CACHE-INV-LABEL: flat_workgroup_acquire_acquire_cmpxchg:
1877; SKIP-CACHE-INV:       ; %bb.0: ; %entry
1878; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
1879; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
1880; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
1881; SKIP-CACHE-INV-NEXT:    s_add_u32 s2, s2, 16
1882; SKIP-CACHE-INV-NEXT:    s_addc_u32 s3, s3, 0
1883; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
1884; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s1
1885; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
1886; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
1887; SKIP-CACHE-INV-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
1888; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
1889; SKIP-CACHE-INV-NEXT:    s_endpgm
1890;
1891; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_acquire_acquire_cmpxchg:
1892; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
1893; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1894; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
1895; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
1896; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
1897; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
1898; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
1899; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
1900; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
1901;
1902; GFX90A-TGSPLIT-LABEL: flat_workgroup_acquire_acquire_cmpxchg:
1903; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
1904; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1905; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
1906; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
1907; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
1908; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
1909; GFX90A-TGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
1910; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
1911; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
1912; GFX90A-TGSPLIT-NEXT:    s_endpgm
1913    i32* %out, i32 %in, i32 %old) {
1914entry:
1915  %gep = getelementptr i32, i32* %out, i32 4
1916  %val = cmpxchg volatile i32* %gep, i32 %old, i32 %in syncscope("workgroup") acquire acquire
1917  ret void
1918}
1919
1920define amdgpu_kernel void @flat_workgroup_release_acquire_cmpxchg(
1921; GFX7-LABEL: flat_workgroup_release_acquire_cmpxchg:
1922; GFX7:       ; %bb.0: ; %entry
1923; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1924; GFX7-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x2
1925; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
1926; GFX7-NEXT:    s_add_u32 s0, s0, 16
1927; GFX7-NEXT:    s_addc_u32 s1, s1, 0
1928; GFX7-NEXT:    v_mov_b32_e32 v0, s0
1929; GFX7-NEXT:    v_mov_b32_e32 v2, s2
1930; GFX7-NEXT:    v_mov_b32_e32 v1, s1
1931; GFX7-NEXT:    v_mov_b32_e32 v3, s3
1932; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
1933; GFX7-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
1934; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
1935; GFX7-NEXT:    s_endpgm
1936;
1937; GFX10-WGP-LABEL: flat_workgroup_release_acquire_cmpxchg:
1938; GFX10-WGP:       ; %bb.0: ; %entry
1939; GFX10-WGP-NEXT:    s_clause 0x1
1940; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1941; GFX10-WGP-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
1942; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
1943; GFX10-WGP-NEXT:    s_add_u32 s0, s0, 16
1944; GFX10-WGP-NEXT:    s_addc_u32 s1, s1, 0
1945; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
1946; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
1947; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
1948; GFX10-WGP-NEXT:    v_mov_b32_e32 v3, s3
1949; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
1950; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
1951; GFX10-WGP-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
1952; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
1953; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
1954; GFX10-WGP-NEXT:    buffer_gl0_inv
1955; GFX10-WGP-NEXT:    s_endpgm
1956;
1957; GFX10-CU-LABEL: flat_workgroup_release_acquire_cmpxchg:
1958; GFX10-CU:       ; %bb.0: ; %entry
1959; GFX10-CU-NEXT:    s_clause 0x1
1960; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1961; GFX10-CU-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
1962; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
1963; GFX10-CU-NEXT:    s_add_u32 s0, s0, 16
1964; GFX10-CU-NEXT:    s_addc_u32 s1, s1, 0
1965; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
1966; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
1967; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
1968; GFX10-CU-NEXT:    v_mov_b32_e32 v3, s3
1969; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
1970; GFX10-CU-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
1971; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
1972; GFX10-CU-NEXT:    s_endpgm
1973;
1974; SKIP-CACHE-INV-LABEL: flat_workgroup_release_acquire_cmpxchg:
1975; SKIP-CACHE-INV:       ; %bb.0: ; %entry
1976; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
1977; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
1978; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
1979; SKIP-CACHE-INV-NEXT:    s_add_u32 s2, s2, 16
1980; SKIP-CACHE-INV-NEXT:    s_addc_u32 s3, s3, 0
1981; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
1982; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s1
1983; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
1984; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
1985; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
1986; SKIP-CACHE-INV-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
1987; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
1988; SKIP-CACHE-INV-NEXT:    s_endpgm
1989;
1990; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_release_acquire_cmpxchg:
1991; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
1992; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
1993; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
1994; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
1995; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
1996; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
1997; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
1998; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
1999; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
2000; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
2001;
2002; GFX90A-TGSPLIT-LABEL: flat_workgroup_release_acquire_cmpxchg:
2003; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
2004; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2005; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
2006; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
2007; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
2008; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
2009; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
2010; GFX90A-TGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
2011; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
2012; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
2013; GFX90A-TGSPLIT-NEXT:    s_endpgm
2014    i32* %out, i32 %in, i32 %old) {
2015entry:
2016  %gep = getelementptr i32, i32* %out, i32 4
2017  %val = cmpxchg volatile i32* %gep, i32 %old, i32 %in syncscope("workgroup") release acquire
2018  ret void
2019}
2020
2021define amdgpu_kernel void @flat_workgroup_acq_rel_acquire_cmpxchg(
2022; GFX7-LABEL: flat_workgroup_acq_rel_acquire_cmpxchg:
2023; GFX7:       ; %bb.0: ; %entry
2024; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2025; GFX7-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x2
2026; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
2027; GFX7-NEXT:    s_add_u32 s0, s0, 16
2028; GFX7-NEXT:    s_addc_u32 s1, s1, 0
2029; GFX7-NEXT:    v_mov_b32_e32 v0, s0
2030; GFX7-NEXT:    v_mov_b32_e32 v2, s2
2031; GFX7-NEXT:    v_mov_b32_e32 v1, s1
2032; GFX7-NEXT:    v_mov_b32_e32 v3, s3
2033; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
2034; GFX7-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
2035; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
2036; GFX7-NEXT:    s_endpgm
2037;
2038; GFX10-WGP-LABEL: flat_workgroup_acq_rel_acquire_cmpxchg:
2039; GFX10-WGP:       ; %bb.0: ; %entry
2040; GFX10-WGP-NEXT:    s_clause 0x1
2041; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2042; GFX10-WGP-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
2043; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
2044; GFX10-WGP-NEXT:    s_add_u32 s0, s0, 16
2045; GFX10-WGP-NEXT:    s_addc_u32 s1, s1, 0
2046; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
2047; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
2048; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
2049; GFX10-WGP-NEXT:    v_mov_b32_e32 v3, s3
2050; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
2051; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
2052; GFX10-WGP-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
2053; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
2054; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
2055; GFX10-WGP-NEXT:    buffer_gl0_inv
2056; GFX10-WGP-NEXT:    s_endpgm
2057;
2058; GFX10-CU-LABEL: flat_workgroup_acq_rel_acquire_cmpxchg:
2059; GFX10-CU:       ; %bb.0: ; %entry
2060; GFX10-CU-NEXT:    s_clause 0x1
2061; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2062; GFX10-CU-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
2063; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
2064; GFX10-CU-NEXT:    s_add_u32 s0, s0, 16
2065; GFX10-CU-NEXT:    s_addc_u32 s1, s1, 0
2066; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
2067; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
2068; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
2069; GFX10-CU-NEXT:    v_mov_b32_e32 v3, s3
2070; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
2071; GFX10-CU-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
2072; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
2073; GFX10-CU-NEXT:    s_endpgm
2074;
2075; SKIP-CACHE-INV-LABEL: flat_workgroup_acq_rel_acquire_cmpxchg:
2076; SKIP-CACHE-INV:       ; %bb.0: ; %entry
2077; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
2078; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
2079; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
2080; SKIP-CACHE-INV-NEXT:    s_add_u32 s2, s2, 16
2081; SKIP-CACHE-INV-NEXT:    s_addc_u32 s3, s3, 0
2082; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
2083; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s1
2084; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
2085; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
2086; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
2087; SKIP-CACHE-INV-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
2088; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
2089; SKIP-CACHE-INV-NEXT:    s_endpgm
2090;
2091; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_acq_rel_acquire_cmpxchg:
2092; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
2093; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2094; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
2095; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
2096; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
2097; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
2098; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
2099; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
2100; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
2101; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
2102;
2103; GFX90A-TGSPLIT-LABEL: flat_workgroup_acq_rel_acquire_cmpxchg:
2104; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
2105; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2106; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
2107; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
2108; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
2109; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
2110; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
2111; GFX90A-TGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
2112; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
2113; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
2114; GFX90A-TGSPLIT-NEXT:    s_endpgm
2115    i32* %out, i32 %in, i32 %old) {
2116entry:
2117  %gep = getelementptr i32, i32* %out, i32 4
2118  %val = cmpxchg volatile i32* %gep, i32 %old, i32 %in syncscope("workgroup") acq_rel acquire
2119  ret void
2120}
2121
2122define amdgpu_kernel void @flat_workgroup_seq_cst_acquire_cmpxchg(
2123; GFX7-LABEL: flat_workgroup_seq_cst_acquire_cmpxchg:
2124; GFX7:       ; %bb.0: ; %entry
2125; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2126; GFX7-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x2
2127; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
2128; GFX7-NEXT:    s_add_u32 s0, s0, 16
2129; GFX7-NEXT:    s_addc_u32 s1, s1, 0
2130; GFX7-NEXT:    v_mov_b32_e32 v0, s0
2131; GFX7-NEXT:    v_mov_b32_e32 v2, s2
2132; GFX7-NEXT:    v_mov_b32_e32 v1, s1
2133; GFX7-NEXT:    v_mov_b32_e32 v3, s3
2134; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
2135; GFX7-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
2136; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
2137; GFX7-NEXT:    s_endpgm
2138;
2139; GFX10-WGP-LABEL: flat_workgroup_seq_cst_acquire_cmpxchg:
2140; GFX10-WGP:       ; %bb.0: ; %entry
2141; GFX10-WGP-NEXT:    s_clause 0x1
2142; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2143; GFX10-WGP-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
2144; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
2145; GFX10-WGP-NEXT:    s_add_u32 s0, s0, 16
2146; GFX10-WGP-NEXT:    s_addc_u32 s1, s1, 0
2147; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
2148; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
2149; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
2150; GFX10-WGP-NEXT:    v_mov_b32_e32 v3, s3
2151; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
2152; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
2153; GFX10-WGP-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
2154; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
2155; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
2156; GFX10-WGP-NEXT:    buffer_gl0_inv
2157; GFX10-WGP-NEXT:    s_endpgm
2158;
2159; GFX10-CU-LABEL: flat_workgroup_seq_cst_acquire_cmpxchg:
2160; GFX10-CU:       ; %bb.0: ; %entry
2161; GFX10-CU-NEXT:    s_clause 0x1
2162; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2163; GFX10-CU-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
2164; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
2165; GFX10-CU-NEXT:    s_add_u32 s0, s0, 16
2166; GFX10-CU-NEXT:    s_addc_u32 s1, s1, 0
2167; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
2168; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
2169; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
2170; GFX10-CU-NEXT:    v_mov_b32_e32 v3, s3
2171; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
2172; GFX10-CU-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
2173; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
2174; GFX10-CU-NEXT:    s_endpgm
2175;
2176; SKIP-CACHE-INV-LABEL: flat_workgroup_seq_cst_acquire_cmpxchg:
2177; SKIP-CACHE-INV:       ; %bb.0: ; %entry
2178; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
2179; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
2180; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
2181; SKIP-CACHE-INV-NEXT:    s_add_u32 s2, s2, 16
2182; SKIP-CACHE-INV-NEXT:    s_addc_u32 s3, s3, 0
2183; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
2184; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s1
2185; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
2186; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
2187; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
2188; SKIP-CACHE-INV-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
2189; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
2190; SKIP-CACHE-INV-NEXT:    s_endpgm
2191;
2192; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_seq_cst_acquire_cmpxchg:
2193; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
2194; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2195; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
2196; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
2197; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
2198; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
2199; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
2200; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
2201; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
2202; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
2203;
2204; GFX90A-TGSPLIT-LABEL: flat_workgroup_seq_cst_acquire_cmpxchg:
2205; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
2206; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2207; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
2208; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
2209; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
2210; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
2211; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
2212; GFX90A-TGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
2213; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
2214; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
2215; GFX90A-TGSPLIT-NEXT:    s_endpgm
2216    i32* %out, i32 %in, i32 %old) {
2217entry:
2218  %gep = getelementptr i32, i32* %out, i32 4
2219  %val = cmpxchg volatile i32* %gep, i32 %old, i32 %in syncscope("workgroup") seq_cst acquire
2220  ret void
2221}
2222
2223define amdgpu_kernel void @flat_workgroup_seq_cst_seq_cst_cmpxchg(
2224; GFX7-LABEL: flat_workgroup_seq_cst_seq_cst_cmpxchg:
2225; GFX7:       ; %bb.0: ; %entry
2226; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2227; GFX7-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x2
2228; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
2229; GFX7-NEXT:    s_add_u32 s0, s0, 16
2230; GFX7-NEXT:    s_addc_u32 s1, s1, 0
2231; GFX7-NEXT:    v_mov_b32_e32 v0, s0
2232; GFX7-NEXT:    v_mov_b32_e32 v2, s2
2233; GFX7-NEXT:    v_mov_b32_e32 v1, s1
2234; GFX7-NEXT:    v_mov_b32_e32 v3, s3
2235; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
2236; GFX7-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
2237; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
2238; GFX7-NEXT:    s_endpgm
2239;
2240; GFX10-WGP-LABEL: flat_workgroup_seq_cst_seq_cst_cmpxchg:
2241; GFX10-WGP:       ; %bb.0: ; %entry
2242; GFX10-WGP-NEXT:    s_clause 0x1
2243; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2244; GFX10-WGP-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
2245; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
2246; GFX10-WGP-NEXT:    s_add_u32 s0, s0, 16
2247; GFX10-WGP-NEXT:    s_addc_u32 s1, s1, 0
2248; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
2249; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
2250; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
2251; GFX10-WGP-NEXT:    v_mov_b32_e32 v3, s3
2252; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
2253; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
2254; GFX10-WGP-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
2255; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
2256; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
2257; GFX10-WGP-NEXT:    buffer_gl0_inv
2258; GFX10-WGP-NEXT:    s_endpgm
2259;
2260; GFX10-CU-LABEL: flat_workgroup_seq_cst_seq_cst_cmpxchg:
2261; GFX10-CU:       ; %bb.0: ; %entry
2262; GFX10-CU-NEXT:    s_clause 0x1
2263; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2264; GFX10-CU-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
2265; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
2266; GFX10-CU-NEXT:    s_add_u32 s0, s0, 16
2267; GFX10-CU-NEXT:    s_addc_u32 s1, s1, 0
2268; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
2269; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
2270; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
2271; GFX10-CU-NEXT:    v_mov_b32_e32 v3, s3
2272; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
2273; GFX10-CU-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
2274; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
2275; GFX10-CU-NEXT:    s_endpgm
2276;
2277; SKIP-CACHE-INV-LABEL: flat_workgroup_seq_cst_seq_cst_cmpxchg:
2278; SKIP-CACHE-INV:       ; %bb.0: ; %entry
2279; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
2280; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
2281; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
2282; SKIP-CACHE-INV-NEXT:    s_add_u32 s2, s2, 16
2283; SKIP-CACHE-INV-NEXT:    s_addc_u32 s3, s3, 0
2284; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
2285; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s1
2286; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
2287; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
2288; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
2289; SKIP-CACHE-INV-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
2290; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
2291; SKIP-CACHE-INV-NEXT:    s_endpgm
2292;
2293; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_seq_cst_seq_cst_cmpxchg:
2294; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
2295; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2296; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
2297; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
2298; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
2299; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
2300; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
2301; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
2302; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
2303; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
2304;
2305; GFX90A-TGSPLIT-LABEL: flat_workgroup_seq_cst_seq_cst_cmpxchg:
2306; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
2307; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2308; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
2309; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
2310; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
2311; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
2312; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
2313; GFX90A-TGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
2314; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
2315; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
2316; GFX90A-TGSPLIT-NEXT:    s_endpgm
2317    i32* %out, i32 %in, i32 %old) {
2318entry:
2319  %gep = getelementptr i32, i32* %out, i32 4
2320  %val = cmpxchg volatile i32* %gep, i32 %old, i32 %in syncscope("workgroup") seq_cst seq_cst
2321  ret void
2322}
2323
2324define amdgpu_kernel void @flat_workgroup_acquire_monotonic_ret_cmpxchg(
2325; GFX7-LABEL: flat_workgroup_acquire_monotonic_ret_cmpxchg:
2326; GFX7:       ; %bb.0: ; %entry
2327; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2328; GFX7-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x2
2329; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
2330; GFX7-NEXT:    s_add_u32 s4, s0, 16
2331; GFX7-NEXT:    s_addc_u32 s5, s1, 0
2332; GFX7-NEXT:    v_mov_b32_e32 v0, s4
2333; GFX7-NEXT:    v_mov_b32_e32 v2, s2
2334; GFX7-NEXT:    v_mov_b32_e32 v1, s5
2335; GFX7-NEXT:    v_mov_b32_e32 v3, s3
2336; GFX7-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
2337; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
2338; GFX7-NEXT:    v_mov_b32_e32 v0, s0
2339; GFX7-NEXT:    v_mov_b32_e32 v1, s1
2340; GFX7-NEXT:    s_waitcnt vmcnt(0)
2341; GFX7-NEXT:    flat_store_dword v[0:1], v2
2342; GFX7-NEXT:    s_endpgm
2343;
2344; GFX10-WGP-LABEL: flat_workgroup_acquire_monotonic_ret_cmpxchg:
2345; GFX10-WGP:       ; %bb.0: ; %entry
2346; GFX10-WGP-NEXT:    s_clause 0x1
2347; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2348; GFX10-WGP-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
2349; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
2350; GFX10-WGP-NEXT:    s_add_u32 s4, s0, 16
2351; GFX10-WGP-NEXT:    s_addc_u32 s5, s1, 0
2352; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s4
2353; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
2354; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s5
2355; GFX10-WGP-NEXT:    v_mov_b32_e32 v3, s3
2356; GFX10-WGP-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
2357; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
2358; GFX10-WGP-NEXT:    buffer_gl0_inv
2359; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
2360; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
2361; GFX10-WGP-NEXT:    flat_store_dword v[0:1], v2
2362; GFX10-WGP-NEXT:    s_endpgm
2363;
2364; GFX10-CU-LABEL: flat_workgroup_acquire_monotonic_ret_cmpxchg:
2365; GFX10-CU:       ; %bb.0: ; %entry
2366; GFX10-CU-NEXT:    s_clause 0x1
2367; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2368; GFX10-CU-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
2369; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
2370; GFX10-CU-NEXT:    s_add_u32 s4, s0, 16
2371; GFX10-CU-NEXT:    s_addc_u32 s5, s1, 0
2372; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s4
2373; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
2374; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s5
2375; GFX10-CU-NEXT:    v_mov_b32_e32 v3, s3
2376; GFX10-CU-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
2377; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
2378; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
2379; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
2380; GFX10-CU-NEXT:    s_waitcnt vmcnt(0)
2381; GFX10-CU-NEXT:    flat_store_dword v[0:1], v2
2382; GFX10-CU-NEXT:    s_endpgm
2383;
2384; SKIP-CACHE-INV-LABEL: flat_workgroup_acquire_monotonic_ret_cmpxchg:
2385; SKIP-CACHE-INV:       ; %bb.0: ; %entry
2386; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
2387; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
2388; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
2389; SKIP-CACHE-INV-NEXT:    s_add_u32 s4, s2, 16
2390; SKIP-CACHE-INV-NEXT:    s_addc_u32 s5, s3, 0
2391; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s4
2392; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s1
2393; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s5
2394; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
2395; SKIP-CACHE-INV-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
2396; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
2397; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
2398; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
2399; SKIP-CACHE-INV-NEXT:    s_waitcnt vmcnt(0)
2400; SKIP-CACHE-INV-NEXT:    flat_store_dword v[0:1], v2
2401; SKIP-CACHE-INV-NEXT:    s_endpgm
2402;
2403; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_acquire_monotonic_ret_cmpxchg:
2404; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
2405; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2406; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
2407; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
2408; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
2409; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
2410; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] offset:16 glc
2411; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
2412; GFX90A-NOTTGSPLIT-NEXT:    flat_store_dword v[0:1], v2
2413; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
2414;
2415; GFX90A-TGSPLIT-LABEL: flat_workgroup_acquire_monotonic_ret_cmpxchg:
2416; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
2417; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2418; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
2419; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
2420; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
2421; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
2422; GFX90A-TGSPLIT-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] offset:16 glc
2423; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
2424; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
2425; GFX90A-TGSPLIT-NEXT:    flat_store_dword v[0:1], v2
2426; GFX90A-TGSPLIT-NEXT:    s_endpgm
2427    i32* %out, i32 %in, i32 %old) {
2428entry:
2429  %gep = getelementptr i32, i32* %out, i32 4
2430  %val = cmpxchg volatile i32* %gep, i32 %old, i32 %in syncscope("workgroup") acquire monotonic
2431  %val0 = extractvalue { i32, i1 } %val, 0
2432  store i32 %val0, i32* %out, align 4
2433  ret void
2434}
2435
2436define amdgpu_kernel void @flat_workgroup_acq_rel_monotonic_ret_cmpxchg(
2437; GFX7-LABEL: flat_workgroup_acq_rel_monotonic_ret_cmpxchg:
2438; GFX7:       ; %bb.0: ; %entry
2439; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2440; GFX7-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x2
2441; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
2442; GFX7-NEXT:    s_add_u32 s4, s0, 16
2443; GFX7-NEXT:    s_addc_u32 s5, s1, 0
2444; GFX7-NEXT:    v_mov_b32_e32 v0, s4
2445; GFX7-NEXT:    v_mov_b32_e32 v2, s2
2446; GFX7-NEXT:    v_mov_b32_e32 v1, s5
2447; GFX7-NEXT:    v_mov_b32_e32 v3, s3
2448; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
2449; GFX7-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
2450; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
2451; GFX7-NEXT:    v_mov_b32_e32 v0, s0
2452; GFX7-NEXT:    v_mov_b32_e32 v1, s1
2453; GFX7-NEXT:    s_waitcnt vmcnt(0)
2454; GFX7-NEXT:    flat_store_dword v[0:1], v2
2455; GFX7-NEXT:    s_endpgm
2456;
2457; GFX10-WGP-LABEL: flat_workgroup_acq_rel_monotonic_ret_cmpxchg:
2458; GFX10-WGP:       ; %bb.0: ; %entry
2459; GFX10-WGP-NEXT:    s_clause 0x1
2460; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2461; GFX10-WGP-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
2462; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
2463; GFX10-WGP-NEXT:    s_add_u32 s4, s0, 16
2464; GFX10-WGP-NEXT:    s_addc_u32 s5, s1, 0
2465; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s4
2466; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
2467; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s5
2468; GFX10-WGP-NEXT:    v_mov_b32_e32 v3, s3
2469; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
2470; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
2471; GFX10-WGP-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
2472; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
2473; GFX10-WGP-NEXT:    buffer_gl0_inv
2474; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
2475; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
2476; GFX10-WGP-NEXT:    flat_store_dword v[0:1], v2
2477; GFX10-WGP-NEXT:    s_endpgm
2478;
2479; GFX10-CU-LABEL: flat_workgroup_acq_rel_monotonic_ret_cmpxchg:
2480; GFX10-CU:       ; %bb.0: ; %entry
2481; GFX10-CU-NEXT:    s_clause 0x1
2482; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2483; GFX10-CU-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
2484; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
2485; GFX10-CU-NEXT:    s_add_u32 s4, s0, 16
2486; GFX10-CU-NEXT:    s_addc_u32 s5, s1, 0
2487; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s4
2488; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
2489; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s5
2490; GFX10-CU-NEXT:    v_mov_b32_e32 v3, s3
2491; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
2492; GFX10-CU-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
2493; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
2494; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
2495; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
2496; GFX10-CU-NEXT:    s_waitcnt vmcnt(0)
2497; GFX10-CU-NEXT:    flat_store_dword v[0:1], v2
2498; GFX10-CU-NEXT:    s_endpgm
2499;
2500; SKIP-CACHE-INV-LABEL: flat_workgroup_acq_rel_monotonic_ret_cmpxchg:
2501; SKIP-CACHE-INV:       ; %bb.0: ; %entry
2502; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
2503; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
2504; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
2505; SKIP-CACHE-INV-NEXT:    s_add_u32 s4, s2, 16
2506; SKIP-CACHE-INV-NEXT:    s_addc_u32 s5, s3, 0
2507; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s4
2508; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s1
2509; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s5
2510; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
2511; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
2512; SKIP-CACHE-INV-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
2513; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
2514; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
2515; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
2516; SKIP-CACHE-INV-NEXT:    s_waitcnt vmcnt(0)
2517; SKIP-CACHE-INV-NEXT:    flat_store_dword v[0:1], v2
2518; SKIP-CACHE-INV-NEXT:    s_endpgm
2519;
2520; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_acq_rel_monotonic_ret_cmpxchg:
2521; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
2522; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2523; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
2524; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
2525; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
2526; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
2527; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
2528; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] offset:16 glc
2529; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
2530; GFX90A-NOTTGSPLIT-NEXT:    flat_store_dword v[0:1], v2
2531; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
2532;
2533; GFX90A-TGSPLIT-LABEL: flat_workgroup_acq_rel_monotonic_ret_cmpxchg:
2534; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
2535; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2536; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
2537; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
2538; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
2539; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
2540; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
2541; GFX90A-TGSPLIT-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] offset:16 glc
2542; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
2543; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
2544; GFX90A-TGSPLIT-NEXT:    flat_store_dword v[0:1], v2
2545; GFX90A-TGSPLIT-NEXT:    s_endpgm
2546    i32* %out, i32 %in, i32 %old) {
2547entry:
2548  %gep = getelementptr i32, i32* %out, i32 4
2549  %val = cmpxchg volatile i32* %gep, i32 %old, i32 %in syncscope("workgroup") acq_rel monotonic
2550  %val0 = extractvalue { i32, i1 } %val, 0
2551  store i32 %val0, i32* %out, align 4
2552  ret void
2553}
2554
2555define amdgpu_kernel void @flat_workgroup_seq_cst_monotonic_ret_cmpxchg(
2556; GFX7-LABEL: flat_workgroup_seq_cst_monotonic_ret_cmpxchg:
2557; GFX7:       ; %bb.0: ; %entry
2558; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2559; GFX7-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x2
2560; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
2561; GFX7-NEXT:    s_add_u32 s4, s0, 16
2562; GFX7-NEXT:    s_addc_u32 s5, s1, 0
2563; GFX7-NEXT:    v_mov_b32_e32 v0, s4
2564; GFX7-NEXT:    v_mov_b32_e32 v2, s2
2565; GFX7-NEXT:    v_mov_b32_e32 v1, s5
2566; GFX7-NEXT:    v_mov_b32_e32 v3, s3
2567; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
2568; GFX7-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
2569; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
2570; GFX7-NEXT:    v_mov_b32_e32 v0, s0
2571; GFX7-NEXT:    v_mov_b32_e32 v1, s1
2572; GFX7-NEXT:    s_waitcnt vmcnt(0)
2573; GFX7-NEXT:    flat_store_dword v[0:1], v2
2574; GFX7-NEXT:    s_endpgm
2575;
2576; GFX10-WGP-LABEL: flat_workgroup_seq_cst_monotonic_ret_cmpxchg:
2577; GFX10-WGP:       ; %bb.0: ; %entry
2578; GFX10-WGP-NEXT:    s_clause 0x1
2579; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2580; GFX10-WGP-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
2581; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
2582; GFX10-WGP-NEXT:    s_add_u32 s4, s0, 16
2583; GFX10-WGP-NEXT:    s_addc_u32 s5, s1, 0
2584; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s4
2585; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
2586; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s5
2587; GFX10-WGP-NEXT:    v_mov_b32_e32 v3, s3
2588; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
2589; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
2590; GFX10-WGP-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
2591; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
2592; GFX10-WGP-NEXT:    buffer_gl0_inv
2593; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
2594; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
2595; GFX10-WGP-NEXT:    flat_store_dword v[0:1], v2
2596; GFX10-WGP-NEXT:    s_endpgm
2597;
2598; GFX10-CU-LABEL: flat_workgroup_seq_cst_monotonic_ret_cmpxchg:
2599; GFX10-CU:       ; %bb.0: ; %entry
2600; GFX10-CU-NEXT:    s_clause 0x1
2601; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2602; GFX10-CU-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
2603; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
2604; GFX10-CU-NEXT:    s_add_u32 s4, s0, 16
2605; GFX10-CU-NEXT:    s_addc_u32 s5, s1, 0
2606; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s4
2607; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
2608; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s5
2609; GFX10-CU-NEXT:    v_mov_b32_e32 v3, s3
2610; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
2611; GFX10-CU-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
2612; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
2613; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
2614; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
2615; GFX10-CU-NEXT:    s_waitcnt vmcnt(0)
2616; GFX10-CU-NEXT:    flat_store_dword v[0:1], v2
2617; GFX10-CU-NEXT:    s_endpgm
2618;
2619; SKIP-CACHE-INV-LABEL: flat_workgroup_seq_cst_monotonic_ret_cmpxchg:
2620; SKIP-CACHE-INV:       ; %bb.0: ; %entry
2621; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
2622; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
2623; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
2624; SKIP-CACHE-INV-NEXT:    s_add_u32 s4, s2, 16
2625; SKIP-CACHE-INV-NEXT:    s_addc_u32 s5, s3, 0
2626; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s4
2627; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s1
2628; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s5
2629; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
2630; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
2631; SKIP-CACHE-INV-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
2632; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
2633; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
2634; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
2635; SKIP-CACHE-INV-NEXT:    s_waitcnt vmcnt(0)
2636; SKIP-CACHE-INV-NEXT:    flat_store_dword v[0:1], v2
2637; SKIP-CACHE-INV-NEXT:    s_endpgm
2638;
2639; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_seq_cst_monotonic_ret_cmpxchg:
2640; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
2641; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2642; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
2643; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
2644; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
2645; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
2646; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
2647; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] offset:16 glc
2648; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
2649; GFX90A-NOTTGSPLIT-NEXT:    flat_store_dword v[0:1], v2
2650; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
2651;
2652; GFX90A-TGSPLIT-LABEL: flat_workgroup_seq_cst_monotonic_ret_cmpxchg:
2653; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
2654; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2655; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
2656; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
2657; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
2658; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
2659; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
2660; GFX90A-TGSPLIT-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] offset:16 glc
2661; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
2662; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
2663; GFX90A-TGSPLIT-NEXT:    flat_store_dword v[0:1], v2
2664; GFX90A-TGSPLIT-NEXT:    s_endpgm
2665    i32* %out, i32 %in, i32 %old) {
2666entry:
2667  %gep = getelementptr i32, i32* %out, i32 4
2668  %val = cmpxchg volatile i32* %gep, i32 %old, i32 %in syncscope("workgroup") seq_cst monotonic
2669  %val0 = extractvalue { i32, i1 } %val, 0
2670  store i32 %val0, i32* %out, align 4
2671  ret void
2672}
2673
2674define amdgpu_kernel void @flat_workgroup_acquire_acquire_ret_cmpxchg(
2675; GFX7-LABEL: flat_workgroup_acquire_acquire_ret_cmpxchg:
2676; GFX7:       ; %bb.0: ; %entry
2677; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2678; GFX7-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x2
2679; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
2680; GFX7-NEXT:    s_add_u32 s4, s0, 16
2681; GFX7-NEXT:    s_addc_u32 s5, s1, 0
2682; GFX7-NEXT:    v_mov_b32_e32 v0, s4
2683; GFX7-NEXT:    v_mov_b32_e32 v2, s2
2684; GFX7-NEXT:    v_mov_b32_e32 v1, s5
2685; GFX7-NEXT:    v_mov_b32_e32 v3, s3
2686; GFX7-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
2687; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
2688; GFX7-NEXT:    v_mov_b32_e32 v0, s0
2689; GFX7-NEXT:    v_mov_b32_e32 v1, s1
2690; GFX7-NEXT:    s_waitcnt vmcnt(0)
2691; GFX7-NEXT:    flat_store_dword v[0:1], v2
2692; GFX7-NEXT:    s_endpgm
2693;
2694; GFX10-WGP-LABEL: flat_workgroup_acquire_acquire_ret_cmpxchg:
2695; GFX10-WGP:       ; %bb.0: ; %entry
2696; GFX10-WGP-NEXT:    s_clause 0x1
2697; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2698; GFX10-WGP-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
2699; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
2700; GFX10-WGP-NEXT:    s_add_u32 s4, s0, 16
2701; GFX10-WGP-NEXT:    s_addc_u32 s5, s1, 0
2702; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s4
2703; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
2704; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s5
2705; GFX10-WGP-NEXT:    v_mov_b32_e32 v3, s3
2706; GFX10-WGP-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
2707; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
2708; GFX10-WGP-NEXT:    buffer_gl0_inv
2709; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
2710; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
2711; GFX10-WGP-NEXT:    flat_store_dword v[0:1], v2
2712; GFX10-WGP-NEXT:    s_endpgm
2713;
2714; GFX10-CU-LABEL: flat_workgroup_acquire_acquire_ret_cmpxchg:
2715; GFX10-CU:       ; %bb.0: ; %entry
2716; GFX10-CU-NEXT:    s_clause 0x1
2717; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2718; GFX10-CU-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
2719; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
2720; GFX10-CU-NEXT:    s_add_u32 s4, s0, 16
2721; GFX10-CU-NEXT:    s_addc_u32 s5, s1, 0
2722; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s4
2723; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
2724; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s5
2725; GFX10-CU-NEXT:    v_mov_b32_e32 v3, s3
2726; GFX10-CU-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
2727; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
2728; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
2729; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
2730; GFX10-CU-NEXT:    s_waitcnt vmcnt(0)
2731; GFX10-CU-NEXT:    flat_store_dword v[0:1], v2
2732; GFX10-CU-NEXT:    s_endpgm
2733;
2734; SKIP-CACHE-INV-LABEL: flat_workgroup_acquire_acquire_ret_cmpxchg:
2735; SKIP-CACHE-INV:       ; %bb.0: ; %entry
2736; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
2737; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
2738; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
2739; SKIP-CACHE-INV-NEXT:    s_add_u32 s4, s2, 16
2740; SKIP-CACHE-INV-NEXT:    s_addc_u32 s5, s3, 0
2741; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s4
2742; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s1
2743; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s5
2744; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
2745; SKIP-CACHE-INV-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
2746; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
2747; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
2748; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
2749; SKIP-CACHE-INV-NEXT:    s_waitcnt vmcnt(0)
2750; SKIP-CACHE-INV-NEXT:    flat_store_dword v[0:1], v2
2751; SKIP-CACHE-INV-NEXT:    s_endpgm
2752;
2753; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_acquire_acquire_ret_cmpxchg:
2754; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
2755; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2756; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
2757; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
2758; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
2759; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
2760; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] offset:16 glc
2761; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
2762; GFX90A-NOTTGSPLIT-NEXT:    flat_store_dword v[0:1], v2
2763; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
2764;
2765; GFX90A-TGSPLIT-LABEL: flat_workgroup_acquire_acquire_ret_cmpxchg:
2766; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
2767; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2768; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
2769; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
2770; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
2771; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
2772; GFX90A-TGSPLIT-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] offset:16 glc
2773; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
2774; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
2775; GFX90A-TGSPLIT-NEXT:    flat_store_dword v[0:1], v2
2776; GFX90A-TGSPLIT-NEXT:    s_endpgm
2777    i32* %out, i32 %in, i32 %old) {
2778entry:
2779  %gep = getelementptr i32, i32* %out, i32 4
2780  %val = cmpxchg volatile i32* %gep, i32 %old, i32 %in syncscope("workgroup") acquire acquire
2781  %val0 = extractvalue { i32, i1 } %val, 0
2782  store i32 %val0, i32* %out, align 4
2783  ret void
2784}
2785
2786define amdgpu_kernel void @flat_workgroup_release_acquire_ret_cmpxchg(
2787; GFX7-LABEL: flat_workgroup_release_acquire_ret_cmpxchg:
2788; GFX7:       ; %bb.0: ; %entry
2789; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2790; GFX7-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x2
2791; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
2792; GFX7-NEXT:    s_add_u32 s4, s0, 16
2793; GFX7-NEXT:    s_addc_u32 s5, s1, 0
2794; GFX7-NEXT:    v_mov_b32_e32 v0, s4
2795; GFX7-NEXT:    v_mov_b32_e32 v2, s2
2796; GFX7-NEXT:    v_mov_b32_e32 v1, s5
2797; GFX7-NEXT:    v_mov_b32_e32 v3, s3
2798; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
2799; GFX7-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
2800; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
2801; GFX7-NEXT:    v_mov_b32_e32 v0, s0
2802; GFX7-NEXT:    v_mov_b32_e32 v1, s1
2803; GFX7-NEXT:    s_waitcnt vmcnt(0)
2804; GFX7-NEXT:    flat_store_dword v[0:1], v2
2805; GFX7-NEXT:    s_endpgm
2806;
2807; GFX10-WGP-LABEL: flat_workgroup_release_acquire_ret_cmpxchg:
2808; GFX10-WGP:       ; %bb.0: ; %entry
2809; GFX10-WGP-NEXT:    s_clause 0x1
2810; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2811; GFX10-WGP-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
2812; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
2813; GFX10-WGP-NEXT:    s_add_u32 s4, s0, 16
2814; GFX10-WGP-NEXT:    s_addc_u32 s5, s1, 0
2815; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s4
2816; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
2817; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s5
2818; GFX10-WGP-NEXT:    v_mov_b32_e32 v3, s3
2819; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
2820; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
2821; GFX10-WGP-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
2822; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
2823; GFX10-WGP-NEXT:    buffer_gl0_inv
2824; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
2825; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
2826; GFX10-WGP-NEXT:    flat_store_dword v[0:1], v2
2827; GFX10-WGP-NEXT:    s_endpgm
2828;
2829; GFX10-CU-LABEL: flat_workgroup_release_acquire_ret_cmpxchg:
2830; GFX10-CU:       ; %bb.0: ; %entry
2831; GFX10-CU-NEXT:    s_clause 0x1
2832; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2833; GFX10-CU-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
2834; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
2835; GFX10-CU-NEXT:    s_add_u32 s4, s0, 16
2836; GFX10-CU-NEXT:    s_addc_u32 s5, s1, 0
2837; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s4
2838; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
2839; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s5
2840; GFX10-CU-NEXT:    v_mov_b32_e32 v3, s3
2841; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
2842; GFX10-CU-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
2843; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
2844; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
2845; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
2846; GFX10-CU-NEXT:    s_waitcnt vmcnt(0)
2847; GFX10-CU-NEXT:    flat_store_dword v[0:1], v2
2848; GFX10-CU-NEXT:    s_endpgm
2849;
2850; SKIP-CACHE-INV-LABEL: flat_workgroup_release_acquire_ret_cmpxchg:
2851; SKIP-CACHE-INV:       ; %bb.0: ; %entry
2852; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
2853; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
2854; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
2855; SKIP-CACHE-INV-NEXT:    s_add_u32 s4, s2, 16
2856; SKIP-CACHE-INV-NEXT:    s_addc_u32 s5, s3, 0
2857; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s4
2858; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s1
2859; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s5
2860; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
2861; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
2862; SKIP-CACHE-INV-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
2863; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
2864; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
2865; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
2866; SKIP-CACHE-INV-NEXT:    s_waitcnt vmcnt(0)
2867; SKIP-CACHE-INV-NEXT:    flat_store_dword v[0:1], v2
2868; SKIP-CACHE-INV-NEXT:    s_endpgm
2869;
2870; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_release_acquire_ret_cmpxchg:
2871; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
2872; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2873; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
2874; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
2875; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
2876; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
2877; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
2878; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] offset:16 glc
2879; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
2880; GFX90A-NOTTGSPLIT-NEXT:    flat_store_dword v[0:1], v2
2881; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
2882;
2883; GFX90A-TGSPLIT-LABEL: flat_workgroup_release_acquire_ret_cmpxchg:
2884; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
2885; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2886; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
2887; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
2888; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
2889; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
2890; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
2891; GFX90A-TGSPLIT-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] offset:16 glc
2892; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
2893; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
2894; GFX90A-TGSPLIT-NEXT:    flat_store_dword v[0:1], v2
2895; GFX90A-TGSPLIT-NEXT:    s_endpgm
2896    i32* %out, i32 %in, i32 %old) {
2897entry:
2898  %gep = getelementptr i32, i32* %out, i32 4
2899  %val = cmpxchg volatile i32* %gep, i32 %old, i32 %in syncscope("workgroup") release acquire
2900  %val0 = extractvalue { i32, i1 } %val, 0
2901  store i32 %val0, i32* %out, align 4
2902  ret void
2903}
2904
2905define amdgpu_kernel void @flat_workgroup_acq_rel_acquire_ret_cmpxchg(
2906; GFX7-LABEL: flat_workgroup_acq_rel_acquire_ret_cmpxchg:
2907; GFX7:       ; %bb.0: ; %entry
2908; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2909; GFX7-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x2
2910; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
2911; GFX7-NEXT:    s_add_u32 s4, s0, 16
2912; GFX7-NEXT:    s_addc_u32 s5, s1, 0
2913; GFX7-NEXT:    v_mov_b32_e32 v0, s4
2914; GFX7-NEXT:    v_mov_b32_e32 v2, s2
2915; GFX7-NEXT:    v_mov_b32_e32 v1, s5
2916; GFX7-NEXT:    v_mov_b32_e32 v3, s3
2917; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
2918; GFX7-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
2919; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
2920; GFX7-NEXT:    v_mov_b32_e32 v0, s0
2921; GFX7-NEXT:    v_mov_b32_e32 v1, s1
2922; GFX7-NEXT:    s_waitcnt vmcnt(0)
2923; GFX7-NEXT:    flat_store_dword v[0:1], v2
2924; GFX7-NEXT:    s_endpgm
2925;
2926; GFX10-WGP-LABEL: flat_workgroup_acq_rel_acquire_ret_cmpxchg:
2927; GFX10-WGP:       ; %bb.0: ; %entry
2928; GFX10-WGP-NEXT:    s_clause 0x1
2929; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2930; GFX10-WGP-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
2931; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
2932; GFX10-WGP-NEXT:    s_add_u32 s4, s0, 16
2933; GFX10-WGP-NEXT:    s_addc_u32 s5, s1, 0
2934; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s4
2935; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
2936; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s5
2937; GFX10-WGP-NEXT:    v_mov_b32_e32 v3, s3
2938; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
2939; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
2940; GFX10-WGP-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
2941; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
2942; GFX10-WGP-NEXT:    buffer_gl0_inv
2943; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
2944; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
2945; GFX10-WGP-NEXT:    flat_store_dword v[0:1], v2
2946; GFX10-WGP-NEXT:    s_endpgm
2947;
2948; GFX10-CU-LABEL: flat_workgroup_acq_rel_acquire_ret_cmpxchg:
2949; GFX10-CU:       ; %bb.0: ; %entry
2950; GFX10-CU-NEXT:    s_clause 0x1
2951; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2952; GFX10-CU-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
2953; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
2954; GFX10-CU-NEXT:    s_add_u32 s4, s0, 16
2955; GFX10-CU-NEXT:    s_addc_u32 s5, s1, 0
2956; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s4
2957; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
2958; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s5
2959; GFX10-CU-NEXT:    v_mov_b32_e32 v3, s3
2960; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
2961; GFX10-CU-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
2962; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
2963; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
2964; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
2965; GFX10-CU-NEXT:    s_waitcnt vmcnt(0)
2966; GFX10-CU-NEXT:    flat_store_dword v[0:1], v2
2967; GFX10-CU-NEXT:    s_endpgm
2968;
2969; SKIP-CACHE-INV-LABEL: flat_workgroup_acq_rel_acquire_ret_cmpxchg:
2970; SKIP-CACHE-INV:       ; %bb.0: ; %entry
2971; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
2972; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
2973; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
2974; SKIP-CACHE-INV-NEXT:    s_add_u32 s4, s2, 16
2975; SKIP-CACHE-INV-NEXT:    s_addc_u32 s5, s3, 0
2976; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s4
2977; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s1
2978; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s5
2979; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
2980; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
2981; SKIP-CACHE-INV-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
2982; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
2983; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
2984; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
2985; SKIP-CACHE-INV-NEXT:    s_waitcnt vmcnt(0)
2986; SKIP-CACHE-INV-NEXT:    flat_store_dword v[0:1], v2
2987; SKIP-CACHE-INV-NEXT:    s_endpgm
2988;
2989; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_acq_rel_acquire_ret_cmpxchg:
2990; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
2991; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
2992; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
2993; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
2994; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
2995; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
2996; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
2997; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] offset:16 glc
2998; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
2999; GFX90A-NOTTGSPLIT-NEXT:    flat_store_dword v[0:1], v2
3000; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
3001;
3002; GFX90A-TGSPLIT-LABEL: flat_workgroup_acq_rel_acquire_ret_cmpxchg:
3003; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
3004; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
3005; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
3006; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
3007; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
3008; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
3009; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
3010; GFX90A-TGSPLIT-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] offset:16 glc
3011; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
3012; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
3013; GFX90A-TGSPLIT-NEXT:    flat_store_dword v[0:1], v2
3014; GFX90A-TGSPLIT-NEXT:    s_endpgm
3015    i32* %out, i32 %in, i32 %old) {
3016entry:
3017  %gep = getelementptr i32, i32* %out, i32 4
3018  %val = cmpxchg volatile i32* %gep, i32 %old, i32 %in syncscope("workgroup") acq_rel acquire
3019  %val0 = extractvalue { i32, i1 } %val, 0
3020  store i32 %val0, i32* %out, align 4
3021  ret void
3022}
3023
3024define amdgpu_kernel void @flat_workgroup_seq_cst_acquire_ret_cmpxchg(
3025; GFX7-LABEL: flat_workgroup_seq_cst_acquire_ret_cmpxchg:
3026; GFX7:       ; %bb.0: ; %entry
3027; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
3028; GFX7-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x2
3029; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
3030; GFX7-NEXT:    s_add_u32 s4, s0, 16
3031; GFX7-NEXT:    s_addc_u32 s5, s1, 0
3032; GFX7-NEXT:    v_mov_b32_e32 v0, s4
3033; GFX7-NEXT:    v_mov_b32_e32 v2, s2
3034; GFX7-NEXT:    v_mov_b32_e32 v1, s5
3035; GFX7-NEXT:    v_mov_b32_e32 v3, s3
3036; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
3037; GFX7-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
3038; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
3039; GFX7-NEXT:    v_mov_b32_e32 v0, s0
3040; GFX7-NEXT:    v_mov_b32_e32 v1, s1
3041; GFX7-NEXT:    s_waitcnt vmcnt(0)
3042; GFX7-NEXT:    flat_store_dword v[0:1], v2
3043; GFX7-NEXT:    s_endpgm
3044;
3045; GFX10-WGP-LABEL: flat_workgroup_seq_cst_acquire_ret_cmpxchg:
3046; GFX10-WGP:       ; %bb.0: ; %entry
3047; GFX10-WGP-NEXT:    s_clause 0x1
3048; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
3049; GFX10-WGP-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
3050; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
3051; GFX10-WGP-NEXT:    s_add_u32 s4, s0, 16
3052; GFX10-WGP-NEXT:    s_addc_u32 s5, s1, 0
3053; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s4
3054; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
3055; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s5
3056; GFX10-WGP-NEXT:    v_mov_b32_e32 v3, s3
3057; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
3058; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
3059; GFX10-WGP-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
3060; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
3061; GFX10-WGP-NEXT:    buffer_gl0_inv
3062; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
3063; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
3064; GFX10-WGP-NEXT:    flat_store_dword v[0:1], v2
3065; GFX10-WGP-NEXT:    s_endpgm
3066;
3067; GFX10-CU-LABEL: flat_workgroup_seq_cst_acquire_ret_cmpxchg:
3068; GFX10-CU:       ; %bb.0: ; %entry
3069; GFX10-CU-NEXT:    s_clause 0x1
3070; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
3071; GFX10-CU-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
3072; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
3073; GFX10-CU-NEXT:    s_add_u32 s4, s0, 16
3074; GFX10-CU-NEXT:    s_addc_u32 s5, s1, 0
3075; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s4
3076; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
3077; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s5
3078; GFX10-CU-NEXT:    v_mov_b32_e32 v3, s3
3079; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
3080; GFX10-CU-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
3081; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
3082; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
3083; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
3084; GFX10-CU-NEXT:    s_waitcnt vmcnt(0)
3085; GFX10-CU-NEXT:    flat_store_dword v[0:1], v2
3086; GFX10-CU-NEXT:    s_endpgm
3087;
3088; SKIP-CACHE-INV-LABEL: flat_workgroup_seq_cst_acquire_ret_cmpxchg:
3089; SKIP-CACHE-INV:       ; %bb.0: ; %entry
3090; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
3091; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
3092; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
3093; SKIP-CACHE-INV-NEXT:    s_add_u32 s4, s2, 16
3094; SKIP-CACHE-INV-NEXT:    s_addc_u32 s5, s3, 0
3095; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s4
3096; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s1
3097; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s5
3098; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
3099; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
3100; SKIP-CACHE-INV-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
3101; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
3102; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
3103; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
3104; SKIP-CACHE-INV-NEXT:    s_waitcnt vmcnt(0)
3105; SKIP-CACHE-INV-NEXT:    flat_store_dword v[0:1], v2
3106; SKIP-CACHE-INV-NEXT:    s_endpgm
3107;
3108; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_seq_cst_acquire_ret_cmpxchg:
3109; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
3110; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
3111; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
3112; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
3113; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
3114; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
3115; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
3116; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] offset:16 glc
3117; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
3118; GFX90A-NOTTGSPLIT-NEXT:    flat_store_dword v[0:1], v2
3119; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
3120;
3121; GFX90A-TGSPLIT-LABEL: flat_workgroup_seq_cst_acquire_ret_cmpxchg:
3122; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
3123; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
3124; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
3125; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
3126; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
3127; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
3128; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
3129; GFX90A-TGSPLIT-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] offset:16 glc
3130; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
3131; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
3132; GFX90A-TGSPLIT-NEXT:    flat_store_dword v[0:1], v2
3133; GFX90A-TGSPLIT-NEXT:    s_endpgm
3134    i32* %out, i32 %in, i32 %old) {
3135entry:
3136  %gep = getelementptr i32, i32* %out, i32 4
3137  %val = cmpxchg volatile i32* %gep, i32 %old, i32 %in syncscope("workgroup") seq_cst acquire
3138  %val0 = extractvalue { i32, i1 } %val, 0
3139  store i32 %val0, i32* %out, align 4
3140  ret void
3141}
3142
3143define amdgpu_kernel void @flat_workgroup_seq_cst_seq_cst_ret_cmpxchg(
3144; GFX7-LABEL: flat_workgroup_seq_cst_seq_cst_ret_cmpxchg:
3145; GFX7:       ; %bb.0: ; %entry
3146; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
3147; GFX7-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x2
3148; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
3149; GFX7-NEXT:    s_add_u32 s4, s0, 16
3150; GFX7-NEXT:    s_addc_u32 s5, s1, 0
3151; GFX7-NEXT:    v_mov_b32_e32 v0, s4
3152; GFX7-NEXT:    v_mov_b32_e32 v2, s2
3153; GFX7-NEXT:    v_mov_b32_e32 v1, s5
3154; GFX7-NEXT:    v_mov_b32_e32 v3, s3
3155; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
3156; GFX7-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
3157; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
3158; GFX7-NEXT:    v_mov_b32_e32 v0, s0
3159; GFX7-NEXT:    v_mov_b32_e32 v1, s1
3160; GFX7-NEXT:    s_waitcnt vmcnt(0)
3161; GFX7-NEXT:    flat_store_dword v[0:1], v2
3162; GFX7-NEXT:    s_endpgm
3163;
3164; GFX10-WGP-LABEL: flat_workgroup_seq_cst_seq_cst_ret_cmpxchg:
3165; GFX10-WGP:       ; %bb.0: ; %entry
3166; GFX10-WGP-NEXT:    s_clause 0x1
3167; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
3168; GFX10-WGP-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
3169; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
3170; GFX10-WGP-NEXT:    s_add_u32 s4, s0, 16
3171; GFX10-WGP-NEXT:    s_addc_u32 s5, s1, 0
3172; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s4
3173; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
3174; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s5
3175; GFX10-WGP-NEXT:    v_mov_b32_e32 v3, s3
3176; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
3177; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
3178; GFX10-WGP-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
3179; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
3180; GFX10-WGP-NEXT:    buffer_gl0_inv
3181; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
3182; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
3183; GFX10-WGP-NEXT:    flat_store_dword v[0:1], v2
3184; GFX10-WGP-NEXT:    s_endpgm
3185;
3186; GFX10-CU-LABEL: flat_workgroup_seq_cst_seq_cst_ret_cmpxchg:
3187; GFX10-CU:       ; %bb.0: ; %entry
3188; GFX10-CU-NEXT:    s_clause 0x1
3189; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
3190; GFX10-CU-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
3191; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
3192; GFX10-CU-NEXT:    s_add_u32 s4, s0, 16
3193; GFX10-CU-NEXT:    s_addc_u32 s5, s1, 0
3194; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s4
3195; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
3196; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s5
3197; GFX10-CU-NEXT:    v_mov_b32_e32 v3, s3
3198; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
3199; GFX10-CU-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
3200; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
3201; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
3202; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
3203; GFX10-CU-NEXT:    s_waitcnt vmcnt(0)
3204; GFX10-CU-NEXT:    flat_store_dword v[0:1], v2
3205; GFX10-CU-NEXT:    s_endpgm
3206;
3207; SKIP-CACHE-INV-LABEL: flat_workgroup_seq_cst_seq_cst_ret_cmpxchg:
3208; SKIP-CACHE-INV:       ; %bb.0: ; %entry
3209; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
3210; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
3211; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
3212; SKIP-CACHE-INV-NEXT:    s_add_u32 s4, s2, 16
3213; SKIP-CACHE-INV-NEXT:    s_addc_u32 s5, s3, 0
3214; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s4
3215; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s1
3216; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s5
3217; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
3218; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
3219; SKIP-CACHE-INV-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
3220; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
3221; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
3222; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
3223; SKIP-CACHE-INV-NEXT:    s_waitcnt vmcnt(0)
3224; SKIP-CACHE-INV-NEXT:    flat_store_dword v[0:1], v2
3225; SKIP-CACHE-INV-NEXT:    s_endpgm
3226;
3227; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_seq_cst_seq_cst_ret_cmpxchg:
3228; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
3229; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
3230; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
3231; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
3232; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
3233; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
3234; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
3235; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] offset:16 glc
3236; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
3237; GFX90A-NOTTGSPLIT-NEXT:    flat_store_dword v[0:1], v2
3238; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
3239;
3240; GFX90A-TGSPLIT-LABEL: flat_workgroup_seq_cst_seq_cst_ret_cmpxchg:
3241; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
3242; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
3243; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
3244; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
3245; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
3246; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
3247; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
3248; GFX90A-TGSPLIT-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] offset:16 glc
3249; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
3250; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
3251; GFX90A-TGSPLIT-NEXT:    flat_store_dword v[0:1], v2
3252; GFX90A-TGSPLIT-NEXT:    s_endpgm
3253    i32* %out, i32 %in, i32 %old) {
3254entry:
3255  %gep = getelementptr i32, i32* %out, i32 4
3256  %val = cmpxchg volatile i32* %gep, i32 %old, i32 %in syncscope("workgroup") seq_cst seq_cst
3257  %val0 = extractvalue { i32, i1 } %val, 0
3258  store i32 %val0, i32* %out, align 4
3259  ret void
3260}
3261
3262define amdgpu_kernel void @flat_workgroup_one_as_unordered_load(
3263; GFX7-LABEL: flat_workgroup_one_as_unordered_load:
3264; GFX7:       ; %bb.0: ; %entry
3265; GFX7-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
3266; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
3267; GFX7-NEXT:    v_mov_b32_e32 v0, s0
3268; GFX7-NEXT:    v_mov_b32_e32 v1, s1
3269; GFX7-NEXT:    flat_load_dword v0, v[0:1]
3270; GFX7-NEXT:    v_mov_b32_e32 v2, s2
3271; GFX7-NEXT:    v_mov_b32_e32 v3, s3
3272; GFX7-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
3273; GFX7-NEXT:    flat_store_dword v[2:3], v0
3274; GFX7-NEXT:    s_endpgm
3275;
3276; GFX10-WGP-LABEL: flat_workgroup_one_as_unordered_load:
3277; GFX10-WGP:       ; %bb.0: ; %entry
3278; GFX10-WGP-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
3279; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
3280; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
3281; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
3282; GFX10-WGP-NEXT:    flat_load_dword v2, v[0:1]
3283; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s2
3284; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s3
3285; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
3286; GFX10-WGP-NEXT:    flat_store_dword v[0:1], v2
3287; GFX10-WGP-NEXT:    s_endpgm
3288;
3289; GFX10-CU-LABEL: flat_workgroup_one_as_unordered_load:
3290; GFX10-CU:       ; %bb.0: ; %entry
3291; GFX10-CU-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
3292; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
3293; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
3294; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
3295; GFX10-CU-NEXT:    flat_load_dword v2, v[0:1]
3296; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s2
3297; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s3
3298; GFX10-CU-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
3299; GFX10-CU-NEXT:    flat_store_dword v[0:1], v2
3300; GFX10-CU-NEXT:    s_endpgm
3301;
3302; SKIP-CACHE-INV-LABEL: flat_workgroup_one_as_unordered_load:
3303; SKIP-CACHE-INV:       ; %bb.0: ; %entry
3304; SKIP-CACHE-INV-NEXT:    s_load_dwordx4 s[0:3], s[0:1], 0x9
3305; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
3306; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s0
3307; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s1
3308; SKIP-CACHE-INV-NEXT:    flat_load_dword v0, v[0:1]
3309; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s2
3310; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s3
3311; SKIP-CACHE-INV-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
3312; SKIP-CACHE-INV-NEXT:    flat_store_dword v[2:3], v0
3313; SKIP-CACHE-INV-NEXT:    s_endpgm
3314;
3315; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_one_as_unordered_load:
3316; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
3317; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
3318; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
3319; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v0, s0
3320; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v1, s1
3321; GFX90A-NOTTGSPLIT-NEXT:    flat_load_dword v0, v[0:1]
3322; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
3323; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v3, s3
3324; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
3325; GFX90A-NOTTGSPLIT-NEXT:    flat_store_dword v[2:3], v0
3326; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
3327;
3328; GFX90A-TGSPLIT-LABEL: flat_workgroup_one_as_unordered_load:
3329; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
3330; GFX90A-TGSPLIT-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
3331; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
3332; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v0, s0
3333; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v1, s1
3334; GFX90A-TGSPLIT-NEXT:    flat_load_dword v0, v[0:1]
3335; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
3336; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v3, s3
3337; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
3338; GFX90A-TGSPLIT-NEXT:    flat_store_dword v[2:3], v0
3339; GFX90A-TGSPLIT-NEXT:    s_endpgm
3340    i32* %in, i32* %out) {
3341entry:
3342  %val = load atomic i32, i32* %in syncscope("workgroup-one-as") unordered, align 4
3343  store i32 %val, i32* %out
3344  ret void
3345}
3346
3347define amdgpu_kernel void @flat_workgroup_one_as_monotonic_load(
3348; GFX7-LABEL: flat_workgroup_one_as_monotonic_load:
3349; GFX7:       ; %bb.0: ; %entry
3350; GFX7-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
3351; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
3352; GFX7-NEXT:    v_mov_b32_e32 v0, s0
3353; GFX7-NEXT:    v_mov_b32_e32 v1, s1
3354; GFX7-NEXT:    flat_load_dword v0, v[0:1]
3355; GFX7-NEXT:    v_mov_b32_e32 v2, s2
3356; GFX7-NEXT:    v_mov_b32_e32 v3, s3
3357; GFX7-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
3358; GFX7-NEXT:    flat_store_dword v[2:3], v0
3359; GFX7-NEXT:    s_endpgm
3360;
3361; GFX10-WGP-LABEL: flat_workgroup_one_as_monotonic_load:
3362; GFX10-WGP:       ; %bb.0: ; %entry
3363; GFX10-WGP-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
3364; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
3365; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
3366; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
3367; GFX10-WGP-NEXT:    flat_load_dword v2, v[0:1] glc
3368; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s2
3369; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s3
3370; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
3371; GFX10-WGP-NEXT:    flat_store_dword v[0:1], v2
3372; GFX10-WGP-NEXT:    s_endpgm
3373;
3374; GFX10-CU-LABEL: flat_workgroup_one_as_monotonic_load:
3375; GFX10-CU:       ; %bb.0: ; %entry
3376; GFX10-CU-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
3377; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
3378; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
3379; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
3380; GFX10-CU-NEXT:    flat_load_dword v2, v[0:1]
3381; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s2
3382; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s3
3383; GFX10-CU-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
3384; GFX10-CU-NEXT:    flat_store_dword v[0:1], v2
3385; GFX10-CU-NEXT:    s_endpgm
3386;
3387; SKIP-CACHE-INV-LABEL: flat_workgroup_one_as_monotonic_load:
3388; SKIP-CACHE-INV:       ; %bb.0: ; %entry
3389; SKIP-CACHE-INV-NEXT:    s_load_dwordx4 s[0:3], s[0:1], 0x9
3390; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
3391; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s0
3392; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s1
3393; SKIP-CACHE-INV-NEXT:    flat_load_dword v0, v[0:1]
3394; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s2
3395; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s3
3396; SKIP-CACHE-INV-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
3397; SKIP-CACHE-INV-NEXT:    flat_store_dword v[2:3], v0
3398; SKIP-CACHE-INV-NEXT:    s_endpgm
3399;
3400; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_one_as_monotonic_load:
3401; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
3402; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
3403; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
3404; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v0, s0
3405; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v1, s1
3406; GFX90A-NOTTGSPLIT-NEXT:    flat_load_dword v0, v[0:1]
3407; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
3408; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v3, s3
3409; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
3410; GFX90A-NOTTGSPLIT-NEXT:    flat_store_dword v[2:3], v0
3411; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
3412;
3413; GFX90A-TGSPLIT-LABEL: flat_workgroup_one_as_monotonic_load:
3414; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
3415; GFX90A-TGSPLIT-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
3416; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
3417; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v0, s0
3418; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v1, s1
3419; GFX90A-TGSPLIT-NEXT:    flat_load_dword v0, v[0:1] glc
3420; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
3421; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v3, s3
3422; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
3423; GFX90A-TGSPLIT-NEXT:    flat_store_dword v[2:3], v0
3424; GFX90A-TGSPLIT-NEXT:    s_endpgm
3425    i32* %in, i32* %out) {
3426entry:
3427  %val = load atomic i32, i32* %in syncscope("workgroup-one-as") monotonic, align 4
3428  store i32 %val, i32* %out
3429  ret void
3430}
3431
3432define amdgpu_kernel void @flat_workgroup_one_as_acquire_load(
3433; GFX7-LABEL: flat_workgroup_one_as_acquire_load:
3434; GFX7:       ; %bb.0: ; %entry
3435; GFX7-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
3436; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
3437; GFX7-NEXT:    v_mov_b32_e32 v0, s0
3438; GFX7-NEXT:    v_mov_b32_e32 v1, s1
3439; GFX7-NEXT:    flat_load_dword v0, v[0:1]
3440; GFX7-NEXT:    v_mov_b32_e32 v2, s2
3441; GFX7-NEXT:    v_mov_b32_e32 v3, s3
3442; GFX7-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
3443; GFX7-NEXT:    flat_store_dword v[2:3], v0
3444; GFX7-NEXT:    s_endpgm
3445;
3446; GFX10-WGP-LABEL: flat_workgroup_one_as_acquire_load:
3447; GFX10-WGP:       ; %bb.0: ; %entry
3448; GFX10-WGP-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
3449; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
3450; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
3451; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
3452; GFX10-WGP-NEXT:    flat_load_dword v2, v[0:1] glc
3453; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0)
3454; GFX10-WGP-NEXT:    buffer_gl0_inv
3455; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s2
3456; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s3
3457; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
3458; GFX10-WGP-NEXT:    flat_store_dword v[0:1], v2
3459; GFX10-WGP-NEXT:    s_endpgm
3460;
3461; GFX10-CU-LABEL: flat_workgroup_one_as_acquire_load:
3462; GFX10-CU:       ; %bb.0: ; %entry
3463; GFX10-CU-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
3464; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
3465; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
3466; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
3467; GFX10-CU-NEXT:    flat_load_dword v2, v[0:1]
3468; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s2
3469; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s3
3470; GFX10-CU-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
3471; GFX10-CU-NEXT:    flat_store_dword v[0:1], v2
3472; GFX10-CU-NEXT:    s_endpgm
3473;
3474; SKIP-CACHE-INV-LABEL: flat_workgroup_one_as_acquire_load:
3475; SKIP-CACHE-INV:       ; %bb.0: ; %entry
3476; SKIP-CACHE-INV-NEXT:    s_load_dwordx4 s[0:3], s[0:1], 0x9
3477; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
3478; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s0
3479; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s1
3480; SKIP-CACHE-INV-NEXT:    flat_load_dword v0, v[0:1]
3481; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s2
3482; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s3
3483; SKIP-CACHE-INV-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
3484; SKIP-CACHE-INV-NEXT:    flat_store_dword v[2:3], v0
3485; SKIP-CACHE-INV-NEXT:    s_endpgm
3486;
3487; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_one_as_acquire_load:
3488; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
3489; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
3490; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
3491; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v0, s0
3492; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v1, s1
3493; GFX90A-NOTTGSPLIT-NEXT:    flat_load_dword v0, v[0:1]
3494; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
3495; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v3, s3
3496; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
3497; GFX90A-NOTTGSPLIT-NEXT:    flat_store_dword v[2:3], v0
3498; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
3499;
3500; GFX90A-TGSPLIT-LABEL: flat_workgroup_one_as_acquire_load:
3501; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
3502; GFX90A-TGSPLIT-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
3503; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
3504; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v0, s0
3505; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v1, s1
3506; GFX90A-TGSPLIT-NEXT:    flat_load_dword v0, v[0:1] glc
3507; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
3508; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
3509; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
3510; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v3, s3
3511; GFX90A-TGSPLIT-NEXT:    flat_store_dword v[2:3], v0
3512; GFX90A-TGSPLIT-NEXT:    s_endpgm
3513    i32* %in, i32* %out) {
3514entry:
3515  %val = load atomic i32, i32* %in syncscope("workgroup-one-as") acquire, align 4
3516  store i32 %val, i32* %out
3517  ret void
3518}
3519
3520define amdgpu_kernel void @flat_workgroup_one_as_seq_cst_load(
3521; GFX7-LABEL: flat_workgroup_one_as_seq_cst_load:
3522; GFX7:       ; %bb.0: ; %entry
3523; GFX7-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
3524; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
3525; GFX7-NEXT:    v_mov_b32_e32 v0, s0
3526; GFX7-NEXT:    v_mov_b32_e32 v1, s1
3527; GFX7-NEXT:    flat_load_dword v0, v[0:1]
3528; GFX7-NEXT:    v_mov_b32_e32 v2, s2
3529; GFX7-NEXT:    v_mov_b32_e32 v3, s3
3530; GFX7-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
3531; GFX7-NEXT:    flat_store_dword v[2:3], v0
3532; GFX7-NEXT:    s_endpgm
3533;
3534; GFX10-WGP-LABEL: flat_workgroup_one_as_seq_cst_load:
3535; GFX10-WGP:       ; %bb.0: ; %entry
3536; GFX10-WGP-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
3537; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
3538; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
3539; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
3540; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0)
3541; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
3542; GFX10-WGP-NEXT:    flat_load_dword v2, v[0:1] glc
3543; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0)
3544; GFX10-WGP-NEXT:    buffer_gl0_inv
3545; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s2
3546; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s3
3547; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
3548; GFX10-WGP-NEXT:    flat_store_dword v[0:1], v2
3549; GFX10-WGP-NEXT:    s_endpgm
3550;
3551; GFX10-CU-LABEL: flat_workgroup_one_as_seq_cst_load:
3552; GFX10-CU:       ; %bb.0: ; %entry
3553; GFX10-CU-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
3554; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
3555; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
3556; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
3557; GFX10-CU-NEXT:    flat_load_dword v2, v[0:1]
3558; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s2
3559; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s3
3560; GFX10-CU-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
3561; GFX10-CU-NEXT:    flat_store_dword v[0:1], v2
3562; GFX10-CU-NEXT:    s_endpgm
3563;
3564; SKIP-CACHE-INV-LABEL: flat_workgroup_one_as_seq_cst_load:
3565; SKIP-CACHE-INV:       ; %bb.0: ; %entry
3566; SKIP-CACHE-INV-NEXT:    s_load_dwordx4 s[0:3], s[0:1], 0x9
3567; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
3568; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s0
3569; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s1
3570; SKIP-CACHE-INV-NEXT:    flat_load_dword v0, v[0:1]
3571; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s2
3572; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s3
3573; SKIP-CACHE-INV-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
3574; SKIP-CACHE-INV-NEXT:    flat_store_dword v[2:3], v0
3575; SKIP-CACHE-INV-NEXT:    s_endpgm
3576;
3577; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_one_as_seq_cst_load:
3578; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
3579; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
3580; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
3581; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v0, s0
3582; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v1, s1
3583; GFX90A-NOTTGSPLIT-NEXT:    flat_load_dword v0, v[0:1]
3584; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
3585; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v3, s3
3586; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
3587; GFX90A-NOTTGSPLIT-NEXT:    flat_store_dword v[2:3], v0
3588; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
3589;
3590; GFX90A-TGSPLIT-LABEL: flat_workgroup_one_as_seq_cst_load:
3591; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
3592; GFX90A-TGSPLIT-NEXT:    s_load_dwordx4 s[0:3], s[4:5], 0x0
3593; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
3594; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v0, s0
3595; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v1, s1
3596; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
3597; GFX90A-TGSPLIT-NEXT:    flat_load_dword v0, v[0:1] glc
3598; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
3599; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
3600; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
3601; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v3, s3
3602; GFX90A-TGSPLIT-NEXT:    flat_store_dword v[2:3], v0
3603; GFX90A-TGSPLIT-NEXT:    s_endpgm
3604    i32* %in, i32* %out) {
3605entry:
3606  %val = load atomic i32, i32* %in syncscope("workgroup-one-as") seq_cst, align 4
3607  store i32 %val, i32* %out
3608  ret void
3609}
3610
3611define amdgpu_kernel void @flat_workgroup_one_as_unordered_store(
3612; GFX7-LABEL: flat_workgroup_one_as_unordered_store:
3613; GFX7:       ; %bb.0: ; %entry
3614; GFX7-NEXT:    s_load_dword s2, s[4:5], 0x0
3615; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x2
3616; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
3617; GFX7-NEXT:    v_mov_b32_e32 v2, s2
3618; GFX7-NEXT:    v_mov_b32_e32 v0, s0
3619; GFX7-NEXT:    v_mov_b32_e32 v1, s1
3620; GFX7-NEXT:    flat_store_dword v[0:1], v2
3621; GFX7-NEXT:    s_endpgm
3622;
3623; GFX10-WGP-LABEL: flat_workgroup_one_as_unordered_store:
3624; GFX10-WGP:       ; %bb.0: ; %entry
3625; GFX10-WGP-NEXT:    s_clause 0x1
3626; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x8
3627; GFX10-WGP-NEXT:    s_load_dword s2, s[4:5], 0x0
3628; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
3629; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
3630; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
3631; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
3632; GFX10-WGP-NEXT:    flat_store_dword v[0:1], v2
3633; GFX10-WGP-NEXT:    s_endpgm
3634;
3635; GFX10-CU-LABEL: flat_workgroup_one_as_unordered_store:
3636; GFX10-CU:       ; %bb.0: ; %entry
3637; GFX10-CU-NEXT:    s_clause 0x1
3638; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x8
3639; GFX10-CU-NEXT:    s_load_dword s2, s[4:5], 0x0
3640; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
3641; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
3642; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
3643; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
3644; GFX10-CU-NEXT:    flat_store_dword v[0:1], v2
3645; GFX10-CU-NEXT:    s_endpgm
3646;
3647; SKIP-CACHE-INV-LABEL: flat_workgroup_one_as_unordered_store:
3648; SKIP-CACHE-INV:       ; %bb.0: ; %entry
3649; SKIP-CACHE-INV-NEXT:    s_load_dword s2, s[0:1], 0x9
3650; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
3651; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
3652; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s2
3653; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s0
3654; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s1
3655; SKIP-CACHE-INV-NEXT:    flat_store_dword v[0:1], v2
3656; SKIP-CACHE-INV-NEXT:    s_endpgm
3657;
3658; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_one_as_unordered_store:
3659; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
3660; GFX90A-NOTTGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x0
3661; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x8
3662; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
3663; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
3664; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
3665; GFX90A-NOTTGSPLIT-NEXT:    flat_store_dword v[0:1], v2
3666; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
3667;
3668; GFX90A-TGSPLIT-LABEL: flat_workgroup_one_as_unordered_store:
3669; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
3670; GFX90A-TGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x0
3671; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x8
3672; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
3673; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
3674; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
3675; GFX90A-TGSPLIT-NEXT:    flat_store_dword v[0:1], v2
3676; GFX90A-TGSPLIT-NEXT:    s_endpgm
3677    i32 %in, i32* %out) {
3678entry:
3679  store atomic i32 %in, i32* %out syncscope("workgroup-one-as") unordered, align 4
3680  ret void
3681}
3682
3683define amdgpu_kernel void @flat_workgroup_one_as_monotonic_store(
3684; GFX7-LABEL: flat_workgroup_one_as_monotonic_store:
3685; GFX7:       ; %bb.0: ; %entry
3686; GFX7-NEXT:    s_load_dword s2, s[4:5], 0x0
3687; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x2
3688; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
3689; GFX7-NEXT:    v_mov_b32_e32 v2, s2
3690; GFX7-NEXT:    v_mov_b32_e32 v0, s0
3691; GFX7-NEXT:    v_mov_b32_e32 v1, s1
3692; GFX7-NEXT:    flat_store_dword v[0:1], v2
3693; GFX7-NEXT:    s_endpgm
3694;
3695; GFX10-WGP-LABEL: flat_workgroup_one_as_monotonic_store:
3696; GFX10-WGP:       ; %bb.0: ; %entry
3697; GFX10-WGP-NEXT:    s_clause 0x1
3698; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x8
3699; GFX10-WGP-NEXT:    s_load_dword s2, s[4:5], 0x0
3700; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
3701; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
3702; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
3703; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
3704; GFX10-WGP-NEXT:    flat_store_dword v[0:1], v2
3705; GFX10-WGP-NEXT:    s_endpgm
3706;
3707; GFX10-CU-LABEL: flat_workgroup_one_as_monotonic_store:
3708; GFX10-CU:       ; %bb.0: ; %entry
3709; GFX10-CU-NEXT:    s_clause 0x1
3710; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x8
3711; GFX10-CU-NEXT:    s_load_dword s2, s[4:5], 0x0
3712; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
3713; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
3714; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
3715; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
3716; GFX10-CU-NEXT:    flat_store_dword v[0:1], v2
3717; GFX10-CU-NEXT:    s_endpgm
3718;
3719; SKIP-CACHE-INV-LABEL: flat_workgroup_one_as_monotonic_store:
3720; SKIP-CACHE-INV:       ; %bb.0: ; %entry
3721; SKIP-CACHE-INV-NEXT:    s_load_dword s2, s[0:1], 0x9
3722; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
3723; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
3724; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s2
3725; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s0
3726; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s1
3727; SKIP-CACHE-INV-NEXT:    flat_store_dword v[0:1], v2
3728; SKIP-CACHE-INV-NEXT:    s_endpgm
3729;
3730; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_one_as_monotonic_store:
3731; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
3732; GFX90A-NOTTGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x0
3733; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x8
3734; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
3735; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
3736; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
3737; GFX90A-NOTTGSPLIT-NEXT:    flat_store_dword v[0:1], v2
3738; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
3739;
3740; GFX90A-TGSPLIT-LABEL: flat_workgroup_one_as_monotonic_store:
3741; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
3742; GFX90A-TGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x0
3743; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x8
3744; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
3745; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
3746; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
3747; GFX90A-TGSPLIT-NEXT:    flat_store_dword v[0:1], v2
3748; GFX90A-TGSPLIT-NEXT:    s_endpgm
3749    i32 %in, i32* %out) {
3750entry:
3751  store atomic i32 %in, i32* %out syncscope("workgroup-one-as") monotonic, align 4
3752  ret void
3753}
3754
3755define amdgpu_kernel void @flat_workgroup_one_as_release_store(
3756; GFX7-LABEL: flat_workgroup_one_as_release_store:
3757; GFX7:       ; %bb.0: ; %entry
3758; GFX7-NEXT:    s_load_dword s2, s[4:5], 0x0
3759; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x2
3760; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
3761; GFX7-NEXT:    v_mov_b32_e32 v2, s2
3762; GFX7-NEXT:    v_mov_b32_e32 v0, s0
3763; GFX7-NEXT:    v_mov_b32_e32 v1, s1
3764; GFX7-NEXT:    flat_store_dword v[0:1], v2
3765; GFX7-NEXT:    s_endpgm
3766;
3767; GFX10-WGP-LABEL: flat_workgroup_one_as_release_store:
3768; GFX10-WGP:       ; %bb.0: ; %entry
3769; GFX10-WGP-NEXT:    s_clause 0x1
3770; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x8
3771; GFX10-WGP-NEXT:    s_load_dword s2, s[4:5], 0x0
3772; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
3773; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
3774; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
3775; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
3776; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0)
3777; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
3778; GFX10-WGP-NEXT:    flat_store_dword v[0:1], v2
3779; GFX10-WGP-NEXT:    s_endpgm
3780;
3781; GFX10-CU-LABEL: flat_workgroup_one_as_release_store:
3782; GFX10-CU:       ; %bb.0: ; %entry
3783; GFX10-CU-NEXT:    s_clause 0x1
3784; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x8
3785; GFX10-CU-NEXT:    s_load_dword s2, s[4:5], 0x0
3786; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
3787; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
3788; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
3789; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
3790; GFX10-CU-NEXT:    flat_store_dword v[0:1], v2
3791; GFX10-CU-NEXT:    s_endpgm
3792;
3793; SKIP-CACHE-INV-LABEL: flat_workgroup_one_as_release_store:
3794; SKIP-CACHE-INV:       ; %bb.0: ; %entry
3795; SKIP-CACHE-INV-NEXT:    s_load_dword s2, s[0:1], 0x9
3796; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
3797; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
3798; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s2
3799; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s0
3800; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s1
3801; SKIP-CACHE-INV-NEXT:    flat_store_dword v[0:1], v2
3802; SKIP-CACHE-INV-NEXT:    s_endpgm
3803;
3804; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_one_as_release_store:
3805; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
3806; GFX90A-NOTTGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x0
3807; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x8
3808; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
3809; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
3810; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
3811; GFX90A-NOTTGSPLIT-NEXT:    flat_store_dword v[0:1], v2
3812; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
3813;
3814; GFX90A-TGSPLIT-LABEL: flat_workgroup_one_as_release_store:
3815; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
3816; GFX90A-TGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x0
3817; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x8
3818; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
3819; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
3820; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
3821; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
3822; GFX90A-TGSPLIT-NEXT:    flat_store_dword v[0:1], v2
3823; GFX90A-TGSPLIT-NEXT:    s_endpgm
3824    i32 %in, i32* %out) {
3825entry:
3826  store atomic i32 %in, i32* %out syncscope("workgroup-one-as") release, align 4
3827  ret void
3828}
3829
3830define amdgpu_kernel void @flat_workgroup_one_as_seq_cst_store(
3831; GFX7-LABEL: flat_workgroup_one_as_seq_cst_store:
3832; GFX7:       ; %bb.0: ; %entry
3833; GFX7-NEXT:    s_load_dword s2, s[4:5], 0x0
3834; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x2
3835; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
3836; GFX7-NEXT:    v_mov_b32_e32 v2, s2
3837; GFX7-NEXT:    v_mov_b32_e32 v0, s0
3838; GFX7-NEXT:    v_mov_b32_e32 v1, s1
3839; GFX7-NEXT:    flat_store_dword v[0:1], v2
3840; GFX7-NEXT:    s_endpgm
3841;
3842; GFX10-WGP-LABEL: flat_workgroup_one_as_seq_cst_store:
3843; GFX10-WGP:       ; %bb.0: ; %entry
3844; GFX10-WGP-NEXT:    s_clause 0x1
3845; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x8
3846; GFX10-WGP-NEXT:    s_load_dword s2, s[4:5], 0x0
3847; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
3848; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
3849; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
3850; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
3851; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0)
3852; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
3853; GFX10-WGP-NEXT:    flat_store_dword v[0:1], v2
3854; GFX10-WGP-NEXT:    s_endpgm
3855;
3856; GFX10-CU-LABEL: flat_workgroup_one_as_seq_cst_store:
3857; GFX10-CU:       ; %bb.0: ; %entry
3858; GFX10-CU-NEXT:    s_clause 0x1
3859; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x8
3860; GFX10-CU-NEXT:    s_load_dword s2, s[4:5], 0x0
3861; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
3862; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
3863; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
3864; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
3865; GFX10-CU-NEXT:    flat_store_dword v[0:1], v2
3866; GFX10-CU-NEXT:    s_endpgm
3867;
3868; SKIP-CACHE-INV-LABEL: flat_workgroup_one_as_seq_cst_store:
3869; SKIP-CACHE-INV:       ; %bb.0: ; %entry
3870; SKIP-CACHE-INV-NEXT:    s_load_dword s2, s[0:1], 0x9
3871; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
3872; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
3873; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s2
3874; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s0
3875; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s1
3876; SKIP-CACHE-INV-NEXT:    flat_store_dword v[0:1], v2
3877; SKIP-CACHE-INV-NEXT:    s_endpgm
3878;
3879; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_one_as_seq_cst_store:
3880; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
3881; GFX90A-NOTTGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x0
3882; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x8
3883; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
3884; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
3885; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
3886; GFX90A-NOTTGSPLIT-NEXT:    flat_store_dword v[0:1], v2
3887; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
3888;
3889; GFX90A-TGSPLIT-LABEL: flat_workgroup_one_as_seq_cst_store:
3890; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
3891; GFX90A-TGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x0
3892; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x8
3893; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
3894; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
3895; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
3896; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
3897; GFX90A-TGSPLIT-NEXT:    flat_store_dword v[0:1], v2
3898; GFX90A-TGSPLIT-NEXT:    s_endpgm
3899    i32 %in, i32* %out) {
3900entry:
3901  store atomic i32 %in, i32* %out syncscope("workgroup-one-as") seq_cst, align 4
3902  ret void
3903}
3904
3905define amdgpu_kernel void @flat_workgroup_one_as_monotonic_atomicrmw(
3906; GFX7-LABEL: flat_workgroup_one_as_monotonic_atomicrmw:
3907; GFX7:       ; %bb.0: ; %entry
3908; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
3909; GFX7-NEXT:    s_load_dword s2, s[4:5], 0x2
3910; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
3911; GFX7-NEXT:    v_mov_b32_e32 v0, s0
3912; GFX7-NEXT:    v_mov_b32_e32 v1, s1
3913; GFX7-NEXT:    v_mov_b32_e32 v2, s2
3914; GFX7-NEXT:    flat_atomic_swap v[0:1], v2
3915; GFX7-NEXT:    s_endpgm
3916;
3917; GFX10-WGP-LABEL: flat_workgroup_one_as_monotonic_atomicrmw:
3918; GFX10-WGP:       ; %bb.0: ; %entry
3919; GFX10-WGP-NEXT:    s_clause 0x1
3920; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
3921; GFX10-WGP-NEXT:    s_load_dword s2, s[4:5], 0x8
3922; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
3923; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
3924; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
3925; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
3926; GFX10-WGP-NEXT:    flat_atomic_swap v[0:1], v2
3927; GFX10-WGP-NEXT:    s_endpgm
3928;
3929; GFX10-CU-LABEL: flat_workgroup_one_as_monotonic_atomicrmw:
3930; GFX10-CU:       ; %bb.0: ; %entry
3931; GFX10-CU-NEXT:    s_clause 0x1
3932; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
3933; GFX10-CU-NEXT:    s_load_dword s2, s[4:5], 0x8
3934; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
3935; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
3936; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
3937; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
3938; GFX10-CU-NEXT:    flat_atomic_swap v[0:1], v2
3939; GFX10-CU-NEXT:    s_endpgm
3940;
3941; SKIP-CACHE-INV-LABEL: flat_workgroup_one_as_monotonic_atomicrmw:
3942; SKIP-CACHE-INV:       ; %bb.0: ; %entry
3943; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
3944; SKIP-CACHE-INV-NEXT:    s_load_dword s0, s[0:1], 0xb
3945; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
3946; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
3947; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
3948; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
3949; SKIP-CACHE-INV-NEXT:    flat_atomic_swap v[0:1], v2
3950; SKIP-CACHE-INV-NEXT:    s_endpgm
3951;
3952; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_one_as_monotonic_atomicrmw:
3953; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
3954; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
3955; GFX90A-NOTTGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x8
3956; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
3957; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
3958; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
3959; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_swap v[0:1], v2
3960; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
3961;
3962; GFX90A-TGSPLIT-LABEL: flat_workgroup_one_as_monotonic_atomicrmw:
3963; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
3964; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
3965; GFX90A-TGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x8
3966; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
3967; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
3968; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
3969; GFX90A-TGSPLIT-NEXT:    flat_atomic_swap v[0:1], v2
3970; GFX90A-TGSPLIT-NEXT:    s_endpgm
3971    i32* %out, i32 %in) {
3972entry:
3973  %val = atomicrmw volatile xchg i32* %out, i32 %in syncscope("workgroup-one-as") monotonic
3974  ret void
3975}
3976
3977define amdgpu_kernel void @flat_workgroup_one_as_acquire_atomicrmw(
3978; GFX7-LABEL: flat_workgroup_one_as_acquire_atomicrmw:
3979; GFX7:       ; %bb.0: ; %entry
3980; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
3981; GFX7-NEXT:    s_load_dword s2, s[4:5], 0x2
3982; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
3983; GFX7-NEXT:    v_mov_b32_e32 v0, s0
3984; GFX7-NEXT:    v_mov_b32_e32 v1, s1
3985; GFX7-NEXT:    v_mov_b32_e32 v2, s2
3986; GFX7-NEXT:    flat_atomic_swap v[0:1], v2
3987; GFX7-NEXT:    s_endpgm
3988;
3989; GFX10-WGP-LABEL: flat_workgroup_one_as_acquire_atomicrmw:
3990; GFX10-WGP:       ; %bb.0: ; %entry
3991; GFX10-WGP-NEXT:    s_clause 0x1
3992; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
3993; GFX10-WGP-NEXT:    s_load_dword s2, s[4:5], 0x8
3994; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
3995; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
3996; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
3997; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
3998; GFX10-WGP-NEXT:    flat_atomic_swap v[0:1], v2
3999; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
4000; GFX10-WGP-NEXT:    buffer_gl0_inv
4001; GFX10-WGP-NEXT:    s_endpgm
4002;
4003; GFX10-CU-LABEL: flat_workgroup_one_as_acquire_atomicrmw:
4004; GFX10-CU:       ; %bb.0: ; %entry
4005; GFX10-CU-NEXT:    s_clause 0x1
4006; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4007; GFX10-CU-NEXT:    s_load_dword s2, s[4:5], 0x8
4008; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
4009; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
4010; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
4011; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
4012; GFX10-CU-NEXT:    flat_atomic_swap v[0:1], v2
4013; GFX10-CU-NEXT:    s_endpgm
4014;
4015; SKIP-CACHE-INV-LABEL: flat_workgroup_one_as_acquire_atomicrmw:
4016; SKIP-CACHE-INV:       ; %bb.0: ; %entry
4017; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
4018; SKIP-CACHE-INV-NEXT:    s_load_dword s0, s[0:1], 0xb
4019; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
4020; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
4021; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
4022; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
4023; SKIP-CACHE-INV-NEXT:    flat_atomic_swap v[0:1], v2
4024; SKIP-CACHE-INV-NEXT:    s_endpgm
4025;
4026; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_one_as_acquire_atomicrmw:
4027; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
4028; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4029; GFX90A-NOTTGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x8
4030; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
4031; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
4032; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
4033; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_swap v[0:1], v2
4034; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
4035;
4036; GFX90A-TGSPLIT-LABEL: flat_workgroup_one_as_acquire_atomicrmw:
4037; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
4038; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4039; GFX90A-TGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x8
4040; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
4041; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
4042; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
4043; GFX90A-TGSPLIT-NEXT:    flat_atomic_swap v[0:1], v2
4044; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
4045; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
4046; GFX90A-TGSPLIT-NEXT:    s_endpgm
4047    i32* %out, i32 %in) {
4048entry:
4049  %val = atomicrmw volatile xchg i32* %out, i32 %in syncscope("workgroup-one-as") acquire
4050  ret void
4051}
4052
4053define amdgpu_kernel void @flat_workgroup_one_as_release_atomicrmw(
4054; GFX7-LABEL: flat_workgroup_one_as_release_atomicrmw:
4055; GFX7:       ; %bb.0: ; %entry
4056; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4057; GFX7-NEXT:    s_load_dword s2, s[4:5], 0x2
4058; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
4059; GFX7-NEXT:    v_mov_b32_e32 v0, s0
4060; GFX7-NEXT:    v_mov_b32_e32 v1, s1
4061; GFX7-NEXT:    v_mov_b32_e32 v2, s2
4062; GFX7-NEXT:    flat_atomic_swap v[0:1], v2
4063; GFX7-NEXT:    s_endpgm
4064;
4065; GFX10-WGP-LABEL: flat_workgroup_one_as_release_atomicrmw:
4066; GFX10-WGP:       ; %bb.0: ; %entry
4067; GFX10-WGP-NEXT:    s_clause 0x1
4068; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4069; GFX10-WGP-NEXT:    s_load_dword s2, s[4:5], 0x8
4070; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
4071; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
4072; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
4073; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
4074; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0)
4075; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
4076; GFX10-WGP-NEXT:    flat_atomic_swap v[0:1], v2
4077; GFX10-WGP-NEXT:    s_endpgm
4078;
4079; GFX10-CU-LABEL: flat_workgroup_one_as_release_atomicrmw:
4080; GFX10-CU:       ; %bb.0: ; %entry
4081; GFX10-CU-NEXT:    s_clause 0x1
4082; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4083; GFX10-CU-NEXT:    s_load_dword s2, s[4:5], 0x8
4084; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
4085; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
4086; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
4087; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
4088; GFX10-CU-NEXT:    flat_atomic_swap v[0:1], v2
4089; GFX10-CU-NEXT:    s_endpgm
4090;
4091; SKIP-CACHE-INV-LABEL: flat_workgroup_one_as_release_atomicrmw:
4092; SKIP-CACHE-INV:       ; %bb.0: ; %entry
4093; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
4094; SKIP-CACHE-INV-NEXT:    s_load_dword s0, s[0:1], 0xb
4095; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
4096; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
4097; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
4098; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
4099; SKIP-CACHE-INV-NEXT:    flat_atomic_swap v[0:1], v2
4100; SKIP-CACHE-INV-NEXT:    s_endpgm
4101;
4102; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_one_as_release_atomicrmw:
4103; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
4104; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4105; GFX90A-NOTTGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x8
4106; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
4107; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
4108; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
4109; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_swap v[0:1], v2
4110; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
4111;
4112; GFX90A-TGSPLIT-LABEL: flat_workgroup_one_as_release_atomicrmw:
4113; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
4114; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4115; GFX90A-TGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x8
4116; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
4117; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
4118; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
4119; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
4120; GFX90A-TGSPLIT-NEXT:    flat_atomic_swap v[0:1], v2
4121; GFX90A-TGSPLIT-NEXT:    s_endpgm
4122    i32* %out, i32 %in) {
4123entry:
4124  %val = atomicrmw volatile xchg i32* %out, i32 %in syncscope("workgroup-one-as") release
4125  ret void
4126}
4127
4128define amdgpu_kernel void @flat_workgroup_one_as_acq_rel_atomicrmw(
4129; GFX7-LABEL: flat_workgroup_one_as_acq_rel_atomicrmw:
4130; GFX7:       ; %bb.0: ; %entry
4131; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4132; GFX7-NEXT:    s_load_dword s2, s[4:5], 0x2
4133; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
4134; GFX7-NEXT:    v_mov_b32_e32 v0, s0
4135; GFX7-NEXT:    v_mov_b32_e32 v1, s1
4136; GFX7-NEXT:    v_mov_b32_e32 v2, s2
4137; GFX7-NEXT:    flat_atomic_swap v[0:1], v2
4138; GFX7-NEXT:    s_endpgm
4139;
4140; GFX10-WGP-LABEL: flat_workgroup_one_as_acq_rel_atomicrmw:
4141; GFX10-WGP:       ; %bb.0: ; %entry
4142; GFX10-WGP-NEXT:    s_clause 0x1
4143; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4144; GFX10-WGP-NEXT:    s_load_dword s2, s[4:5], 0x8
4145; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
4146; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
4147; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
4148; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
4149; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0)
4150; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
4151; GFX10-WGP-NEXT:    flat_atomic_swap v[0:1], v2
4152; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
4153; GFX10-WGP-NEXT:    buffer_gl0_inv
4154; GFX10-WGP-NEXT:    s_endpgm
4155;
4156; GFX10-CU-LABEL: flat_workgroup_one_as_acq_rel_atomicrmw:
4157; GFX10-CU:       ; %bb.0: ; %entry
4158; GFX10-CU-NEXT:    s_clause 0x1
4159; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4160; GFX10-CU-NEXT:    s_load_dword s2, s[4:5], 0x8
4161; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
4162; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
4163; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
4164; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
4165; GFX10-CU-NEXT:    flat_atomic_swap v[0:1], v2
4166; GFX10-CU-NEXT:    s_endpgm
4167;
4168; SKIP-CACHE-INV-LABEL: flat_workgroup_one_as_acq_rel_atomicrmw:
4169; SKIP-CACHE-INV:       ; %bb.0: ; %entry
4170; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
4171; SKIP-CACHE-INV-NEXT:    s_load_dword s0, s[0:1], 0xb
4172; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
4173; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
4174; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
4175; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
4176; SKIP-CACHE-INV-NEXT:    flat_atomic_swap v[0:1], v2
4177; SKIP-CACHE-INV-NEXT:    s_endpgm
4178;
4179; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_one_as_acq_rel_atomicrmw:
4180; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
4181; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4182; GFX90A-NOTTGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x8
4183; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
4184; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
4185; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
4186; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_swap v[0:1], v2
4187; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
4188;
4189; GFX90A-TGSPLIT-LABEL: flat_workgroup_one_as_acq_rel_atomicrmw:
4190; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
4191; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4192; GFX90A-TGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x8
4193; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
4194; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
4195; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
4196; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
4197; GFX90A-TGSPLIT-NEXT:    flat_atomic_swap v[0:1], v2
4198; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
4199; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
4200; GFX90A-TGSPLIT-NEXT:    s_endpgm
4201    i32* %out, i32 %in) {
4202entry:
4203  %val = atomicrmw volatile xchg i32* %out, i32 %in syncscope("workgroup-one-as") acq_rel
4204  ret void
4205}
4206
4207define amdgpu_kernel void @flat_workgroup_one_as_seq_cst_atomicrmw(
4208; GFX7-LABEL: flat_workgroup_one_as_seq_cst_atomicrmw:
4209; GFX7:       ; %bb.0: ; %entry
4210; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4211; GFX7-NEXT:    s_load_dword s2, s[4:5], 0x2
4212; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
4213; GFX7-NEXT:    v_mov_b32_e32 v0, s0
4214; GFX7-NEXT:    v_mov_b32_e32 v1, s1
4215; GFX7-NEXT:    v_mov_b32_e32 v2, s2
4216; GFX7-NEXT:    flat_atomic_swap v[0:1], v2
4217; GFX7-NEXT:    s_endpgm
4218;
4219; GFX10-WGP-LABEL: flat_workgroup_one_as_seq_cst_atomicrmw:
4220; GFX10-WGP:       ; %bb.0: ; %entry
4221; GFX10-WGP-NEXT:    s_clause 0x1
4222; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4223; GFX10-WGP-NEXT:    s_load_dword s2, s[4:5], 0x8
4224; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
4225; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
4226; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
4227; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
4228; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0)
4229; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
4230; GFX10-WGP-NEXT:    flat_atomic_swap v[0:1], v2
4231; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
4232; GFX10-WGP-NEXT:    buffer_gl0_inv
4233; GFX10-WGP-NEXT:    s_endpgm
4234;
4235; GFX10-CU-LABEL: flat_workgroup_one_as_seq_cst_atomicrmw:
4236; GFX10-CU:       ; %bb.0: ; %entry
4237; GFX10-CU-NEXT:    s_clause 0x1
4238; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4239; GFX10-CU-NEXT:    s_load_dword s2, s[4:5], 0x8
4240; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
4241; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
4242; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
4243; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
4244; GFX10-CU-NEXT:    flat_atomic_swap v[0:1], v2
4245; GFX10-CU-NEXT:    s_endpgm
4246;
4247; SKIP-CACHE-INV-LABEL: flat_workgroup_one_as_seq_cst_atomicrmw:
4248; SKIP-CACHE-INV:       ; %bb.0: ; %entry
4249; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
4250; SKIP-CACHE-INV-NEXT:    s_load_dword s0, s[0:1], 0xb
4251; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
4252; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
4253; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
4254; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
4255; SKIP-CACHE-INV-NEXT:    flat_atomic_swap v[0:1], v2
4256; SKIP-CACHE-INV-NEXT:    s_endpgm
4257;
4258; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_one_as_seq_cst_atomicrmw:
4259; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
4260; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4261; GFX90A-NOTTGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x8
4262; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
4263; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
4264; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
4265; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_swap v[0:1], v2
4266; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
4267;
4268; GFX90A-TGSPLIT-LABEL: flat_workgroup_one_as_seq_cst_atomicrmw:
4269; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
4270; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4271; GFX90A-TGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x8
4272; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
4273; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
4274; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
4275; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
4276; GFX90A-TGSPLIT-NEXT:    flat_atomic_swap v[0:1], v2
4277; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
4278; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
4279; GFX90A-TGSPLIT-NEXT:    s_endpgm
4280    i32* %out, i32 %in) {
4281entry:
4282  %val = atomicrmw volatile xchg i32* %out, i32 %in syncscope("workgroup-one-as") seq_cst
4283  ret void
4284}
4285
4286define amdgpu_kernel void @flat_workgroup_one_as_acquire_ret_atomicrmw(
4287; GFX7-LABEL: flat_workgroup_one_as_acquire_ret_atomicrmw:
4288; GFX7:       ; %bb.0: ; %entry
4289; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4290; GFX7-NEXT:    s_load_dword s2, s[4:5], 0x2
4291; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
4292; GFX7-NEXT:    v_mov_b32_e32 v0, s0
4293; GFX7-NEXT:    v_mov_b32_e32 v1, s1
4294; GFX7-NEXT:    v_mov_b32_e32 v2, s2
4295; GFX7-NEXT:    flat_atomic_swap v2, v[0:1], v2 glc
4296; GFX7-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
4297; GFX7-NEXT:    flat_store_dword v[0:1], v2
4298; GFX7-NEXT:    s_endpgm
4299;
4300; GFX10-WGP-LABEL: flat_workgroup_one_as_acquire_ret_atomicrmw:
4301; GFX10-WGP:       ; %bb.0: ; %entry
4302; GFX10-WGP-NEXT:    s_clause 0x1
4303; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4304; GFX10-WGP-NEXT:    s_load_dword s2, s[4:5], 0x8
4305; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
4306; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
4307; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
4308; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
4309; GFX10-WGP-NEXT:    flat_atomic_swap v2, v[0:1], v2 glc
4310; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0)
4311; GFX10-WGP-NEXT:    buffer_gl0_inv
4312; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
4313; GFX10-WGP-NEXT:    flat_store_dword v[0:1], v2
4314; GFX10-WGP-NEXT:    s_endpgm
4315;
4316; GFX10-CU-LABEL: flat_workgroup_one_as_acquire_ret_atomicrmw:
4317; GFX10-CU:       ; %bb.0: ; %entry
4318; GFX10-CU-NEXT:    s_clause 0x1
4319; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4320; GFX10-CU-NEXT:    s_load_dword s2, s[4:5], 0x8
4321; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
4322; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
4323; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
4324; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
4325; GFX10-CU-NEXT:    flat_atomic_swap v2, v[0:1], v2 glc
4326; GFX10-CU-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
4327; GFX10-CU-NEXT:    flat_store_dword v[0:1], v2
4328; GFX10-CU-NEXT:    s_endpgm
4329;
4330; SKIP-CACHE-INV-LABEL: flat_workgroup_one_as_acquire_ret_atomicrmw:
4331; SKIP-CACHE-INV:       ; %bb.0: ; %entry
4332; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
4333; SKIP-CACHE-INV-NEXT:    s_load_dword s0, s[0:1], 0xb
4334; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
4335; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
4336; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
4337; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
4338; SKIP-CACHE-INV-NEXT:    flat_atomic_swap v2, v[0:1], v2 glc
4339; SKIP-CACHE-INV-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
4340; SKIP-CACHE-INV-NEXT:    flat_store_dword v[0:1], v2
4341; SKIP-CACHE-INV-NEXT:    s_endpgm
4342;
4343; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_one_as_acquire_ret_atomicrmw:
4344; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
4345; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4346; GFX90A-NOTTGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x8
4347; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
4348; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
4349; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
4350; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_swap v2, v[0:1], v2 glc
4351; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
4352; GFX90A-NOTTGSPLIT-NEXT:    flat_store_dword v[0:1], v2
4353; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
4354;
4355; GFX90A-TGSPLIT-LABEL: flat_workgroup_one_as_acquire_ret_atomicrmw:
4356; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
4357; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4358; GFX90A-TGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x8
4359; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
4360; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
4361; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
4362; GFX90A-TGSPLIT-NEXT:    flat_atomic_swap v2, v[0:1], v2 glc
4363; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
4364; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
4365; GFX90A-TGSPLIT-NEXT:    flat_store_dword v[0:1], v2
4366; GFX90A-TGSPLIT-NEXT:    s_endpgm
4367    i32* %out, i32 %in) {
4368entry:
4369  %val = atomicrmw volatile xchg i32* %out, i32 %in syncscope("workgroup-one-as") acquire
4370  store i32 %val, i32* %out, align 4
4371  ret void
4372}
4373
4374define amdgpu_kernel void @flat_workgroup_one_as_acq_rel_ret_atomicrmw(
4375; GFX7-LABEL: flat_workgroup_one_as_acq_rel_ret_atomicrmw:
4376; GFX7:       ; %bb.0: ; %entry
4377; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4378; GFX7-NEXT:    s_load_dword s2, s[4:5], 0x2
4379; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
4380; GFX7-NEXT:    v_mov_b32_e32 v0, s0
4381; GFX7-NEXT:    v_mov_b32_e32 v1, s1
4382; GFX7-NEXT:    v_mov_b32_e32 v2, s2
4383; GFX7-NEXT:    flat_atomic_swap v2, v[0:1], v2 glc
4384; GFX7-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
4385; GFX7-NEXT:    flat_store_dword v[0:1], v2
4386; GFX7-NEXT:    s_endpgm
4387;
4388; GFX10-WGP-LABEL: flat_workgroup_one_as_acq_rel_ret_atomicrmw:
4389; GFX10-WGP:       ; %bb.0: ; %entry
4390; GFX10-WGP-NEXT:    s_clause 0x1
4391; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4392; GFX10-WGP-NEXT:    s_load_dword s2, s[4:5], 0x8
4393; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
4394; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
4395; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
4396; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
4397; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0)
4398; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
4399; GFX10-WGP-NEXT:    flat_atomic_swap v2, v[0:1], v2 glc
4400; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0)
4401; GFX10-WGP-NEXT:    buffer_gl0_inv
4402; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
4403; GFX10-WGP-NEXT:    flat_store_dword v[0:1], v2
4404; GFX10-WGP-NEXT:    s_endpgm
4405;
4406; GFX10-CU-LABEL: flat_workgroup_one_as_acq_rel_ret_atomicrmw:
4407; GFX10-CU:       ; %bb.0: ; %entry
4408; GFX10-CU-NEXT:    s_clause 0x1
4409; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4410; GFX10-CU-NEXT:    s_load_dword s2, s[4:5], 0x8
4411; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
4412; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
4413; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
4414; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
4415; GFX10-CU-NEXT:    flat_atomic_swap v2, v[0:1], v2 glc
4416; GFX10-CU-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
4417; GFX10-CU-NEXT:    flat_store_dword v[0:1], v2
4418; GFX10-CU-NEXT:    s_endpgm
4419;
4420; SKIP-CACHE-INV-LABEL: flat_workgroup_one_as_acq_rel_ret_atomicrmw:
4421; SKIP-CACHE-INV:       ; %bb.0: ; %entry
4422; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
4423; SKIP-CACHE-INV-NEXT:    s_load_dword s0, s[0:1], 0xb
4424; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
4425; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
4426; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
4427; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
4428; SKIP-CACHE-INV-NEXT:    flat_atomic_swap v2, v[0:1], v2 glc
4429; SKIP-CACHE-INV-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
4430; SKIP-CACHE-INV-NEXT:    flat_store_dword v[0:1], v2
4431; SKIP-CACHE-INV-NEXT:    s_endpgm
4432;
4433; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_one_as_acq_rel_ret_atomicrmw:
4434; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
4435; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4436; GFX90A-NOTTGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x8
4437; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
4438; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
4439; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
4440; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_swap v2, v[0:1], v2 glc
4441; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
4442; GFX90A-NOTTGSPLIT-NEXT:    flat_store_dword v[0:1], v2
4443; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
4444;
4445; GFX90A-TGSPLIT-LABEL: flat_workgroup_one_as_acq_rel_ret_atomicrmw:
4446; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
4447; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4448; GFX90A-TGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x8
4449; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
4450; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
4451; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
4452; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
4453; GFX90A-TGSPLIT-NEXT:    flat_atomic_swap v2, v[0:1], v2 glc
4454; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
4455; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
4456; GFX90A-TGSPLIT-NEXT:    flat_store_dword v[0:1], v2
4457; GFX90A-TGSPLIT-NEXT:    s_endpgm
4458    i32* %out, i32 %in) {
4459entry:
4460  %val = atomicrmw volatile xchg i32* %out, i32 %in syncscope("workgroup-one-as") acq_rel
4461  store i32 %val, i32* %out, align 4
4462  ret void
4463}
4464
4465define amdgpu_kernel void @flat_workgroup_one_as_seq_cst_ret_atomicrmw(
4466; GFX7-LABEL: flat_workgroup_one_as_seq_cst_ret_atomicrmw:
4467; GFX7:       ; %bb.0: ; %entry
4468; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4469; GFX7-NEXT:    s_load_dword s2, s[4:5], 0x2
4470; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
4471; GFX7-NEXT:    v_mov_b32_e32 v0, s0
4472; GFX7-NEXT:    v_mov_b32_e32 v1, s1
4473; GFX7-NEXT:    v_mov_b32_e32 v2, s2
4474; GFX7-NEXT:    flat_atomic_swap v2, v[0:1], v2 glc
4475; GFX7-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
4476; GFX7-NEXT:    flat_store_dword v[0:1], v2
4477; GFX7-NEXT:    s_endpgm
4478;
4479; GFX10-WGP-LABEL: flat_workgroup_one_as_seq_cst_ret_atomicrmw:
4480; GFX10-WGP:       ; %bb.0: ; %entry
4481; GFX10-WGP-NEXT:    s_clause 0x1
4482; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4483; GFX10-WGP-NEXT:    s_load_dword s2, s[4:5], 0x8
4484; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
4485; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
4486; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
4487; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
4488; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0)
4489; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
4490; GFX10-WGP-NEXT:    flat_atomic_swap v2, v[0:1], v2 glc
4491; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0)
4492; GFX10-WGP-NEXT:    buffer_gl0_inv
4493; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
4494; GFX10-WGP-NEXT:    flat_store_dword v[0:1], v2
4495; GFX10-WGP-NEXT:    s_endpgm
4496;
4497; GFX10-CU-LABEL: flat_workgroup_one_as_seq_cst_ret_atomicrmw:
4498; GFX10-CU:       ; %bb.0: ; %entry
4499; GFX10-CU-NEXT:    s_clause 0x1
4500; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4501; GFX10-CU-NEXT:    s_load_dword s2, s[4:5], 0x8
4502; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
4503; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
4504; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
4505; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
4506; GFX10-CU-NEXT:    flat_atomic_swap v2, v[0:1], v2 glc
4507; GFX10-CU-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
4508; GFX10-CU-NEXT:    flat_store_dword v[0:1], v2
4509; GFX10-CU-NEXT:    s_endpgm
4510;
4511; SKIP-CACHE-INV-LABEL: flat_workgroup_one_as_seq_cst_ret_atomicrmw:
4512; SKIP-CACHE-INV:       ; %bb.0: ; %entry
4513; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
4514; SKIP-CACHE-INV-NEXT:    s_load_dword s0, s[0:1], 0xb
4515; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
4516; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
4517; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
4518; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
4519; SKIP-CACHE-INV-NEXT:    flat_atomic_swap v2, v[0:1], v2 glc
4520; SKIP-CACHE-INV-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
4521; SKIP-CACHE-INV-NEXT:    flat_store_dword v[0:1], v2
4522; SKIP-CACHE-INV-NEXT:    s_endpgm
4523;
4524; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_one_as_seq_cst_ret_atomicrmw:
4525; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
4526; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4527; GFX90A-NOTTGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x8
4528; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
4529; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
4530; GFX90A-NOTTGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
4531; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_swap v2, v[0:1], v2 glc
4532; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
4533; GFX90A-NOTTGSPLIT-NEXT:    flat_store_dword v[0:1], v2
4534; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
4535;
4536; GFX90A-TGSPLIT-LABEL: flat_workgroup_one_as_seq_cst_ret_atomicrmw:
4537; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
4538; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4539; GFX90A-TGSPLIT-NEXT:    s_load_dword s2, s[4:5], 0x8
4540; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
4541; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
4542; GFX90A-TGSPLIT-NEXT:    v_mov_b32_e32 v2, s2
4543; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
4544; GFX90A-TGSPLIT-NEXT:    flat_atomic_swap v2, v[0:1], v2 glc
4545; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
4546; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
4547; GFX90A-TGSPLIT-NEXT:    flat_store_dword v[0:1], v2
4548; GFX90A-TGSPLIT-NEXT:    s_endpgm
4549    i32* %out, i32 %in) {
4550entry:
4551  %val = atomicrmw volatile xchg i32* %out, i32 %in syncscope("workgroup-one-as") seq_cst
4552  store i32 %val, i32* %out, align 4
4553  ret void
4554}
4555
4556define amdgpu_kernel void @flat_workgroup_one_as_monotonic_monotonic_cmpxchg(
4557; GFX7-LABEL: flat_workgroup_one_as_monotonic_monotonic_cmpxchg:
4558; GFX7:       ; %bb.0: ; %entry
4559; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4560; GFX7-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x2
4561; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
4562; GFX7-NEXT:    s_add_u32 s0, s0, 16
4563; GFX7-NEXT:    s_addc_u32 s1, s1, 0
4564; GFX7-NEXT:    v_mov_b32_e32 v0, s0
4565; GFX7-NEXT:    v_mov_b32_e32 v2, s2
4566; GFX7-NEXT:    v_mov_b32_e32 v1, s1
4567; GFX7-NEXT:    v_mov_b32_e32 v3, s3
4568; GFX7-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
4569; GFX7-NEXT:    s_endpgm
4570;
4571; GFX10-WGP-LABEL: flat_workgroup_one_as_monotonic_monotonic_cmpxchg:
4572; GFX10-WGP:       ; %bb.0: ; %entry
4573; GFX10-WGP-NEXT:    s_clause 0x1
4574; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4575; GFX10-WGP-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
4576; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
4577; GFX10-WGP-NEXT:    s_add_u32 s0, s0, 16
4578; GFX10-WGP-NEXT:    s_addc_u32 s1, s1, 0
4579; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
4580; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
4581; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
4582; GFX10-WGP-NEXT:    v_mov_b32_e32 v3, s3
4583; GFX10-WGP-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
4584; GFX10-WGP-NEXT:    s_endpgm
4585;
4586; GFX10-CU-LABEL: flat_workgroup_one_as_monotonic_monotonic_cmpxchg:
4587; GFX10-CU:       ; %bb.0: ; %entry
4588; GFX10-CU-NEXT:    s_clause 0x1
4589; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4590; GFX10-CU-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
4591; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
4592; GFX10-CU-NEXT:    s_add_u32 s0, s0, 16
4593; GFX10-CU-NEXT:    s_addc_u32 s1, s1, 0
4594; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
4595; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
4596; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
4597; GFX10-CU-NEXT:    v_mov_b32_e32 v3, s3
4598; GFX10-CU-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
4599; GFX10-CU-NEXT:    s_endpgm
4600;
4601; SKIP-CACHE-INV-LABEL: flat_workgroup_one_as_monotonic_monotonic_cmpxchg:
4602; SKIP-CACHE-INV:       ; %bb.0: ; %entry
4603; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
4604; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
4605; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
4606; SKIP-CACHE-INV-NEXT:    s_add_u32 s2, s2, 16
4607; SKIP-CACHE-INV-NEXT:    s_addc_u32 s3, s3, 0
4608; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
4609; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s1
4610; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
4611; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
4612; SKIP-CACHE-INV-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
4613; SKIP-CACHE-INV-NEXT:    s_endpgm
4614;
4615; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_one_as_monotonic_monotonic_cmpxchg:
4616; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
4617; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4618; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
4619; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
4620; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
4621; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
4622; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
4623; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
4624;
4625; GFX90A-TGSPLIT-LABEL: flat_workgroup_one_as_monotonic_monotonic_cmpxchg:
4626; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
4627; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4628; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
4629; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
4630; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
4631; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
4632; GFX90A-TGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
4633; GFX90A-TGSPLIT-NEXT:    s_endpgm
4634    i32* %out, i32 %in, i32 %old) {
4635entry:
4636  %gep = getelementptr i32, i32* %out, i32 4
4637  %val = cmpxchg volatile i32* %gep, i32 %old, i32 %in syncscope("workgroup-one-as") monotonic monotonic
4638  ret void
4639}
4640
4641define amdgpu_kernel void @flat_workgroup_one_as_acquire_monotonic_cmpxchg(
4642; GFX7-LABEL: flat_workgroup_one_as_acquire_monotonic_cmpxchg:
4643; GFX7:       ; %bb.0: ; %entry
4644; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4645; GFX7-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x2
4646; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
4647; GFX7-NEXT:    s_add_u32 s0, s0, 16
4648; GFX7-NEXT:    s_addc_u32 s1, s1, 0
4649; GFX7-NEXT:    v_mov_b32_e32 v0, s0
4650; GFX7-NEXT:    v_mov_b32_e32 v2, s2
4651; GFX7-NEXT:    v_mov_b32_e32 v1, s1
4652; GFX7-NEXT:    v_mov_b32_e32 v3, s3
4653; GFX7-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
4654; GFX7-NEXT:    s_endpgm
4655;
4656; GFX10-WGP-LABEL: flat_workgroup_one_as_acquire_monotonic_cmpxchg:
4657; GFX10-WGP:       ; %bb.0: ; %entry
4658; GFX10-WGP-NEXT:    s_clause 0x1
4659; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4660; GFX10-WGP-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
4661; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
4662; GFX10-WGP-NEXT:    s_add_u32 s0, s0, 16
4663; GFX10-WGP-NEXT:    s_addc_u32 s1, s1, 0
4664; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
4665; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
4666; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
4667; GFX10-WGP-NEXT:    v_mov_b32_e32 v3, s3
4668; GFX10-WGP-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
4669; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
4670; GFX10-WGP-NEXT:    buffer_gl0_inv
4671; GFX10-WGP-NEXT:    s_endpgm
4672;
4673; GFX10-CU-LABEL: flat_workgroup_one_as_acquire_monotonic_cmpxchg:
4674; GFX10-CU:       ; %bb.0: ; %entry
4675; GFX10-CU-NEXT:    s_clause 0x1
4676; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4677; GFX10-CU-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
4678; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
4679; GFX10-CU-NEXT:    s_add_u32 s0, s0, 16
4680; GFX10-CU-NEXT:    s_addc_u32 s1, s1, 0
4681; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
4682; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
4683; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
4684; GFX10-CU-NEXT:    v_mov_b32_e32 v3, s3
4685; GFX10-CU-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
4686; GFX10-CU-NEXT:    s_endpgm
4687;
4688; SKIP-CACHE-INV-LABEL: flat_workgroup_one_as_acquire_monotonic_cmpxchg:
4689; SKIP-CACHE-INV:       ; %bb.0: ; %entry
4690; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
4691; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
4692; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
4693; SKIP-CACHE-INV-NEXT:    s_add_u32 s2, s2, 16
4694; SKIP-CACHE-INV-NEXT:    s_addc_u32 s3, s3, 0
4695; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
4696; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s1
4697; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
4698; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
4699; SKIP-CACHE-INV-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
4700; SKIP-CACHE-INV-NEXT:    s_endpgm
4701;
4702; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_one_as_acquire_monotonic_cmpxchg:
4703; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
4704; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4705; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
4706; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
4707; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
4708; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
4709; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
4710; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
4711;
4712; GFX90A-TGSPLIT-LABEL: flat_workgroup_one_as_acquire_monotonic_cmpxchg:
4713; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
4714; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4715; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
4716; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
4717; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
4718; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
4719; GFX90A-TGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
4720; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
4721; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
4722; GFX90A-TGSPLIT-NEXT:    s_endpgm
4723    i32* %out, i32 %in, i32 %old) {
4724entry:
4725  %gep = getelementptr i32, i32* %out, i32 4
4726  %val = cmpxchg volatile i32* %gep, i32 %old, i32 %in syncscope("workgroup-one-as") acquire monotonic
4727  ret void
4728}
4729
4730define amdgpu_kernel void @flat_workgroup_one_as_release_monotonic_cmpxchg(
4731; GFX7-LABEL: flat_workgroup_one_as_release_monotonic_cmpxchg:
4732; GFX7:       ; %bb.0: ; %entry
4733; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4734; GFX7-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x2
4735; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
4736; GFX7-NEXT:    s_add_u32 s0, s0, 16
4737; GFX7-NEXT:    s_addc_u32 s1, s1, 0
4738; GFX7-NEXT:    v_mov_b32_e32 v0, s0
4739; GFX7-NEXT:    v_mov_b32_e32 v2, s2
4740; GFX7-NEXT:    v_mov_b32_e32 v1, s1
4741; GFX7-NEXT:    v_mov_b32_e32 v3, s3
4742; GFX7-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
4743; GFX7-NEXT:    s_endpgm
4744;
4745; GFX10-WGP-LABEL: flat_workgroup_one_as_release_monotonic_cmpxchg:
4746; GFX10-WGP:       ; %bb.0: ; %entry
4747; GFX10-WGP-NEXT:    s_clause 0x1
4748; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4749; GFX10-WGP-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
4750; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
4751; GFX10-WGP-NEXT:    s_add_u32 s0, s0, 16
4752; GFX10-WGP-NEXT:    s_addc_u32 s1, s1, 0
4753; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
4754; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
4755; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
4756; GFX10-WGP-NEXT:    v_mov_b32_e32 v3, s3
4757; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0)
4758; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
4759; GFX10-WGP-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
4760; GFX10-WGP-NEXT:    s_endpgm
4761;
4762; GFX10-CU-LABEL: flat_workgroup_one_as_release_monotonic_cmpxchg:
4763; GFX10-CU:       ; %bb.0: ; %entry
4764; GFX10-CU-NEXT:    s_clause 0x1
4765; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4766; GFX10-CU-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
4767; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
4768; GFX10-CU-NEXT:    s_add_u32 s0, s0, 16
4769; GFX10-CU-NEXT:    s_addc_u32 s1, s1, 0
4770; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
4771; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
4772; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
4773; GFX10-CU-NEXT:    v_mov_b32_e32 v3, s3
4774; GFX10-CU-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
4775; GFX10-CU-NEXT:    s_endpgm
4776;
4777; SKIP-CACHE-INV-LABEL: flat_workgroup_one_as_release_monotonic_cmpxchg:
4778; SKIP-CACHE-INV:       ; %bb.0: ; %entry
4779; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
4780; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
4781; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
4782; SKIP-CACHE-INV-NEXT:    s_add_u32 s2, s2, 16
4783; SKIP-CACHE-INV-NEXT:    s_addc_u32 s3, s3, 0
4784; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
4785; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s1
4786; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
4787; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
4788; SKIP-CACHE-INV-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
4789; SKIP-CACHE-INV-NEXT:    s_endpgm
4790;
4791; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_one_as_release_monotonic_cmpxchg:
4792; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
4793; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4794; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
4795; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
4796; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
4797; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
4798; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
4799; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
4800;
4801; GFX90A-TGSPLIT-LABEL: flat_workgroup_one_as_release_monotonic_cmpxchg:
4802; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
4803; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4804; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
4805; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
4806; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
4807; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
4808; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
4809; GFX90A-TGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
4810; GFX90A-TGSPLIT-NEXT:    s_endpgm
4811    i32* %out, i32 %in, i32 %old) {
4812entry:
4813  %gep = getelementptr i32, i32* %out, i32 4
4814  %val = cmpxchg volatile i32* %gep, i32 %old, i32 %in syncscope("workgroup-one-as") release monotonic
4815  ret void
4816}
4817
4818define amdgpu_kernel void @flat_workgroup_one_as_acq_rel_monotonic_cmpxchg(
4819; GFX7-LABEL: flat_workgroup_one_as_acq_rel_monotonic_cmpxchg:
4820; GFX7:       ; %bb.0: ; %entry
4821; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4822; GFX7-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x2
4823; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
4824; GFX7-NEXT:    s_add_u32 s0, s0, 16
4825; GFX7-NEXT:    s_addc_u32 s1, s1, 0
4826; GFX7-NEXT:    v_mov_b32_e32 v0, s0
4827; GFX7-NEXT:    v_mov_b32_e32 v2, s2
4828; GFX7-NEXT:    v_mov_b32_e32 v1, s1
4829; GFX7-NEXT:    v_mov_b32_e32 v3, s3
4830; GFX7-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
4831; GFX7-NEXT:    s_endpgm
4832;
4833; GFX10-WGP-LABEL: flat_workgroup_one_as_acq_rel_monotonic_cmpxchg:
4834; GFX10-WGP:       ; %bb.0: ; %entry
4835; GFX10-WGP-NEXT:    s_clause 0x1
4836; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4837; GFX10-WGP-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
4838; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
4839; GFX10-WGP-NEXT:    s_add_u32 s0, s0, 16
4840; GFX10-WGP-NEXT:    s_addc_u32 s1, s1, 0
4841; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
4842; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
4843; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
4844; GFX10-WGP-NEXT:    v_mov_b32_e32 v3, s3
4845; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0)
4846; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
4847; GFX10-WGP-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
4848; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
4849; GFX10-WGP-NEXT:    buffer_gl0_inv
4850; GFX10-WGP-NEXT:    s_endpgm
4851;
4852; GFX10-CU-LABEL: flat_workgroup_one_as_acq_rel_monotonic_cmpxchg:
4853; GFX10-CU:       ; %bb.0: ; %entry
4854; GFX10-CU-NEXT:    s_clause 0x1
4855; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4856; GFX10-CU-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
4857; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
4858; GFX10-CU-NEXT:    s_add_u32 s0, s0, 16
4859; GFX10-CU-NEXT:    s_addc_u32 s1, s1, 0
4860; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
4861; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
4862; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
4863; GFX10-CU-NEXT:    v_mov_b32_e32 v3, s3
4864; GFX10-CU-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
4865; GFX10-CU-NEXT:    s_endpgm
4866;
4867; SKIP-CACHE-INV-LABEL: flat_workgroup_one_as_acq_rel_monotonic_cmpxchg:
4868; SKIP-CACHE-INV:       ; %bb.0: ; %entry
4869; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
4870; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
4871; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
4872; SKIP-CACHE-INV-NEXT:    s_add_u32 s2, s2, 16
4873; SKIP-CACHE-INV-NEXT:    s_addc_u32 s3, s3, 0
4874; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
4875; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s1
4876; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
4877; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
4878; SKIP-CACHE-INV-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
4879; SKIP-CACHE-INV-NEXT:    s_endpgm
4880;
4881; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_one_as_acq_rel_monotonic_cmpxchg:
4882; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
4883; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4884; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
4885; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
4886; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
4887; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
4888; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
4889; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
4890;
4891; GFX90A-TGSPLIT-LABEL: flat_workgroup_one_as_acq_rel_monotonic_cmpxchg:
4892; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
4893; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4894; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
4895; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
4896; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
4897; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
4898; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
4899; GFX90A-TGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
4900; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
4901; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
4902; GFX90A-TGSPLIT-NEXT:    s_endpgm
4903    i32* %out, i32 %in, i32 %old) {
4904entry:
4905  %gep = getelementptr i32, i32* %out, i32 4
4906  %val = cmpxchg volatile i32* %gep, i32 %old, i32 %in syncscope("workgroup-one-as") acq_rel monotonic
4907  ret void
4908}
4909
4910define amdgpu_kernel void @flat_workgroup_one_as_seq_cst_monotonic_cmpxchg(
4911; GFX7-LABEL: flat_workgroup_one_as_seq_cst_monotonic_cmpxchg:
4912; GFX7:       ; %bb.0: ; %entry
4913; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4914; GFX7-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x2
4915; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
4916; GFX7-NEXT:    s_add_u32 s0, s0, 16
4917; GFX7-NEXT:    s_addc_u32 s1, s1, 0
4918; GFX7-NEXT:    v_mov_b32_e32 v0, s0
4919; GFX7-NEXT:    v_mov_b32_e32 v2, s2
4920; GFX7-NEXT:    v_mov_b32_e32 v1, s1
4921; GFX7-NEXT:    v_mov_b32_e32 v3, s3
4922; GFX7-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
4923; GFX7-NEXT:    s_endpgm
4924;
4925; GFX10-WGP-LABEL: flat_workgroup_one_as_seq_cst_monotonic_cmpxchg:
4926; GFX10-WGP:       ; %bb.0: ; %entry
4927; GFX10-WGP-NEXT:    s_clause 0x1
4928; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4929; GFX10-WGP-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
4930; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
4931; GFX10-WGP-NEXT:    s_add_u32 s0, s0, 16
4932; GFX10-WGP-NEXT:    s_addc_u32 s1, s1, 0
4933; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
4934; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
4935; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
4936; GFX10-WGP-NEXT:    v_mov_b32_e32 v3, s3
4937; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0)
4938; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
4939; GFX10-WGP-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
4940; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
4941; GFX10-WGP-NEXT:    buffer_gl0_inv
4942; GFX10-WGP-NEXT:    s_endpgm
4943;
4944; GFX10-CU-LABEL: flat_workgroup_one_as_seq_cst_monotonic_cmpxchg:
4945; GFX10-CU:       ; %bb.0: ; %entry
4946; GFX10-CU-NEXT:    s_clause 0x1
4947; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4948; GFX10-CU-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
4949; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
4950; GFX10-CU-NEXT:    s_add_u32 s0, s0, 16
4951; GFX10-CU-NEXT:    s_addc_u32 s1, s1, 0
4952; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
4953; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
4954; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
4955; GFX10-CU-NEXT:    v_mov_b32_e32 v3, s3
4956; GFX10-CU-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
4957; GFX10-CU-NEXT:    s_endpgm
4958;
4959; SKIP-CACHE-INV-LABEL: flat_workgroup_one_as_seq_cst_monotonic_cmpxchg:
4960; SKIP-CACHE-INV:       ; %bb.0: ; %entry
4961; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
4962; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
4963; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
4964; SKIP-CACHE-INV-NEXT:    s_add_u32 s2, s2, 16
4965; SKIP-CACHE-INV-NEXT:    s_addc_u32 s3, s3, 0
4966; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
4967; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s1
4968; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
4969; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
4970; SKIP-CACHE-INV-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
4971; SKIP-CACHE-INV-NEXT:    s_endpgm
4972;
4973; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_one_as_seq_cst_monotonic_cmpxchg:
4974; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
4975; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4976; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
4977; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
4978; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
4979; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
4980; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
4981; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
4982;
4983; GFX90A-TGSPLIT-LABEL: flat_workgroup_one_as_seq_cst_monotonic_cmpxchg:
4984; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
4985; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
4986; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
4987; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
4988; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
4989; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
4990; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
4991; GFX90A-TGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
4992; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
4993; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
4994; GFX90A-TGSPLIT-NEXT:    s_endpgm
4995    i32* %out, i32 %in, i32 %old) {
4996entry:
4997  %gep = getelementptr i32, i32* %out, i32 4
4998  %val = cmpxchg volatile i32* %gep, i32 %old, i32 %in syncscope("workgroup-one-as") seq_cst monotonic
4999  ret void
5000}
5001
5002define amdgpu_kernel void @flat_workgroup_one_as_acquire_acquire_cmpxchg(
5003; GFX7-LABEL: flat_workgroup_one_as_acquire_acquire_cmpxchg:
5004; GFX7:       ; %bb.0: ; %entry
5005; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5006; GFX7-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x2
5007; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
5008; GFX7-NEXT:    s_add_u32 s0, s0, 16
5009; GFX7-NEXT:    s_addc_u32 s1, s1, 0
5010; GFX7-NEXT:    v_mov_b32_e32 v0, s0
5011; GFX7-NEXT:    v_mov_b32_e32 v2, s2
5012; GFX7-NEXT:    v_mov_b32_e32 v1, s1
5013; GFX7-NEXT:    v_mov_b32_e32 v3, s3
5014; GFX7-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
5015; GFX7-NEXT:    s_endpgm
5016;
5017; GFX10-WGP-LABEL: flat_workgroup_one_as_acquire_acquire_cmpxchg:
5018; GFX10-WGP:       ; %bb.0: ; %entry
5019; GFX10-WGP-NEXT:    s_clause 0x1
5020; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5021; GFX10-WGP-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
5022; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
5023; GFX10-WGP-NEXT:    s_add_u32 s0, s0, 16
5024; GFX10-WGP-NEXT:    s_addc_u32 s1, s1, 0
5025; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
5026; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
5027; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
5028; GFX10-WGP-NEXT:    v_mov_b32_e32 v3, s3
5029; GFX10-WGP-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
5030; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
5031; GFX10-WGP-NEXT:    buffer_gl0_inv
5032; GFX10-WGP-NEXT:    s_endpgm
5033;
5034; GFX10-CU-LABEL: flat_workgroup_one_as_acquire_acquire_cmpxchg:
5035; GFX10-CU:       ; %bb.0: ; %entry
5036; GFX10-CU-NEXT:    s_clause 0x1
5037; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5038; GFX10-CU-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
5039; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
5040; GFX10-CU-NEXT:    s_add_u32 s0, s0, 16
5041; GFX10-CU-NEXT:    s_addc_u32 s1, s1, 0
5042; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
5043; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
5044; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
5045; GFX10-CU-NEXT:    v_mov_b32_e32 v3, s3
5046; GFX10-CU-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
5047; GFX10-CU-NEXT:    s_endpgm
5048;
5049; SKIP-CACHE-INV-LABEL: flat_workgroup_one_as_acquire_acquire_cmpxchg:
5050; SKIP-CACHE-INV:       ; %bb.0: ; %entry
5051; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
5052; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
5053; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
5054; SKIP-CACHE-INV-NEXT:    s_add_u32 s2, s2, 16
5055; SKIP-CACHE-INV-NEXT:    s_addc_u32 s3, s3, 0
5056; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
5057; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s1
5058; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
5059; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
5060; SKIP-CACHE-INV-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
5061; SKIP-CACHE-INV-NEXT:    s_endpgm
5062;
5063; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_one_as_acquire_acquire_cmpxchg:
5064; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
5065; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5066; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
5067; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
5068; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
5069; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
5070; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
5071; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
5072;
5073; GFX90A-TGSPLIT-LABEL: flat_workgroup_one_as_acquire_acquire_cmpxchg:
5074; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
5075; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5076; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
5077; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
5078; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
5079; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
5080; GFX90A-TGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
5081; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
5082; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
5083; GFX90A-TGSPLIT-NEXT:    s_endpgm
5084    i32* %out, i32 %in, i32 %old) {
5085entry:
5086  %gep = getelementptr i32, i32* %out, i32 4
5087  %val = cmpxchg volatile i32* %gep, i32 %old, i32 %in syncscope("workgroup-one-as") acquire acquire
5088  ret void
5089}
5090
5091define amdgpu_kernel void @flat_workgroup_one_as_release_acquire_cmpxchg(
5092; GFX7-LABEL: flat_workgroup_one_as_release_acquire_cmpxchg:
5093; GFX7:       ; %bb.0: ; %entry
5094; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5095; GFX7-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x2
5096; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
5097; GFX7-NEXT:    s_add_u32 s0, s0, 16
5098; GFX7-NEXT:    s_addc_u32 s1, s1, 0
5099; GFX7-NEXT:    v_mov_b32_e32 v0, s0
5100; GFX7-NEXT:    v_mov_b32_e32 v2, s2
5101; GFX7-NEXT:    v_mov_b32_e32 v1, s1
5102; GFX7-NEXT:    v_mov_b32_e32 v3, s3
5103; GFX7-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
5104; GFX7-NEXT:    s_endpgm
5105;
5106; GFX10-WGP-LABEL: flat_workgroup_one_as_release_acquire_cmpxchg:
5107; GFX10-WGP:       ; %bb.0: ; %entry
5108; GFX10-WGP-NEXT:    s_clause 0x1
5109; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5110; GFX10-WGP-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
5111; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
5112; GFX10-WGP-NEXT:    s_add_u32 s0, s0, 16
5113; GFX10-WGP-NEXT:    s_addc_u32 s1, s1, 0
5114; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
5115; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
5116; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
5117; GFX10-WGP-NEXT:    v_mov_b32_e32 v3, s3
5118; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0)
5119; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
5120; GFX10-WGP-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
5121; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
5122; GFX10-WGP-NEXT:    buffer_gl0_inv
5123; GFX10-WGP-NEXT:    s_endpgm
5124;
5125; GFX10-CU-LABEL: flat_workgroup_one_as_release_acquire_cmpxchg:
5126; GFX10-CU:       ; %bb.0: ; %entry
5127; GFX10-CU-NEXT:    s_clause 0x1
5128; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5129; GFX10-CU-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
5130; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
5131; GFX10-CU-NEXT:    s_add_u32 s0, s0, 16
5132; GFX10-CU-NEXT:    s_addc_u32 s1, s1, 0
5133; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
5134; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
5135; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
5136; GFX10-CU-NEXT:    v_mov_b32_e32 v3, s3
5137; GFX10-CU-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
5138; GFX10-CU-NEXT:    s_endpgm
5139;
5140; SKIP-CACHE-INV-LABEL: flat_workgroup_one_as_release_acquire_cmpxchg:
5141; SKIP-CACHE-INV:       ; %bb.0: ; %entry
5142; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
5143; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
5144; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
5145; SKIP-CACHE-INV-NEXT:    s_add_u32 s2, s2, 16
5146; SKIP-CACHE-INV-NEXT:    s_addc_u32 s3, s3, 0
5147; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
5148; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s1
5149; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
5150; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
5151; SKIP-CACHE-INV-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
5152; SKIP-CACHE-INV-NEXT:    s_endpgm
5153;
5154; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_one_as_release_acquire_cmpxchg:
5155; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
5156; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5157; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
5158; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
5159; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
5160; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
5161; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
5162; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
5163;
5164; GFX90A-TGSPLIT-LABEL: flat_workgroup_one_as_release_acquire_cmpxchg:
5165; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
5166; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5167; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
5168; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
5169; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
5170; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
5171; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
5172; GFX90A-TGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
5173; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
5174; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
5175; GFX90A-TGSPLIT-NEXT:    s_endpgm
5176    i32* %out, i32 %in, i32 %old) {
5177entry:
5178  %gep = getelementptr i32, i32* %out, i32 4
5179  %val = cmpxchg volatile i32* %gep, i32 %old, i32 %in syncscope("workgroup-one-as") release acquire
5180  ret void
5181}
5182
5183define amdgpu_kernel void @flat_workgroup_one_as_acq_rel_acquire_cmpxchg(
5184; GFX7-LABEL: flat_workgroup_one_as_acq_rel_acquire_cmpxchg:
5185; GFX7:       ; %bb.0: ; %entry
5186; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5187; GFX7-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x2
5188; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
5189; GFX7-NEXT:    s_add_u32 s0, s0, 16
5190; GFX7-NEXT:    s_addc_u32 s1, s1, 0
5191; GFX7-NEXT:    v_mov_b32_e32 v0, s0
5192; GFX7-NEXT:    v_mov_b32_e32 v2, s2
5193; GFX7-NEXT:    v_mov_b32_e32 v1, s1
5194; GFX7-NEXT:    v_mov_b32_e32 v3, s3
5195; GFX7-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
5196; GFX7-NEXT:    s_endpgm
5197;
5198; GFX10-WGP-LABEL: flat_workgroup_one_as_acq_rel_acquire_cmpxchg:
5199; GFX10-WGP:       ; %bb.0: ; %entry
5200; GFX10-WGP-NEXT:    s_clause 0x1
5201; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5202; GFX10-WGP-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
5203; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
5204; GFX10-WGP-NEXT:    s_add_u32 s0, s0, 16
5205; GFX10-WGP-NEXT:    s_addc_u32 s1, s1, 0
5206; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
5207; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
5208; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
5209; GFX10-WGP-NEXT:    v_mov_b32_e32 v3, s3
5210; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0)
5211; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
5212; GFX10-WGP-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
5213; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
5214; GFX10-WGP-NEXT:    buffer_gl0_inv
5215; GFX10-WGP-NEXT:    s_endpgm
5216;
5217; GFX10-CU-LABEL: flat_workgroup_one_as_acq_rel_acquire_cmpxchg:
5218; GFX10-CU:       ; %bb.0: ; %entry
5219; GFX10-CU-NEXT:    s_clause 0x1
5220; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5221; GFX10-CU-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
5222; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
5223; GFX10-CU-NEXT:    s_add_u32 s0, s0, 16
5224; GFX10-CU-NEXT:    s_addc_u32 s1, s1, 0
5225; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
5226; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
5227; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
5228; GFX10-CU-NEXT:    v_mov_b32_e32 v3, s3
5229; GFX10-CU-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
5230; GFX10-CU-NEXT:    s_endpgm
5231;
5232; SKIP-CACHE-INV-LABEL: flat_workgroup_one_as_acq_rel_acquire_cmpxchg:
5233; SKIP-CACHE-INV:       ; %bb.0: ; %entry
5234; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
5235; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
5236; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
5237; SKIP-CACHE-INV-NEXT:    s_add_u32 s2, s2, 16
5238; SKIP-CACHE-INV-NEXT:    s_addc_u32 s3, s3, 0
5239; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
5240; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s1
5241; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
5242; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
5243; SKIP-CACHE-INV-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
5244; SKIP-CACHE-INV-NEXT:    s_endpgm
5245;
5246; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_one_as_acq_rel_acquire_cmpxchg:
5247; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
5248; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5249; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
5250; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
5251; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
5252; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
5253; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
5254; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
5255;
5256; GFX90A-TGSPLIT-LABEL: flat_workgroup_one_as_acq_rel_acquire_cmpxchg:
5257; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
5258; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5259; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
5260; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
5261; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
5262; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
5263; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
5264; GFX90A-TGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
5265; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
5266; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
5267; GFX90A-TGSPLIT-NEXT:    s_endpgm
5268    i32* %out, i32 %in, i32 %old) {
5269entry:
5270  %gep = getelementptr i32, i32* %out, i32 4
5271  %val = cmpxchg volatile i32* %gep, i32 %old, i32 %in syncscope("workgroup-one-as") acq_rel acquire
5272  ret void
5273}
5274
5275define amdgpu_kernel void @flat_workgroup_one_as_seq_cst_acquire_cmpxchg(
5276; GFX7-LABEL: flat_workgroup_one_as_seq_cst_acquire_cmpxchg:
5277; GFX7:       ; %bb.0: ; %entry
5278; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5279; GFX7-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x2
5280; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
5281; GFX7-NEXT:    s_add_u32 s0, s0, 16
5282; GFX7-NEXT:    s_addc_u32 s1, s1, 0
5283; GFX7-NEXT:    v_mov_b32_e32 v0, s0
5284; GFX7-NEXT:    v_mov_b32_e32 v2, s2
5285; GFX7-NEXT:    v_mov_b32_e32 v1, s1
5286; GFX7-NEXT:    v_mov_b32_e32 v3, s3
5287; GFX7-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
5288; GFX7-NEXT:    s_endpgm
5289;
5290; GFX10-WGP-LABEL: flat_workgroup_one_as_seq_cst_acquire_cmpxchg:
5291; GFX10-WGP:       ; %bb.0: ; %entry
5292; GFX10-WGP-NEXT:    s_clause 0x1
5293; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5294; GFX10-WGP-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
5295; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
5296; GFX10-WGP-NEXT:    s_add_u32 s0, s0, 16
5297; GFX10-WGP-NEXT:    s_addc_u32 s1, s1, 0
5298; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
5299; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
5300; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
5301; GFX10-WGP-NEXT:    v_mov_b32_e32 v3, s3
5302; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0)
5303; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
5304; GFX10-WGP-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
5305; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
5306; GFX10-WGP-NEXT:    buffer_gl0_inv
5307; GFX10-WGP-NEXT:    s_endpgm
5308;
5309; GFX10-CU-LABEL: flat_workgroup_one_as_seq_cst_acquire_cmpxchg:
5310; GFX10-CU:       ; %bb.0: ; %entry
5311; GFX10-CU-NEXT:    s_clause 0x1
5312; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5313; GFX10-CU-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
5314; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
5315; GFX10-CU-NEXT:    s_add_u32 s0, s0, 16
5316; GFX10-CU-NEXT:    s_addc_u32 s1, s1, 0
5317; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
5318; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
5319; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
5320; GFX10-CU-NEXT:    v_mov_b32_e32 v3, s3
5321; GFX10-CU-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
5322; GFX10-CU-NEXT:    s_endpgm
5323;
5324; SKIP-CACHE-INV-LABEL: flat_workgroup_one_as_seq_cst_acquire_cmpxchg:
5325; SKIP-CACHE-INV:       ; %bb.0: ; %entry
5326; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
5327; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
5328; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
5329; SKIP-CACHE-INV-NEXT:    s_add_u32 s2, s2, 16
5330; SKIP-CACHE-INV-NEXT:    s_addc_u32 s3, s3, 0
5331; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
5332; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s1
5333; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
5334; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
5335; SKIP-CACHE-INV-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
5336; SKIP-CACHE-INV-NEXT:    s_endpgm
5337;
5338; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_one_as_seq_cst_acquire_cmpxchg:
5339; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
5340; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5341; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
5342; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
5343; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
5344; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
5345; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
5346; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
5347;
5348; GFX90A-TGSPLIT-LABEL: flat_workgroup_one_as_seq_cst_acquire_cmpxchg:
5349; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
5350; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5351; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
5352; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
5353; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
5354; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
5355; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
5356; GFX90A-TGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
5357; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
5358; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
5359; GFX90A-TGSPLIT-NEXT:    s_endpgm
5360    i32* %out, i32 %in, i32 %old) {
5361entry:
5362  %gep = getelementptr i32, i32* %out, i32 4
5363  %val = cmpxchg volatile i32* %gep, i32 %old, i32 %in syncscope("workgroup-one-as") seq_cst acquire
5364  ret void
5365}
5366
5367define amdgpu_kernel void @flat_workgroup_one_as_seq_cst_seq_cst_cmpxchg(
5368; GFX7-LABEL: flat_workgroup_one_as_seq_cst_seq_cst_cmpxchg:
5369; GFX7:       ; %bb.0: ; %entry
5370; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5371; GFX7-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x2
5372; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
5373; GFX7-NEXT:    s_add_u32 s0, s0, 16
5374; GFX7-NEXT:    s_addc_u32 s1, s1, 0
5375; GFX7-NEXT:    v_mov_b32_e32 v0, s0
5376; GFX7-NEXT:    v_mov_b32_e32 v2, s2
5377; GFX7-NEXT:    v_mov_b32_e32 v1, s1
5378; GFX7-NEXT:    v_mov_b32_e32 v3, s3
5379; GFX7-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
5380; GFX7-NEXT:    s_endpgm
5381;
5382; GFX10-WGP-LABEL: flat_workgroup_one_as_seq_cst_seq_cst_cmpxchg:
5383; GFX10-WGP:       ; %bb.0: ; %entry
5384; GFX10-WGP-NEXT:    s_clause 0x1
5385; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5386; GFX10-WGP-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
5387; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
5388; GFX10-WGP-NEXT:    s_add_u32 s0, s0, 16
5389; GFX10-WGP-NEXT:    s_addc_u32 s1, s1, 0
5390; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
5391; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
5392; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
5393; GFX10-WGP-NEXT:    v_mov_b32_e32 v3, s3
5394; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0)
5395; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
5396; GFX10-WGP-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
5397; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
5398; GFX10-WGP-NEXT:    buffer_gl0_inv
5399; GFX10-WGP-NEXT:    s_endpgm
5400;
5401; GFX10-CU-LABEL: flat_workgroup_one_as_seq_cst_seq_cst_cmpxchg:
5402; GFX10-CU:       ; %bb.0: ; %entry
5403; GFX10-CU-NEXT:    s_clause 0x1
5404; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5405; GFX10-CU-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
5406; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
5407; GFX10-CU-NEXT:    s_add_u32 s0, s0, 16
5408; GFX10-CU-NEXT:    s_addc_u32 s1, s1, 0
5409; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
5410; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
5411; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
5412; GFX10-CU-NEXT:    v_mov_b32_e32 v3, s3
5413; GFX10-CU-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
5414; GFX10-CU-NEXT:    s_endpgm
5415;
5416; SKIP-CACHE-INV-LABEL: flat_workgroup_one_as_seq_cst_seq_cst_cmpxchg:
5417; SKIP-CACHE-INV:       ; %bb.0: ; %entry
5418; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
5419; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
5420; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
5421; SKIP-CACHE-INV-NEXT:    s_add_u32 s2, s2, 16
5422; SKIP-CACHE-INV-NEXT:    s_addc_u32 s3, s3, 0
5423; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
5424; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s1
5425; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
5426; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
5427; SKIP-CACHE-INV-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3]
5428; SKIP-CACHE-INV-NEXT:    s_endpgm
5429;
5430; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_one_as_seq_cst_seq_cst_cmpxchg:
5431; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
5432; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5433; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
5434; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
5435; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
5436; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
5437; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
5438; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
5439;
5440; GFX90A-TGSPLIT-LABEL: flat_workgroup_one_as_seq_cst_seq_cst_cmpxchg:
5441; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
5442; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5443; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
5444; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
5445; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
5446; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
5447; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
5448; GFX90A-TGSPLIT-NEXT:    flat_atomic_cmpswap v[0:1], v[2:3] offset:16
5449; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
5450; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
5451; GFX90A-TGSPLIT-NEXT:    s_endpgm
5452    i32* %out, i32 %in, i32 %old) {
5453entry:
5454  %gep = getelementptr i32, i32* %out, i32 4
5455  %val = cmpxchg volatile i32* %gep, i32 %old, i32 %in syncscope("workgroup-one-as") seq_cst seq_cst
5456  ret void
5457}
5458
5459define amdgpu_kernel void @flat_workgroup_one_as_acquire_monotonic_ret_cmpxchg(
5460; GFX7-LABEL: flat_workgroup_one_as_acquire_monotonic_ret_cmpxchg:
5461; GFX7:       ; %bb.0: ; %entry
5462; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5463; GFX7-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x2
5464; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
5465; GFX7-NEXT:    s_add_u32 s4, s0, 16
5466; GFX7-NEXT:    s_addc_u32 s5, s1, 0
5467; GFX7-NEXT:    v_mov_b32_e32 v0, s4
5468; GFX7-NEXT:    v_mov_b32_e32 v2, s2
5469; GFX7-NEXT:    v_mov_b32_e32 v1, s5
5470; GFX7-NEXT:    v_mov_b32_e32 v3, s3
5471; GFX7-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
5472; GFX7-NEXT:    v_mov_b32_e32 v0, s0
5473; GFX7-NEXT:    v_mov_b32_e32 v1, s1
5474; GFX7-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
5475; GFX7-NEXT:    flat_store_dword v[0:1], v2
5476; GFX7-NEXT:    s_endpgm
5477;
5478; GFX10-WGP-LABEL: flat_workgroup_one_as_acquire_monotonic_ret_cmpxchg:
5479; GFX10-WGP:       ; %bb.0: ; %entry
5480; GFX10-WGP-NEXT:    s_clause 0x1
5481; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5482; GFX10-WGP-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
5483; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
5484; GFX10-WGP-NEXT:    s_add_u32 s4, s0, 16
5485; GFX10-WGP-NEXT:    s_addc_u32 s5, s1, 0
5486; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s4
5487; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
5488; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s5
5489; GFX10-WGP-NEXT:    v_mov_b32_e32 v3, s3
5490; GFX10-WGP-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
5491; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0)
5492; GFX10-WGP-NEXT:    buffer_gl0_inv
5493; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
5494; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
5495; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
5496; GFX10-WGP-NEXT:    flat_store_dword v[0:1], v2
5497; GFX10-WGP-NEXT:    s_endpgm
5498;
5499; GFX10-CU-LABEL: flat_workgroup_one_as_acquire_monotonic_ret_cmpxchg:
5500; GFX10-CU:       ; %bb.0: ; %entry
5501; GFX10-CU-NEXT:    s_clause 0x1
5502; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5503; GFX10-CU-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
5504; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
5505; GFX10-CU-NEXT:    s_add_u32 s4, s0, 16
5506; GFX10-CU-NEXT:    s_addc_u32 s5, s1, 0
5507; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s4
5508; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
5509; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s5
5510; GFX10-CU-NEXT:    v_mov_b32_e32 v3, s3
5511; GFX10-CU-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
5512; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
5513; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
5514; GFX10-CU-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
5515; GFX10-CU-NEXT:    flat_store_dword v[0:1], v2
5516; GFX10-CU-NEXT:    s_endpgm
5517;
5518; SKIP-CACHE-INV-LABEL: flat_workgroup_one_as_acquire_monotonic_ret_cmpxchg:
5519; SKIP-CACHE-INV:       ; %bb.0: ; %entry
5520; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
5521; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
5522; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
5523; SKIP-CACHE-INV-NEXT:    s_add_u32 s4, s2, 16
5524; SKIP-CACHE-INV-NEXT:    s_addc_u32 s5, s3, 0
5525; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s4
5526; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s1
5527; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s5
5528; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
5529; SKIP-CACHE-INV-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
5530; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
5531; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
5532; SKIP-CACHE-INV-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
5533; SKIP-CACHE-INV-NEXT:    flat_store_dword v[0:1], v2
5534; SKIP-CACHE-INV-NEXT:    s_endpgm
5535;
5536; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_one_as_acquire_monotonic_ret_cmpxchg:
5537; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
5538; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5539; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
5540; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
5541; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
5542; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
5543; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] offset:16 glc
5544; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
5545; GFX90A-NOTTGSPLIT-NEXT:    flat_store_dword v[0:1], v2
5546; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
5547;
5548; GFX90A-TGSPLIT-LABEL: flat_workgroup_one_as_acquire_monotonic_ret_cmpxchg:
5549; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
5550; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5551; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
5552; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
5553; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
5554; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
5555; GFX90A-TGSPLIT-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] offset:16 glc
5556; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
5557; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
5558; GFX90A-TGSPLIT-NEXT:    flat_store_dword v[0:1], v2
5559; GFX90A-TGSPLIT-NEXT:    s_endpgm
5560    i32* %out, i32 %in, i32 %old) {
5561entry:
5562  %gep = getelementptr i32, i32* %out, i32 4
5563  %val = cmpxchg volatile i32* %gep, i32 %old, i32 %in syncscope("workgroup-one-as") acquire monotonic
5564  %val0 = extractvalue { i32, i1 } %val, 0
5565  store i32 %val0, i32* %out, align 4
5566  ret void
5567}
5568
5569define amdgpu_kernel void @flat_workgroup_one_as_acq_rel_monotonic_ret_cmpxchg(
5570; GFX7-LABEL: flat_workgroup_one_as_acq_rel_monotonic_ret_cmpxchg:
5571; GFX7:       ; %bb.0: ; %entry
5572; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5573; GFX7-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x2
5574; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
5575; GFX7-NEXT:    s_add_u32 s4, s0, 16
5576; GFX7-NEXT:    s_addc_u32 s5, s1, 0
5577; GFX7-NEXT:    v_mov_b32_e32 v0, s4
5578; GFX7-NEXT:    v_mov_b32_e32 v2, s2
5579; GFX7-NEXT:    v_mov_b32_e32 v1, s5
5580; GFX7-NEXT:    v_mov_b32_e32 v3, s3
5581; GFX7-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
5582; GFX7-NEXT:    v_mov_b32_e32 v0, s0
5583; GFX7-NEXT:    v_mov_b32_e32 v1, s1
5584; GFX7-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
5585; GFX7-NEXT:    flat_store_dword v[0:1], v2
5586; GFX7-NEXT:    s_endpgm
5587;
5588; GFX10-WGP-LABEL: flat_workgroup_one_as_acq_rel_monotonic_ret_cmpxchg:
5589; GFX10-WGP:       ; %bb.0: ; %entry
5590; GFX10-WGP-NEXT:    s_clause 0x1
5591; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5592; GFX10-WGP-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
5593; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
5594; GFX10-WGP-NEXT:    s_add_u32 s4, s0, 16
5595; GFX10-WGP-NEXT:    s_addc_u32 s5, s1, 0
5596; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s4
5597; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
5598; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s5
5599; GFX10-WGP-NEXT:    v_mov_b32_e32 v3, s3
5600; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0)
5601; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
5602; GFX10-WGP-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
5603; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0)
5604; GFX10-WGP-NEXT:    buffer_gl0_inv
5605; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
5606; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
5607; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
5608; GFX10-WGP-NEXT:    flat_store_dword v[0:1], v2
5609; GFX10-WGP-NEXT:    s_endpgm
5610;
5611; GFX10-CU-LABEL: flat_workgroup_one_as_acq_rel_monotonic_ret_cmpxchg:
5612; GFX10-CU:       ; %bb.0: ; %entry
5613; GFX10-CU-NEXT:    s_clause 0x1
5614; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5615; GFX10-CU-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
5616; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
5617; GFX10-CU-NEXT:    s_add_u32 s4, s0, 16
5618; GFX10-CU-NEXT:    s_addc_u32 s5, s1, 0
5619; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s4
5620; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
5621; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s5
5622; GFX10-CU-NEXT:    v_mov_b32_e32 v3, s3
5623; GFX10-CU-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
5624; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
5625; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
5626; GFX10-CU-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
5627; GFX10-CU-NEXT:    flat_store_dword v[0:1], v2
5628; GFX10-CU-NEXT:    s_endpgm
5629;
5630; SKIP-CACHE-INV-LABEL: flat_workgroup_one_as_acq_rel_monotonic_ret_cmpxchg:
5631; SKIP-CACHE-INV:       ; %bb.0: ; %entry
5632; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
5633; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
5634; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
5635; SKIP-CACHE-INV-NEXT:    s_add_u32 s4, s2, 16
5636; SKIP-CACHE-INV-NEXT:    s_addc_u32 s5, s3, 0
5637; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s4
5638; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s1
5639; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s5
5640; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
5641; SKIP-CACHE-INV-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
5642; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
5643; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
5644; SKIP-CACHE-INV-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
5645; SKIP-CACHE-INV-NEXT:    flat_store_dword v[0:1], v2
5646; SKIP-CACHE-INV-NEXT:    s_endpgm
5647;
5648; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_one_as_acq_rel_monotonic_ret_cmpxchg:
5649; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
5650; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5651; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
5652; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
5653; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
5654; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
5655; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] offset:16 glc
5656; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
5657; GFX90A-NOTTGSPLIT-NEXT:    flat_store_dword v[0:1], v2
5658; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
5659;
5660; GFX90A-TGSPLIT-LABEL: flat_workgroup_one_as_acq_rel_monotonic_ret_cmpxchg:
5661; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
5662; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5663; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
5664; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
5665; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
5666; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
5667; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
5668; GFX90A-TGSPLIT-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] offset:16 glc
5669; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
5670; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
5671; GFX90A-TGSPLIT-NEXT:    flat_store_dword v[0:1], v2
5672; GFX90A-TGSPLIT-NEXT:    s_endpgm
5673    i32* %out, i32 %in, i32 %old) {
5674entry:
5675  %gep = getelementptr i32, i32* %out, i32 4
5676  %val = cmpxchg volatile i32* %gep, i32 %old, i32 %in syncscope("workgroup-one-as") acq_rel monotonic
5677  %val0 = extractvalue { i32, i1 } %val, 0
5678  store i32 %val0, i32* %out, align 4
5679  ret void
5680}
5681
5682define amdgpu_kernel void @flat_workgroup_one_as_seq_cst_monotonic_ret_cmpxchg(
5683; GFX7-LABEL: flat_workgroup_one_as_seq_cst_monotonic_ret_cmpxchg:
5684; GFX7:       ; %bb.0: ; %entry
5685; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5686; GFX7-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x2
5687; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
5688; GFX7-NEXT:    s_add_u32 s4, s0, 16
5689; GFX7-NEXT:    s_addc_u32 s5, s1, 0
5690; GFX7-NEXT:    v_mov_b32_e32 v0, s4
5691; GFX7-NEXT:    v_mov_b32_e32 v2, s2
5692; GFX7-NEXT:    v_mov_b32_e32 v1, s5
5693; GFX7-NEXT:    v_mov_b32_e32 v3, s3
5694; GFX7-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
5695; GFX7-NEXT:    v_mov_b32_e32 v0, s0
5696; GFX7-NEXT:    v_mov_b32_e32 v1, s1
5697; GFX7-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
5698; GFX7-NEXT:    flat_store_dword v[0:1], v2
5699; GFX7-NEXT:    s_endpgm
5700;
5701; GFX10-WGP-LABEL: flat_workgroup_one_as_seq_cst_monotonic_ret_cmpxchg:
5702; GFX10-WGP:       ; %bb.0: ; %entry
5703; GFX10-WGP-NEXT:    s_clause 0x1
5704; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5705; GFX10-WGP-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
5706; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
5707; GFX10-WGP-NEXT:    s_add_u32 s4, s0, 16
5708; GFX10-WGP-NEXT:    s_addc_u32 s5, s1, 0
5709; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s4
5710; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
5711; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s5
5712; GFX10-WGP-NEXT:    v_mov_b32_e32 v3, s3
5713; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0)
5714; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
5715; GFX10-WGP-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
5716; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0)
5717; GFX10-WGP-NEXT:    buffer_gl0_inv
5718; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
5719; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
5720; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
5721; GFX10-WGP-NEXT:    flat_store_dword v[0:1], v2
5722; GFX10-WGP-NEXT:    s_endpgm
5723;
5724; GFX10-CU-LABEL: flat_workgroup_one_as_seq_cst_monotonic_ret_cmpxchg:
5725; GFX10-CU:       ; %bb.0: ; %entry
5726; GFX10-CU-NEXT:    s_clause 0x1
5727; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5728; GFX10-CU-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
5729; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
5730; GFX10-CU-NEXT:    s_add_u32 s4, s0, 16
5731; GFX10-CU-NEXT:    s_addc_u32 s5, s1, 0
5732; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s4
5733; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
5734; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s5
5735; GFX10-CU-NEXT:    v_mov_b32_e32 v3, s3
5736; GFX10-CU-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
5737; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
5738; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
5739; GFX10-CU-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
5740; GFX10-CU-NEXT:    flat_store_dword v[0:1], v2
5741; GFX10-CU-NEXT:    s_endpgm
5742;
5743; SKIP-CACHE-INV-LABEL: flat_workgroup_one_as_seq_cst_monotonic_ret_cmpxchg:
5744; SKIP-CACHE-INV:       ; %bb.0: ; %entry
5745; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
5746; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
5747; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
5748; SKIP-CACHE-INV-NEXT:    s_add_u32 s4, s2, 16
5749; SKIP-CACHE-INV-NEXT:    s_addc_u32 s5, s3, 0
5750; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s4
5751; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s1
5752; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s5
5753; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
5754; SKIP-CACHE-INV-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
5755; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
5756; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
5757; SKIP-CACHE-INV-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
5758; SKIP-CACHE-INV-NEXT:    flat_store_dword v[0:1], v2
5759; SKIP-CACHE-INV-NEXT:    s_endpgm
5760;
5761; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_one_as_seq_cst_monotonic_ret_cmpxchg:
5762; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
5763; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5764; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
5765; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
5766; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
5767; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
5768; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] offset:16 glc
5769; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
5770; GFX90A-NOTTGSPLIT-NEXT:    flat_store_dword v[0:1], v2
5771; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
5772;
5773; GFX90A-TGSPLIT-LABEL: flat_workgroup_one_as_seq_cst_monotonic_ret_cmpxchg:
5774; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
5775; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5776; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
5777; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
5778; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
5779; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
5780; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
5781; GFX90A-TGSPLIT-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] offset:16 glc
5782; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
5783; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
5784; GFX90A-TGSPLIT-NEXT:    flat_store_dword v[0:1], v2
5785; GFX90A-TGSPLIT-NEXT:    s_endpgm
5786    i32* %out, i32 %in, i32 %old) {
5787entry:
5788  %gep = getelementptr i32, i32* %out, i32 4
5789  %val = cmpxchg volatile i32* %gep, i32 %old, i32 %in syncscope("workgroup-one-as") seq_cst monotonic
5790  %val0 = extractvalue { i32, i1 } %val, 0
5791  store i32 %val0, i32* %out, align 4
5792  ret void
5793}
5794
5795define amdgpu_kernel void @flat_workgroup_one_as_acquire_acquire_ret_cmpxchg(
5796; GFX7-LABEL: flat_workgroup_one_as_acquire_acquire_ret_cmpxchg:
5797; GFX7:       ; %bb.0: ; %entry
5798; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5799; GFX7-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x2
5800; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
5801; GFX7-NEXT:    s_add_u32 s4, s0, 16
5802; GFX7-NEXT:    s_addc_u32 s5, s1, 0
5803; GFX7-NEXT:    v_mov_b32_e32 v0, s4
5804; GFX7-NEXT:    v_mov_b32_e32 v2, s2
5805; GFX7-NEXT:    v_mov_b32_e32 v1, s5
5806; GFX7-NEXT:    v_mov_b32_e32 v3, s3
5807; GFX7-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
5808; GFX7-NEXT:    v_mov_b32_e32 v0, s0
5809; GFX7-NEXT:    v_mov_b32_e32 v1, s1
5810; GFX7-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
5811; GFX7-NEXT:    flat_store_dword v[0:1], v2
5812; GFX7-NEXT:    s_endpgm
5813;
5814; GFX10-WGP-LABEL: flat_workgroup_one_as_acquire_acquire_ret_cmpxchg:
5815; GFX10-WGP:       ; %bb.0: ; %entry
5816; GFX10-WGP-NEXT:    s_clause 0x1
5817; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5818; GFX10-WGP-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
5819; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
5820; GFX10-WGP-NEXT:    s_add_u32 s4, s0, 16
5821; GFX10-WGP-NEXT:    s_addc_u32 s5, s1, 0
5822; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s4
5823; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
5824; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s5
5825; GFX10-WGP-NEXT:    v_mov_b32_e32 v3, s3
5826; GFX10-WGP-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
5827; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0)
5828; GFX10-WGP-NEXT:    buffer_gl0_inv
5829; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
5830; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
5831; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
5832; GFX10-WGP-NEXT:    flat_store_dword v[0:1], v2
5833; GFX10-WGP-NEXT:    s_endpgm
5834;
5835; GFX10-CU-LABEL: flat_workgroup_one_as_acquire_acquire_ret_cmpxchg:
5836; GFX10-CU:       ; %bb.0: ; %entry
5837; GFX10-CU-NEXT:    s_clause 0x1
5838; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5839; GFX10-CU-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
5840; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
5841; GFX10-CU-NEXT:    s_add_u32 s4, s0, 16
5842; GFX10-CU-NEXT:    s_addc_u32 s5, s1, 0
5843; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s4
5844; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
5845; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s5
5846; GFX10-CU-NEXT:    v_mov_b32_e32 v3, s3
5847; GFX10-CU-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
5848; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
5849; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
5850; GFX10-CU-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
5851; GFX10-CU-NEXT:    flat_store_dword v[0:1], v2
5852; GFX10-CU-NEXT:    s_endpgm
5853;
5854; SKIP-CACHE-INV-LABEL: flat_workgroup_one_as_acquire_acquire_ret_cmpxchg:
5855; SKIP-CACHE-INV:       ; %bb.0: ; %entry
5856; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
5857; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
5858; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
5859; SKIP-CACHE-INV-NEXT:    s_add_u32 s4, s2, 16
5860; SKIP-CACHE-INV-NEXT:    s_addc_u32 s5, s3, 0
5861; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s4
5862; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s1
5863; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s5
5864; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
5865; SKIP-CACHE-INV-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
5866; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
5867; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
5868; SKIP-CACHE-INV-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
5869; SKIP-CACHE-INV-NEXT:    flat_store_dword v[0:1], v2
5870; SKIP-CACHE-INV-NEXT:    s_endpgm
5871;
5872; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_one_as_acquire_acquire_ret_cmpxchg:
5873; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
5874; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5875; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
5876; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
5877; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
5878; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
5879; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] offset:16 glc
5880; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
5881; GFX90A-NOTTGSPLIT-NEXT:    flat_store_dword v[0:1], v2
5882; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
5883;
5884; GFX90A-TGSPLIT-LABEL: flat_workgroup_one_as_acquire_acquire_ret_cmpxchg:
5885; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
5886; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5887; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
5888; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
5889; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
5890; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
5891; GFX90A-TGSPLIT-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] offset:16 glc
5892; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
5893; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
5894; GFX90A-TGSPLIT-NEXT:    flat_store_dword v[0:1], v2
5895; GFX90A-TGSPLIT-NEXT:    s_endpgm
5896    i32* %out, i32 %in, i32 %old) {
5897entry:
5898  %gep = getelementptr i32, i32* %out, i32 4
5899  %val = cmpxchg volatile i32* %gep, i32 %old, i32 %in syncscope("workgroup-one-as") acquire acquire
5900  %val0 = extractvalue { i32, i1 } %val, 0
5901  store i32 %val0, i32* %out, align 4
5902  ret void
5903}
5904
5905define amdgpu_kernel void @flat_workgroup_one_as_release_acquire_ret_cmpxchg(
5906; GFX7-LABEL: flat_workgroup_one_as_release_acquire_ret_cmpxchg:
5907; GFX7:       ; %bb.0: ; %entry
5908; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5909; GFX7-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x2
5910; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
5911; GFX7-NEXT:    s_add_u32 s4, s0, 16
5912; GFX7-NEXT:    s_addc_u32 s5, s1, 0
5913; GFX7-NEXT:    v_mov_b32_e32 v0, s4
5914; GFX7-NEXT:    v_mov_b32_e32 v2, s2
5915; GFX7-NEXT:    v_mov_b32_e32 v1, s5
5916; GFX7-NEXT:    v_mov_b32_e32 v3, s3
5917; GFX7-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
5918; GFX7-NEXT:    v_mov_b32_e32 v0, s0
5919; GFX7-NEXT:    v_mov_b32_e32 v1, s1
5920; GFX7-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
5921; GFX7-NEXT:    flat_store_dword v[0:1], v2
5922; GFX7-NEXT:    s_endpgm
5923;
5924; GFX10-WGP-LABEL: flat_workgroup_one_as_release_acquire_ret_cmpxchg:
5925; GFX10-WGP:       ; %bb.0: ; %entry
5926; GFX10-WGP-NEXT:    s_clause 0x1
5927; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5928; GFX10-WGP-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
5929; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
5930; GFX10-WGP-NEXT:    s_add_u32 s4, s0, 16
5931; GFX10-WGP-NEXT:    s_addc_u32 s5, s1, 0
5932; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s4
5933; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
5934; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s5
5935; GFX10-WGP-NEXT:    v_mov_b32_e32 v3, s3
5936; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0)
5937; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
5938; GFX10-WGP-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
5939; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0)
5940; GFX10-WGP-NEXT:    buffer_gl0_inv
5941; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
5942; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
5943; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
5944; GFX10-WGP-NEXT:    flat_store_dword v[0:1], v2
5945; GFX10-WGP-NEXT:    s_endpgm
5946;
5947; GFX10-CU-LABEL: flat_workgroup_one_as_release_acquire_ret_cmpxchg:
5948; GFX10-CU:       ; %bb.0: ; %entry
5949; GFX10-CU-NEXT:    s_clause 0x1
5950; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5951; GFX10-CU-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
5952; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
5953; GFX10-CU-NEXT:    s_add_u32 s4, s0, 16
5954; GFX10-CU-NEXT:    s_addc_u32 s5, s1, 0
5955; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s4
5956; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
5957; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s5
5958; GFX10-CU-NEXT:    v_mov_b32_e32 v3, s3
5959; GFX10-CU-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
5960; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
5961; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
5962; GFX10-CU-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
5963; GFX10-CU-NEXT:    flat_store_dword v[0:1], v2
5964; GFX10-CU-NEXT:    s_endpgm
5965;
5966; SKIP-CACHE-INV-LABEL: flat_workgroup_one_as_release_acquire_ret_cmpxchg:
5967; SKIP-CACHE-INV:       ; %bb.0: ; %entry
5968; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
5969; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
5970; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
5971; SKIP-CACHE-INV-NEXT:    s_add_u32 s4, s2, 16
5972; SKIP-CACHE-INV-NEXT:    s_addc_u32 s5, s3, 0
5973; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s4
5974; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s1
5975; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s5
5976; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
5977; SKIP-CACHE-INV-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
5978; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
5979; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
5980; SKIP-CACHE-INV-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
5981; SKIP-CACHE-INV-NEXT:    flat_store_dword v[0:1], v2
5982; SKIP-CACHE-INV-NEXT:    s_endpgm
5983;
5984; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_one_as_release_acquire_ret_cmpxchg:
5985; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
5986; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5987; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
5988; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
5989; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
5990; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
5991; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] offset:16 glc
5992; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
5993; GFX90A-NOTTGSPLIT-NEXT:    flat_store_dword v[0:1], v2
5994; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
5995;
5996; GFX90A-TGSPLIT-LABEL: flat_workgroup_one_as_release_acquire_ret_cmpxchg:
5997; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
5998; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
5999; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
6000; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
6001; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
6002; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
6003; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
6004; GFX90A-TGSPLIT-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] offset:16 glc
6005; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
6006; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
6007; GFX90A-TGSPLIT-NEXT:    flat_store_dword v[0:1], v2
6008; GFX90A-TGSPLIT-NEXT:    s_endpgm
6009    i32* %out, i32 %in, i32 %old) {
6010entry:
6011  %gep = getelementptr i32, i32* %out, i32 4
6012  %val = cmpxchg volatile i32* %gep, i32 %old, i32 %in syncscope("workgroup-one-as") release acquire
6013  %val0 = extractvalue { i32, i1 } %val, 0
6014  store i32 %val0, i32* %out, align 4
6015  ret void
6016}
6017
6018define amdgpu_kernel void @flat_workgroup_one_as_acq_rel_acquire_ret_cmpxchg(
6019; GFX7-LABEL: flat_workgroup_one_as_acq_rel_acquire_ret_cmpxchg:
6020; GFX7:       ; %bb.0: ; %entry
6021; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
6022; GFX7-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x2
6023; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
6024; GFX7-NEXT:    s_add_u32 s4, s0, 16
6025; GFX7-NEXT:    s_addc_u32 s5, s1, 0
6026; GFX7-NEXT:    v_mov_b32_e32 v0, s4
6027; GFX7-NEXT:    v_mov_b32_e32 v2, s2
6028; GFX7-NEXT:    v_mov_b32_e32 v1, s5
6029; GFX7-NEXT:    v_mov_b32_e32 v3, s3
6030; GFX7-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
6031; GFX7-NEXT:    v_mov_b32_e32 v0, s0
6032; GFX7-NEXT:    v_mov_b32_e32 v1, s1
6033; GFX7-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
6034; GFX7-NEXT:    flat_store_dword v[0:1], v2
6035; GFX7-NEXT:    s_endpgm
6036;
6037; GFX10-WGP-LABEL: flat_workgroup_one_as_acq_rel_acquire_ret_cmpxchg:
6038; GFX10-WGP:       ; %bb.0: ; %entry
6039; GFX10-WGP-NEXT:    s_clause 0x1
6040; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
6041; GFX10-WGP-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
6042; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
6043; GFX10-WGP-NEXT:    s_add_u32 s4, s0, 16
6044; GFX10-WGP-NEXT:    s_addc_u32 s5, s1, 0
6045; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s4
6046; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
6047; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s5
6048; GFX10-WGP-NEXT:    v_mov_b32_e32 v3, s3
6049; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0)
6050; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
6051; GFX10-WGP-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
6052; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0)
6053; GFX10-WGP-NEXT:    buffer_gl0_inv
6054; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
6055; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
6056; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
6057; GFX10-WGP-NEXT:    flat_store_dword v[0:1], v2
6058; GFX10-WGP-NEXT:    s_endpgm
6059;
6060; GFX10-CU-LABEL: flat_workgroup_one_as_acq_rel_acquire_ret_cmpxchg:
6061; GFX10-CU:       ; %bb.0: ; %entry
6062; GFX10-CU-NEXT:    s_clause 0x1
6063; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
6064; GFX10-CU-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
6065; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
6066; GFX10-CU-NEXT:    s_add_u32 s4, s0, 16
6067; GFX10-CU-NEXT:    s_addc_u32 s5, s1, 0
6068; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s4
6069; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
6070; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s5
6071; GFX10-CU-NEXT:    v_mov_b32_e32 v3, s3
6072; GFX10-CU-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
6073; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
6074; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
6075; GFX10-CU-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
6076; GFX10-CU-NEXT:    flat_store_dword v[0:1], v2
6077; GFX10-CU-NEXT:    s_endpgm
6078;
6079; SKIP-CACHE-INV-LABEL: flat_workgroup_one_as_acq_rel_acquire_ret_cmpxchg:
6080; SKIP-CACHE-INV:       ; %bb.0: ; %entry
6081; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
6082; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
6083; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
6084; SKIP-CACHE-INV-NEXT:    s_add_u32 s4, s2, 16
6085; SKIP-CACHE-INV-NEXT:    s_addc_u32 s5, s3, 0
6086; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s4
6087; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s1
6088; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s5
6089; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
6090; SKIP-CACHE-INV-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
6091; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
6092; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
6093; SKIP-CACHE-INV-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
6094; SKIP-CACHE-INV-NEXT:    flat_store_dword v[0:1], v2
6095; SKIP-CACHE-INV-NEXT:    s_endpgm
6096;
6097; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_one_as_acq_rel_acquire_ret_cmpxchg:
6098; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
6099; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
6100; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
6101; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
6102; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
6103; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
6104; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] offset:16 glc
6105; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
6106; GFX90A-NOTTGSPLIT-NEXT:    flat_store_dword v[0:1], v2
6107; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
6108;
6109; GFX90A-TGSPLIT-LABEL: flat_workgroup_one_as_acq_rel_acquire_ret_cmpxchg:
6110; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
6111; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
6112; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
6113; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
6114; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
6115; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
6116; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
6117; GFX90A-TGSPLIT-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] offset:16 glc
6118; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
6119; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
6120; GFX90A-TGSPLIT-NEXT:    flat_store_dword v[0:1], v2
6121; GFX90A-TGSPLIT-NEXT:    s_endpgm
6122    i32* %out, i32 %in, i32 %old) {
6123entry:
6124  %gep = getelementptr i32, i32* %out, i32 4
6125  %val = cmpxchg volatile i32* %gep, i32 %old, i32 %in syncscope("workgroup-one-as") acq_rel acquire
6126  %val0 = extractvalue { i32, i1 } %val, 0
6127  store i32 %val0, i32* %out, align 4
6128  ret void
6129}
6130
6131define amdgpu_kernel void @flat_workgroup_one_as_seq_cst_acquire_ret_cmpxchg(
6132; GFX7-LABEL: flat_workgroup_one_as_seq_cst_acquire_ret_cmpxchg:
6133; GFX7:       ; %bb.0: ; %entry
6134; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
6135; GFX7-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x2
6136; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
6137; GFX7-NEXT:    s_add_u32 s4, s0, 16
6138; GFX7-NEXT:    s_addc_u32 s5, s1, 0
6139; GFX7-NEXT:    v_mov_b32_e32 v0, s4
6140; GFX7-NEXT:    v_mov_b32_e32 v2, s2
6141; GFX7-NEXT:    v_mov_b32_e32 v1, s5
6142; GFX7-NEXT:    v_mov_b32_e32 v3, s3
6143; GFX7-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
6144; GFX7-NEXT:    v_mov_b32_e32 v0, s0
6145; GFX7-NEXT:    v_mov_b32_e32 v1, s1
6146; GFX7-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
6147; GFX7-NEXT:    flat_store_dword v[0:1], v2
6148; GFX7-NEXT:    s_endpgm
6149;
6150; GFX10-WGP-LABEL: flat_workgroup_one_as_seq_cst_acquire_ret_cmpxchg:
6151; GFX10-WGP:       ; %bb.0: ; %entry
6152; GFX10-WGP-NEXT:    s_clause 0x1
6153; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
6154; GFX10-WGP-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
6155; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
6156; GFX10-WGP-NEXT:    s_add_u32 s4, s0, 16
6157; GFX10-WGP-NEXT:    s_addc_u32 s5, s1, 0
6158; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s4
6159; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
6160; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s5
6161; GFX10-WGP-NEXT:    v_mov_b32_e32 v3, s3
6162; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0)
6163; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
6164; GFX10-WGP-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
6165; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0)
6166; GFX10-WGP-NEXT:    buffer_gl0_inv
6167; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
6168; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
6169; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
6170; GFX10-WGP-NEXT:    flat_store_dword v[0:1], v2
6171; GFX10-WGP-NEXT:    s_endpgm
6172;
6173; GFX10-CU-LABEL: flat_workgroup_one_as_seq_cst_acquire_ret_cmpxchg:
6174; GFX10-CU:       ; %bb.0: ; %entry
6175; GFX10-CU-NEXT:    s_clause 0x1
6176; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
6177; GFX10-CU-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
6178; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
6179; GFX10-CU-NEXT:    s_add_u32 s4, s0, 16
6180; GFX10-CU-NEXT:    s_addc_u32 s5, s1, 0
6181; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s4
6182; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
6183; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s5
6184; GFX10-CU-NEXT:    v_mov_b32_e32 v3, s3
6185; GFX10-CU-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
6186; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
6187; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
6188; GFX10-CU-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
6189; GFX10-CU-NEXT:    flat_store_dword v[0:1], v2
6190; GFX10-CU-NEXT:    s_endpgm
6191;
6192; SKIP-CACHE-INV-LABEL: flat_workgroup_one_as_seq_cst_acquire_ret_cmpxchg:
6193; SKIP-CACHE-INV:       ; %bb.0: ; %entry
6194; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
6195; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
6196; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
6197; SKIP-CACHE-INV-NEXT:    s_add_u32 s4, s2, 16
6198; SKIP-CACHE-INV-NEXT:    s_addc_u32 s5, s3, 0
6199; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s4
6200; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s1
6201; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s5
6202; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
6203; SKIP-CACHE-INV-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
6204; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
6205; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
6206; SKIP-CACHE-INV-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
6207; SKIP-CACHE-INV-NEXT:    flat_store_dword v[0:1], v2
6208; SKIP-CACHE-INV-NEXT:    s_endpgm
6209;
6210; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_one_as_seq_cst_acquire_ret_cmpxchg:
6211; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
6212; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
6213; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
6214; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
6215; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
6216; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
6217; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] offset:16 glc
6218; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
6219; GFX90A-NOTTGSPLIT-NEXT:    flat_store_dword v[0:1], v2
6220; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
6221;
6222; GFX90A-TGSPLIT-LABEL: flat_workgroup_one_as_seq_cst_acquire_ret_cmpxchg:
6223; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
6224; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
6225; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
6226; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
6227; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
6228; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
6229; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
6230; GFX90A-TGSPLIT-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] offset:16 glc
6231; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
6232; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
6233; GFX90A-TGSPLIT-NEXT:    flat_store_dword v[0:1], v2
6234; GFX90A-TGSPLIT-NEXT:    s_endpgm
6235    i32* %out, i32 %in, i32 %old) {
6236entry:
6237  %gep = getelementptr i32, i32* %out, i32 4
6238  %val = cmpxchg volatile i32* %gep, i32 %old, i32 %in syncscope("workgroup-one-as") seq_cst acquire
6239  %val0 = extractvalue { i32, i1 } %val, 0
6240  store i32 %val0, i32* %out, align 4
6241  ret void
6242}
6243
6244define amdgpu_kernel void @flat_workgroup_one_as_seq_cst_seq_cst_ret_cmpxchg(
6245; GFX7-LABEL: flat_workgroup_one_as_seq_cst_seq_cst_ret_cmpxchg:
6246; GFX7:       ; %bb.0: ; %entry
6247; GFX7-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
6248; GFX7-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x2
6249; GFX7-NEXT:    s_waitcnt lgkmcnt(0)
6250; GFX7-NEXT:    s_add_u32 s4, s0, 16
6251; GFX7-NEXT:    s_addc_u32 s5, s1, 0
6252; GFX7-NEXT:    v_mov_b32_e32 v0, s4
6253; GFX7-NEXT:    v_mov_b32_e32 v2, s2
6254; GFX7-NEXT:    v_mov_b32_e32 v1, s5
6255; GFX7-NEXT:    v_mov_b32_e32 v3, s3
6256; GFX7-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
6257; GFX7-NEXT:    v_mov_b32_e32 v0, s0
6258; GFX7-NEXT:    v_mov_b32_e32 v1, s1
6259; GFX7-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
6260; GFX7-NEXT:    flat_store_dword v[0:1], v2
6261; GFX7-NEXT:    s_endpgm
6262;
6263; GFX10-WGP-LABEL: flat_workgroup_one_as_seq_cst_seq_cst_ret_cmpxchg:
6264; GFX10-WGP:       ; %bb.0: ; %entry
6265; GFX10-WGP-NEXT:    s_clause 0x1
6266; GFX10-WGP-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
6267; GFX10-WGP-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
6268; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
6269; GFX10-WGP-NEXT:    s_add_u32 s4, s0, 16
6270; GFX10-WGP-NEXT:    s_addc_u32 s5, s1, 0
6271; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s4
6272; GFX10-WGP-NEXT:    v_mov_b32_e32 v2, s2
6273; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s5
6274; GFX10-WGP-NEXT:    v_mov_b32_e32 v3, s3
6275; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0)
6276; GFX10-WGP-NEXT:    s_waitcnt_vscnt null, 0x0
6277; GFX10-WGP-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
6278; GFX10-WGP-NEXT:    s_waitcnt vmcnt(0)
6279; GFX10-WGP-NEXT:    buffer_gl0_inv
6280; GFX10-WGP-NEXT:    v_mov_b32_e32 v0, s0
6281; GFX10-WGP-NEXT:    v_mov_b32_e32 v1, s1
6282; GFX10-WGP-NEXT:    s_waitcnt lgkmcnt(0)
6283; GFX10-WGP-NEXT:    flat_store_dword v[0:1], v2
6284; GFX10-WGP-NEXT:    s_endpgm
6285;
6286; GFX10-CU-LABEL: flat_workgroup_one_as_seq_cst_seq_cst_ret_cmpxchg:
6287; GFX10-CU:       ; %bb.0: ; %entry
6288; GFX10-CU-NEXT:    s_clause 0x1
6289; GFX10-CU-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
6290; GFX10-CU-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
6291; GFX10-CU-NEXT:    s_waitcnt lgkmcnt(0)
6292; GFX10-CU-NEXT:    s_add_u32 s4, s0, 16
6293; GFX10-CU-NEXT:    s_addc_u32 s5, s1, 0
6294; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s4
6295; GFX10-CU-NEXT:    v_mov_b32_e32 v2, s2
6296; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s5
6297; GFX10-CU-NEXT:    v_mov_b32_e32 v3, s3
6298; GFX10-CU-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
6299; GFX10-CU-NEXT:    v_mov_b32_e32 v0, s0
6300; GFX10-CU-NEXT:    v_mov_b32_e32 v1, s1
6301; GFX10-CU-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
6302; GFX10-CU-NEXT:    flat_store_dword v[0:1], v2
6303; GFX10-CU-NEXT:    s_endpgm
6304;
6305; SKIP-CACHE-INV-LABEL: flat_workgroup_one_as_seq_cst_seq_cst_ret_cmpxchg:
6306; SKIP-CACHE-INV:       ; %bb.0: ; %entry
6307; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[2:3], s[0:1], 0x9
6308; SKIP-CACHE-INV-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0xb
6309; SKIP-CACHE-INV-NEXT:    s_waitcnt lgkmcnt(0)
6310; SKIP-CACHE-INV-NEXT:    s_add_u32 s4, s2, 16
6311; SKIP-CACHE-INV-NEXT:    s_addc_u32 s5, s3, 0
6312; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s4
6313; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v3, s1
6314; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s5
6315; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v2, s0
6316; SKIP-CACHE-INV-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] glc
6317; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v0, s2
6318; SKIP-CACHE-INV-NEXT:    v_mov_b32_e32 v1, s3
6319; SKIP-CACHE-INV-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
6320; SKIP-CACHE-INV-NEXT:    flat_store_dword v[0:1], v2
6321; SKIP-CACHE-INV-NEXT:    s_endpgm
6322;
6323; GFX90A-NOTTGSPLIT-LABEL: flat_workgroup_one_as_seq_cst_seq_cst_ret_cmpxchg:
6324; GFX90A-NOTTGSPLIT:       ; %bb.0: ; %entry
6325; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
6326; GFX90A-NOTTGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
6327; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
6328; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
6329; GFX90A-NOTTGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
6330; GFX90A-NOTTGSPLIT-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] offset:16 glc
6331; GFX90A-NOTTGSPLIT-NEXT:    s_waitcnt vmcnt(0) lgkmcnt(0)
6332; GFX90A-NOTTGSPLIT-NEXT:    flat_store_dword v[0:1], v2
6333; GFX90A-NOTTGSPLIT-NEXT:    s_endpgm
6334;
6335; GFX90A-TGSPLIT-LABEL: flat_workgroup_one_as_seq_cst_seq_cst_ret_cmpxchg:
6336; GFX90A-TGSPLIT:       ; %bb.0: ; %entry
6337; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[0:1], s[4:5], 0x0
6338; GFX90A-TGSPLIT-NEXT:    s_load_dwordx2 s[2:3], s[4:5], 0x8
6339; GFX90A-TGSPLIT-NEXT:    s_waitcnt lgkmcnt(0)
6340; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[0:1], s[0:1], s[0:1] op_sel:[0,1]
6341; GFX90A-TGSPLIT-NEXT:    v_pk_mov_b32 v[2:3], s[2:3], s[2:3] op_sel:[0,1]
6342; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
6343; GFX90A-TGSPLIT-NEXT:    flat_atomic_cmpswap v2, v[0:1], v[2:3] offset:16 glc
6344; GFX90A-TGSPLIT-NEXT:    s_waitcnt vmcnt(0)
6345; GFX90A-TGSPLIT-NEXT:    buffer_wbinvl1_vol
6346; GFX90A-TGSPLIT-NEXT:    flat_store_dword v[0:1], v2
6347; GFX90A-TGSPLIT-NEXT:    s_endpgm
6348    i32* %out, i32 %in, i32 %old) {
6349entry:
6350  %gep = getelementptr i32, i32* %out, i32 4
6351  %val = cmpxchg volatile i32* %gep, i32 %old, i32 %in syncscope("workgroup-one-as") seq_cst seq_cst
6352  %val0 = extractvalue { i32, i1 } %val, 0
6353  store i32 %val0, i32* %out, align 4
6354  ret void
6355}
6356
6357