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