1 ;RUN: llc < %s -mtriple=amdgcn -mcpu=verde -amdgpu-atomic-optimizer-strategy=None -verify-machineinstrs | FileCheck %s
2 ;RUN: llc < %s -mtriple=amdgcn -mcpu=tonga -amdgpu-atomic-optimizer-strategy=None -verify-machineinstrs | FileCheck %s
4 ;CHECK-LABEL: {{^}}test1:
6 ;CHECK: buffer_atomic_swap v0, off, s[0:3], 0 glc
7 ;CHECK: s_movk_i32 [[SOFS:s[0-9]+]], 0x1ffc
8 ;CHECK: s_waitcnt vmcnt(0)
9 ;CHECK: buffer_atomic_swap v0, v1, s[0:3], 0 offen glc
10 ;CHECK: s_waitcnt vmcnt(0)
11 ;CHECK: buffer_atomic_swap v0, v1, s[0:3], 0 offen offset:42 glc
12 ;CHECK-DAG: s_waitcnt vmcnt(0)
13 ;CHECK: buffer_atomic_swap v0, off, s[0:3], [[SOFS]] offset:4 glc
14 ;CHECK: s_waitcnt vmcnt(0)
15 ;CHECK: buffer_atomic_swap v0, off, s[0:3], 0{{$}}
16 ;CHECK: buffer_atomic_swap v0, off, s[0:3], 0 glc
17 define amdgpu_ps float @test1(<4 x i32> inreg %rsrc, i32 %data, i32 %voffset) {
19 %o1 = call i32 @llvm.amdgcn.raw.buffer.atomic.swap.i32(i32 %data, <4 x i32> %rsrc, i32 0, i32 0, i32 0)
20 %o3 = call i32 @llvm.amdgcn.raw.buffer.atomic.swap.i32(i32 %o1, <4 x i32> %rsrc, i32 %voffset, i32 0, i32 0)
21 %off5 = add i32 %voffset, 42
22 %o5 = call i32 @llvm.amdgcn.raw.buffer.atomic.swap.i32(i32 %o3, <4 x i32> %rsrc, i32 %off5, i32 0, i32 0)
23 %o6 = call i32 @llvm.amdgcn.raw.buffer.atomic.swap.i32(i32 %o5, <4 x i32> %rsrc, i32 4, i32 8188, i32 0)
24 %unused = call i32 @llvm.amdgcn.raw.buffer.atomic.swap.i32(i32 %o6, <4 x i32> %rsrc, i32 0, i32 0, i32 0)
25 %o7 = bitcast i32 %o6 to float
26 %out = call float @llvm.amdgcn.raw.buffer.atomic.swap.f32(float %o7, <4 x i32> %rsrc, i32 0, i32 0, i32 0)
30 ;CHECK-LABEL: {{^}}test2:
32 ;CHECK: buffer_atomic_add v0, v1, s[0:3], 0 offen glc{{$}}
33 ;CHECK: s_waitcnt vmcnt(0)
34 ;CHECK: buffer_atomic_sub v0, v1, s[0:3], 0 offen glc slc
35 ;CHECK: s_waitcnt vmcnt(0)
36 ;CHECK: buffer_atomic_smin v0, v1, s[0:3], 0 offen glc{{$}}
37 ;CHECK: s_waitcnt vmcnt(0)
38 ;CHECK: buffer_atomic_umin v0, v1, s[0:3], 0 offen glc slc
39 ;CHECK: s_waitcnt vmcnt(0)
40 ;CHECK: buffer_atomic_smax v0, v1, s[0:3], 0 offen glc{{$}}
41 ;CHECK: s_waitcnt vmcnt(0)
42 ;CHECK: buffer_atomic_umax v0, v1, s[0:3], 0 offen glc slc
43 ;CHECK: s_waitcnt vmcnt(0)
44 ;CHECK: buffer_atomic_and v0, v1, s[0:3], 0 offen glc{{$}}
45 ;CHECK: s_waitcnt vmcnt(0)
46 ;CHECK: buffer_atomic_or v0, v1, s[0:3], 0 offen glc slc
47 ;CHECK: s_waitcnt vmcnt(0)
48 ;CHECK: buffer_atomic_xor v0, v1, s[0:3], 0 offen glc
49 ;CHECK: s_waitcnt vmcnt(0)
50 ;CHECK: buffer_atomic_inc v0, v1, s[0:3], 0 offen glc
51 ;CHECK: s_waitcnt vmcnt(0)
52 ;CHECK: buffer_atomic_dec v0, v1, s[0:3], 0 offen glc
53 define amdgpu_ps float @test2(<4 x i32> inreg %rsrc, i32 %data, i32 %voffset) {
55 %t1 = call i32 @llvm.amdgcn.raw.buffer.atomic.add.i32(i32 %data, <4 x i32> %rsrc, i32 %voffset, i32 0, i32 0)
56 %t2 = call i32 @llvm.amdgcn.raw.buffer.atomic.sub.i32(i32 %t1, <4 x i32> %rsrc, i32 %voffset, i32 0, i32 2)
57 %t3 = call i32 @llvm.amdgcn.raw.buffer.atomic.smin.i32(i32 %t2, <4 x i32> %rsrc, i32 %voffset, i32 0, i32 0)
58 %t4 = call i32 @llvm.amdgcn.raw.buffer.atomic.umin.i32(i32 %t3, <4 x i32> %rsrc, i32 %voffset, i32 0, i32 2)
59 %t5 = call i32 @llvm.amdgcn.raw.buffer.atomic.smax.i32(i32 %t4, <4 x i32> %rsrc, i32 %voffset, i32 0, i32 0)
60 %t6 = call i32 @llvm.amdgcn.raw.buffer.atomic.umax.i32(i32 %t5, <4 x i32> %rsrc, i32 %voffset, i32 0, i32 2)
61 %t7 = call i32 @llvm.amdgcn.raw.buffer.atomic.and.i32(i32 %t6, <4 x i32> %rsrc, i32 %voffset, i32 0, i32 0)
62 %t8 = call i32 @llvm.amdgcn.raw.buffer.atomic.or.i32(i32 %t7, <4 x i32> %rsrc, i32 %voffset, i32 0, i32 2)
63 %t9 = call i32 @llvm.amdgcn.raw.buffer.atomic.xor.i32(i32 %t8, <4 x i32> %rsrc, i32 %voffset, i32 0, i32 0)
64 %t10 = call i32 @llvm.amdgcn.raw.buffer.atomic.inc.i32(i32 %t9, <4 x i32> %rsrc, i32 %voffset, i32 0, i32 0)
65 %t11 = call i32 @llvm.amdgcn.raw.buffer.atomic.dec.i32(i32 %t10, <4 x i32> %rsrc, i32 %voffset, i32 0, i32 0)
66 %out = bitcast i32 %t11 to float
70 ; Ideally, we would teach tablegen & friends that cmpswap only modifies the
71 ; first vgpr. Since we don't do that yet, the register allocator will have to
72 ; create copies which we don't bother to track here.
74 ;CHECK-LABEL: {{^}}test3:
76 ;CHECK: buffer_atomic_cmpswap {{v\[[0-9]+:[0-9]+\]}}, off, s[0:3], 0 glc
77 ;CHECK: s_waitcnt vmcnt(0)
78 ;CHECK: s_movk_i32 [[SOFS:s[0-9]+]], 0x1ffc
79 ;CHECK: buffer_atomic_cmpswap {{v\[[0-9]+:[0-9]+\]}}, v2, s[0:3], 0 offen glc
80 ;CHECK: s_waitcnt vmcnt(0)
81 ;CHECK: buffer_atomic_cmpswap {{v\[[0-9]+:[0-9]+\]}}, v2, s[0:3], 0 offen offset:44 glc
82 ;CHECK-DAG: s_waitcnt vmcnt(0)
83 ;CHECK: buffer_atomic_cmpswap {{v\[[0-9]+:[0-9]+\]}}, off, s[0:3], [[SOFS]] offset:4 glc
84 define amdgpu_ps float @test3(<4 x i32> inreg %rsrc, i32 %data, i32 %cmp, i32 %vindex, i32 %voffset) {
86 %o1 = call i32 @llvm.amdgcn.raw.buffer.atomic.cmpswap.i32(i32 %data, i32 %cmp, <4 x i32> %rsrc, i32 0, i32 0, i32 0)
87 %o3 = call i32 @llvm.amdgcn.raw.buffer.atomic.cmpswap.i32(i32 %o1, i32 %cmp, <4 x i32> %rsrc, i32 %voffset, i32 0, i32 0)
88 %ofs.5 = add i32 %voffset, 44
89 %o5 = call i32 @llvm.amdgcn.raw.buffer.atomic.cmpswap.i32(i32 %o3, i32 %cmp, <4 x i32> %rsrc, i32 %ofs.5, i32 0, i32 0)
90 %o6 = call i32 @llvm.amdgcn.raw.buffer.atomic.cmpswap.i32(i32 %o5, i32 %cmp, <4 x i32> %rsrc, i32 4, i32 8188, i32 0)
92 ; Detecting the no-return variant doesn't work right now because of how the
93 ; intrinsic is replaced by an instruction that feeds into an EXTRACT_SUBREG.
94 ; Since there probably isn't a reasonable use-case of cmpswap that discards
95 ; the return value, that seems okay.
97 ; %unused = call i32 @llvm.amdgcn.raw.buffer.atomic.cmpswap.i32(i32 %o6, i32 %cmp, <4 x i32> %rsrc, i32 0, i32 0, i32 0)
98 %out = bitcast i32 %o6 to float
102 ;CHECK-LABEL: {{^}}test4:
103 ;CHECK: buffer_atomic_add v0,
104 define amdgpu_ps float @test4() {
106 %v = call i32 @llvm.amdgcn.raw.buffer.atomic.add.i32(i32 1, <4 x i32> undef, i32 4, i32 0, i32 0)
107 %v.float = bitcast i32 %v to float
111 ;CHECK-LABEL: {{^}}test5:
112 ;CHECK-NOT: s_waitcnt
113 ;CHECK: buffer_atomic_cmpswap_x2 {{v\[[0-9]+:[0-9]+\]}}, off, s[0:3], 0 glc
114 ;CHECK-DAG: s_waitcnt vmcnt(0)
115 ;CHECK-DAG: s_movk_i32 [[SOFS:s[0-9]+]], 0x1ffc
116 ;CHECK: buffer_atomic_cmpswap_x2 {{v\[[0-9]+:[0-9]+\]}}, v4, s[0:3], 0 offen glc
117 ;CHECK: s_waitcnt vmcnt(0)
118 ;CHECK: buffer_atomic_cmpswap_x2 {{v\[[0-9]+:[0-9]+\]}}, v4, s[0:3], 0 offen offset:44 glc
119 ;CHECK-DAG: s_waitcnt vmcnt(0)
120 ;CHECK: buffer_atomic_cmpswap_x2 {{v\[[0-9]+:[0-9]+\]}}, off, s[0:3], [[SOFS]] offset:4 glc
121 define amdgpu_ps float @test5(<4 x i32> inreg %rsrc, i64 %data, i64 %cmp, i32 %vindex, i32 %voffset) {
123 %o1 = call i64 @llvm.amdgcn.raw.buffer.atomic.cmpswap.i64(i64 %data, i64 %cmp, <4 x i32> %rsrc, i32 0, i32 0, i32 0)
124 %o3 = call i64 @llvm.amdgcn.raw.buffer.atomic.cmpswap.i64(i64 %o1, i64 %cmp, <4 x i32> %rsrc, i32 %voffset, i32 0, i32 0)
125 %ofs.5 = add i32 %voffset, 44
126 %o5 = call i64 @llvm.amdgcn.raw.buffer.atomic.cmpswap.i64(i64 %o3, i64 %cmp, <4 x i32> %rsrc, i32 %ofs.5, i32 0, i32 0)
127 %o6 = call i64 @llvm.amdgcn.raw.buffer.atomic.cmpswap.i64(i64 %o5, i64 %cmp, <4 x i32> %rsrc, i32 4, i32 8188, i32 0)
128 %out = sitofp i64 %o6 to float
132 declare i32 @llvm.amdgcn.raw.buffer.atomic.swap.i32(i32, <4 x i32>, i32, i32, i32) #0
133 declare float @llvm.amdgcn.raw.buffer.atomic.swap.f32(float, <4 x i32>, i32, i32, i32) #0
134 declare i32 @llvm.amdgcn.raw.buffer.atomic.add.i32(i32, <4 x i32>, i32, i32, i32) #0
135 declare i32 @llvm.amdgcn.raw.buffer.atomic.sub.i32(i32, <4 x i32>, i32, i32, i32) #0
136 declare i32 @llvm.amdgcn.raw.buffer.atomic.smin.i32(i32, <4 x i32>, i32, i32, i32) #0
137 declare i32 @llvm.amdgcn.raw.buffer.atomic.umin.i32(i32, <4 x i32>, i32, i32, i32) #0
138 declare i32 @llvm.amdgcn.raw.buffer.atomic.smax.i32(i32, <4 x i32>, i32, i32, i32) #0
139 declare i32 @llvm.amdgcn.raw.buffer.atomic.umax.i32(i32, <4 x i32>, i32, i32, i32) #0
140 declare i32 @llvm.amdgcn.raw.buffer.atomic.and.i32(i32, <4 x i32>, i32, i32, i32) #0
141 declare i32 @llvm.amdgcn.raw.buffer.atomic.or.i32(i32, <4 x i32>, i32, i32, i32) #0
142 declare i32 @llvm.amdgcn.raw.buffer.atomic.xor.i32(i32, <4 x i32>, i32, i32, i32) #0
143 declare i32 @llvm.amdgcn.raw.buffer.atomic.inc.i32(i32, <4 x i32>, i32, i32, i32) #0
144 declare i32 @llvm.amdgcn.raw.buffer.atomic.dec.i32(i32, <4 x i32>, i32, i32, i32) #0
145 declare i32 @llvm.amdgcn.raw.buffer.atomic.cmpswap.i32(i32, i32, <4 x i32>, i32, i32, i32) #0
146 declare i64 @llvm.amdgcn.raw.buffer.atomic.cmpswap.i64(i64, i64, <4 x i32>, i32, i32, i32) #0
148 attributes #0 = { nounwind }