1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -mcpu=hawaii -atomic-expand %s | FileCheck -check-prefix=CI %s
3 ; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -atomic-expand %s | FileCheck -check-prefix=GFX9 %s
5 define float @test_atomicrmw_fadd_f32_flat(float* %ptr, float %value) {
6 ; CI-LABEL: @test_atomicrmw_fadd_f32_flat(
7 ; CI-NEXT: [[TMP1:%.*]] = load float, float* [[PTR:%.*]], align 4
8 ; CI-NEXT: br label [[ATOMICRMW_START:%.*]]
10 ; CI-NEXT: [[LOADED:%.*]] = phi float [ [[TMP1]], [[TMP0:%.*]] ], [ [[TMP6:%.*]], [[ATOMICRMW_START]] ]
11 ; CI-NEXT: [[NEW:%.*]] = fadd float [[LOADED]], [[VALUE:%.*]]
12 ; CI-NEXT: [[TMP2:%.*]] = bitcast float* [[PTR]] to i32*
13 ; CI-NEXT: [[TMP3:%.*]] = bitcast float [[NEW]] to i32
14 ; CI-NEXT: [[TMP4:%.*]] = bitcast float [[LOADED]] to i32
15 ; CI-NEXT: [[TMP5:%.*]] = cmpxchg i32* [[TMP2]], i32 [[TMP4]], i32 [[TMP3]] seq_cst seq_cst
16 ; CI-NEXT: [[SUCCESS:%.*]] = extractvalue { i32, i1 } [[TMP5]], 1
17 ; CI-NEXT: [[NEWLOADED:%.*]] = extractvalue { i32, i1 } [[TMP5]], 0
18 ; CI-NEXT: [[TMP6]] = bitcast i32 [[NEWLOADED]] to float
19 ; CI-NEXT: br i1 [[SUCCESS]], label [[ATOMICRMW_END:%.*]], label [[ATOMICRMW_START]]
21 ; CI-NEXT: ret float [[TMP6]]
23 ; GFX9-LABEL: @test_atomicrmw_fadd_f32_flat(
24 ; GFX9-NEXT: [[TMP1:%.*]] = load float, float* [[PTR:%.*]], align 4
25 ; GFX9-NEXT: br label [[ATOMICRMW_START:%.*]]
26 ; GFX9: atomicrmw.start:
27 ; GFX9-NEXT: [[LOADED:%.*]] = phi float [ [[TMP1]], [[TMP0:%.*]] ], [ [[TMP6:%.*]], [[ATOMICRMW_START]] ]
28 ; GFX9-NEXT: [[NEW:%.*]] = fadd float [[LOADED]], [[VALUE:%.*]]
29 ; GFX9-NEXT: [[TMP2:%.*]] = bitcast float* [[PTR]] to i32*
30 ; GFX9-NEXT: [[TMP3:%.*]] = bitcast float [[NEW]] to i32
31 ; GFX9-NEXT: [[TMP4:%.*]] = bitcast float [[LOADED]] to i32
32 ; GFX9-NEXT: [[TMP5:%.*]] = cmpxchg i32* [[TMP2]], i32 [[TMP4]], i32 [[TMP3]] seq_cst seq_cst
33 ; GFX9-NEXT: [[SUCCESS:%.*]] = extractvalue { i32, i1 } [[TMP5]], 1
34 ; GFX9-NEXT: [[NEWLOADED:%.*]] = extractvalue { i32, i1 } [[TMP5]], 0
35 ; GFX9-NEXT: [[TMP6]] = bitcast i32 [[NEWLOADED]] to float
36 ; GFX9-NEXT: br i1 [[SUCCESS]], label [[ATOMICRMW_END:%.*]], label [[ATOMICRMW_START]]
37 ; GFX9: atomicrmw.end:
38 ; GFX9-NEXT: ret float [[TMP6]]
40 %res = atomicrmw fadd float* %ptr, float %value seq_cst
44 define float @test_atomicrmw_fadd_f32_global(float addrspace(1)* %ptr, float %value) {
45 ; CI-LABEL: @test_atomicrmw_fadd_f32_global(
46 ; CI-NEXT: [[TMP1:%.*]] = load float, float addrspace(1)* [[PTR:%.*]], align 4
47 ; CI-NEXT: br label [[ATOMICRMW_START:%.*]]
48 ; CI: atomicrmw.start:
49 ; CI-NEXT: [[LOADED:%.*]] = phi float [ [[TMP1]], [[TMP0:%.*]] ], [ [[TMP6:%.*]], [[ATOMICRMW_START]] ]
50 ; CI-NEXT: [[NEW:%.*]] = fadd float [[LOADED]], [[VALUE:%.*]]
51 ; CI-NEXT: [[TMP2:%.*]] = bitcast float addrspace(1)* [[PTR]] to i32 addrspace(1)*
52 ; CI-NEXT: [[TMP3:%.*]] = bitcast float [[NEW]] to i32
53 ; CI-NEXT: [[TMP4:%.*]] = bitcast float [[LOADED]] to i32
54 ; CI-NEXT: [[TMP5:%.*]] = cmpxchg i32 addrspace(1)* [[TMP2]], i32 [[TMP4]], i32 [[TMP3]] seq_cst seq_cst
55 ; CI-NEXT: [[SUCCESS:%.*]] = extractvalue { i32, i1 } [[TMP5]], 1
56 ; CI-NEXT: [[NEWLOADED:%.*]] = extractvalue { i32, i1 } [[TMP5]], 0
57 ; CI-NEXT: [[TMP6]] = bitcast i32 [[NEWLOADED]] to float
58 ; CI-NEXT: br i1 [[SUCCESS]], label [[ATOMICRMW_END:%.*]], label [[ATOMICRMW_START]]
60 ; CI-NEXT: ret float [[TMP6]]
62 ; GFX9-LABEL: @test_atomicrmw_fadd_f32_global(
63 ; GFX9-NEXT: [[TMP1:%.*]] = load float, float addrspace(1)* [[PTR:%.*]], align 4
64 ; GFX9-NEXT: br label [[ATOMICRMW_START:%.*]]
65 ; GFX9: atomicrmw.start:
66 ; GFX9-NEXT: [[LOADED:%.*]] = phi float [ [[TMP1]], [[TMP0:%.*]] ], [ [[TMP6:%.*]], [[ATOMICRMW_START]] ]
67 ; GFX9-NEXT: [[NEW:%.*]] = fadd float [[LOADED]], [[VALUE:%.*]]
68 ; GFX9-NEXT: [[TMP2:%.*]] = bitcast float addrspace(1)* [[PTR]] to i32 addrspace(1)*
69 ; GFX9-NEXT: [[TMP3:%.*]] = bitcast float [[NEW]] to i32
70 ; GFX9-NEXT: [[TMP4:%.*]] = bitcast float [[LOADED]] to i32
71 ; GFX9-NEXT: [[TMP5:%.*]] = cmpxchg i32 addrspace(1)* [[TMP2]], i32 [[TMP4]], i32 [[TMP3]] seq_cst seq_cst
72 ; GFX9-NEXT: [[SUCCESS:%.*]] = extractvalue { i32, i1 } [[TMP5]], 1
73 ; GFX9-NEXT: [[NEWLOADED:%.*]] = extractvalue { i32, i1 } [[TMP5]], 0
74 ; GFX9-NEXT: [[TMP6]] = bitcast i32 [[NEWLOADED]] to float
75 ; GFX9-NEXT: br i1 [[SUCCESS]], label [[ATOMICRMW_END:%.*]], label [[ATOMICRMW_START]]
76 ; GFX9: atomicrmw.end:
77 ; GFX9-NEXT: ret float [[TMP6]]
79 %res = atomicrmw fadd float addrspace(1)* %ptr, float %value seq_cst
83 define float @test_atomicrmw_fadd_f32_local(float addrspace(3)* %ptr, float %value) {
84 ; CI-LABEL: @test_atomicrmw_fadd_f32_local(
85 ; CI-NEXT: [[TMP1:%.*]] = load float, float addrspace(3)* [[PTR:%.*]], align 4
86 ; CI-NEXT: br label [[ATOMICRMW_START:%.*]]
87 ; CI: atomicrmw.start:
88 ; CI-NEXT: [[LOADED:%.*]] = phi float [ [[TMP1]], [[TMP0:%.*]] ], [ [[TMP6:%.*]], [[ATOMICRMW_START]] ]
89 ; CI-NEXT: [[NEW:%.*]] = fadd float [[LOADED]], [[VALUE:%.*]]
90 ; CI-NEXT: [[TMP2:%.*]] = bitcast float addrspace(3)* [[PTR]] to i32 addrspace(3)*
91 ; CI-NEXT: [[TMP3:%.*]] = bitcast float [[NEW]] to i32
92 ; CI-NEXT: [[TMP4:%.*]] = bitcast float [[LOADED]] to i32
93 ; CI-NEXT: [[TMP5:%.*]] = cmpxchg i32 addrspace(3)* [[TMP2]], i32 [[TMP4]], i32 [[TMP3]] seq_cst seq_cst
94 ; CI-NEXT: [[SUCCESS:%.*]] = extractvalue { i32, i1 } [[TMP5]], 1
95 ; CI-NEXT: [[NEWLOADED:%.*]] = extractvalue { i32, i1 } [[TMP5]], 0
96 ; CI-NEXT: [[TMP6]] = bitcast i32 [[NEWLOADED]] to float
97 ; CI-NEXT: br i1 [[SUCCESS]], label [[ATOMICRMW_END:%.*]], label [[ATOMICRMW_START]]
99 ; CI-NEXT: ret float [[TMP6]]
101 ; GFX9-LABEL: @test_atomicrmw_fadd_f32_local(
102 ; GFX9-NEXT: [[RES:%.*]] = atomicrmw fadd float addrspace(3)* [[PTR:%.*]], float [[VALUE:%.*]] seq_cst
103 ; GFX9-NEXT: ret float [[RES]]
105 %res = atomicrmw fadd float addrspace(3)* %ptr, float %value seq_cst
109 define half @test_atomicrmw_fadd_f16_flat(half* %ptr, half %value) {
110 ; CI-LABEL: @test_atomicrmw_fadd_f16_flat(
111 ; CI-NEXT: [[RES:%.*]] = atomicrmw fadd half* [[PTR:%.*]], half [[VALUE:%.*]] seq_cst
112 ; CI-NEXT: ret half [[RES]]
114 ; GFX9-LABEL: @test_atomicrmw_fadd_f16_flat(
115 ; GFX9-NEXT: [[RES:%.*]] = atomicrmw fadd half* [[PTR:%.*]], half [[VALUE:%.*]] seq_cst
116 ; GFX9-NEXT: ret half [[RES]]
118 %res = atomicrmw fadd half* %ptr, half %value seq_cst
122 define half @test_atomicrmw_fadd_f16_global(half addrspace(1)* %ptr, half %value) {
123 ; CI-LABEL: @test_atomicrmw_fadd_f16_global(
124 ; CI-NEXT: [[RES:%.*]] = atomicrmw fadd half addrspace(1)* [[PTR:%.*]], half [[VALUE:%.*]] seq_cst
125 ; CI-NEXT: ret half [[RES]]
127 ; GFX9-LABEL: @test_atomicrmw_fadd_f16_global(
128 ; GFX9-NEXT: [[RES:%.*]] = atomicrmw fadd half addrspace(1)* [[PTR:%.*]], half [[VALUE:%.*]] seq_cst
129 ; GFX9-NEXT: ret half [[RES]]
131 %res = atomicrmw fadd half addrspace(1)* %ptr, half %value seq_cst
135 define half @test_atomicrmw_fadd_f16_local(half addrspace(3)* %ptr, half %value) {
136 ; CI-LABEL: @test_atomicrmw_fadd_f16_local(
137 ; CI-NEXT: [[RES:%.*]] = atomicrmw fadd half addrspace(3)* [[PTR:%.*]], half [[VALUE:%.*]] seq_cst
138 ; CI-NEXT: ret half [[RES]]
140 ; GFX9-LABEL: @test_atomicrmw_fadd_f16_local(
141 ; GFX9-NEXT: [[RES:%.*]] = atomicrmw fadd half addrspace(3)* [[PTR:%.*]], half [[VALUE:%.*]] seq_cst
142 ; GFX9-NEXT: ret half [[RES]]
144 %res = atomicrmw fadd half addrspace(3)* %ptr, half %value seq_cst
148 define double @test_atomicrmw_fadd_f64_flat(double* %ptr, double %value) {
149 ; CI-LABEL: @test_atomicrmw_fadd_f64_flat(
150 ; CI-NEXT: [[TMP1:%.*]] = load double, double* [[PTR:%.*]], align 8
151 ; CI-NEXT: br label [[ATOMICRMW_START:%.*]]
152 ; CI: atomicrmw.start:
153 ; CI-NEXT: [[LOADED:%.*]] = phi double [ [[TMP1]], [[TMP0:%.*]] ], [ [[TMP6:%.*]], [[ATOMICRMW_START]] ]
154 ; CI-NEXT: [[NEW:%.*]] = fadd double [[LOADED]], [[VALUE:%.*]]
155 ; CI-NEXT: [[TMP2:%.*]] = bitcast double* [[PTR]] to i64*
156 ; CI-NEXT: [[TMP3:%.*]] = bitcast double [[NEW]] to i64
157 ; CI-NEXT: [[TMP4:%.*]] = bitcast double [[LOADED]] to i64
158 ; CI-NEXT: [[TMP5:%.*]] = cmpxchg i64* [[TMP2]], i64 [[TMP4]], i64 [[TMP3]] seq_cst seq_cst
159 ; CI-NEXT: [[SUCCESS:%.*]] = extractvalue { i64, i1 } [[TMP5]], 1
160 ; CI-NEXT: [[NEWLOADED:%.*]] = extractvalue { i64, i1 } [[TMP5]], 0
161 ; CI-NEXT: [[TMP6]] = bitcast i64 [[NEWLOADED]] to double
162 ; CI-NEXT: br i1 [[SUCCESS]], label [[ATOMICRMW_END:%.*]], label [[ATOMICRMW_START]]
164 ; CI-NEXT: ret double [[TMP6]]
166 ; GFX9-LABEL: @test_atomicrmw_fadd_f64_flat(
167 ; GFX9-NEXT: [[TMP1:%.*]] = load double, double* [[PTR:%.*]], align 8
168 ; GFX9-NEXT: br label [[ATOMICRMW_START:%.*]]
169 ; GFX9: atomicrmw.start:
170 ; GFX9-NEXT: [[LOADED:%.*]] = phi double [ [[TMP1]], [[TMP0:%.*]] ], [ [[TMP6:%.*]], [[ATOMICRMW_START]] ]
171 ; GFX9-NEXT: [[NEW:%.*]] = fadd double [[LOADED]], [[VALUE:%.*]]
172 ; GFX9-NEXT: [[TMP2:%.*]] = bitcast double* [[PTR]] to i64*
173 ; GFX9-NEXT: [[TMP3:%.*]] = bitcast double [[NEW]] to i64
174 ; GFX9-NEXT: [[TMP4:%.*]] = bitcast double [[LOADED]] to i64
175 ; GFX9-NEXT: [[TMP5:%.*]] = cmpxchg i64* [[TMP2]], i64 [[TMP4]], i64 [[TMP3]] seq_cst seq_cst
176 ; GFX9-NEXT: [[SUCCESS:%.*]] = extractvalue { i64, i1 } [[TMP5]], 1
177 ; GFX9-NEXT: [[NEWLOADED:%.*]] = extractvalue { i64, i1 } [[TMP5]], 0
178 ; GFX9-NEXT: [[TMP6]] = bitcast i64 [[NEWLOADED]] to double
179 ; GFX9-NEXT: br i1 [[SUCCESS]], label [[ATOMICRMW_END:%.*]], label [[ATOMICRMW_START]]
180 ; GFX9: atomicrmw.end:
181 ; GFX9-NEXT: ret double [[TMP6]]
183 %res = atomicrmw fadd double* %ptr, double %value seq_cst
187 define double @test_atomicrmw_fadd_f64_global(double addrspace(1)* %ptr, double %value) {
188 ; CI-LABEL: @test_atomicrmw_fadd_f64_global(
189 ; CI-NEXT: [[TMP1:%.*]] = load double, double addrspace(1)* [[PTR:%.*]], align 8
190 ; CI-NEXT: br label [[ATOMICRMW_START:%.*]]
191 ; CI: atomicrmw.start:
192 ; CI-NEXT: [[LOADED:%.*]] = phi double [ [[TMP1]], [[TMP0:%.*]] ], [ [[TMP6:%.*]], [[ATOMICRMW_START]] ]
193 ; CI-NEXT: [[NEW:%.*]] = fadd double [[LOADED]], [[VALUE:%.*]]
194 ; CI-NEXT: [[TMP2:%.*]] = bitcast double addrspace(1)* [[PTR]] to i64 addrspace(1)*
195 ; CI-NEXT: [[TMP3:%.*]] = bitcast double [[NEW]] to i64
196 ; CI-NEXT: [[TMP4:%.*]] = bitcast double [[LOADED]] to i64
197 ; CI-NEXT: [[TMP5:%.*]] = cmpxchg i64 addrspace(1)* [[TMP2]], i64 [[TMP4]], i64 [[TMP3]] seq_cst seq_cst
198 ; CI-NEXT: [[SUCCESS:%.*]] = extractvalue { i64, i1 } [[TMP5]], 1
199 ; CI-NEXT: [[NEWLOADED:%.*]] = extractvalue { i64, i1 } [[TMP5]], 0
200 ; CI-NEXT: [[TMP6]] = bitcast i64 [[NEWLOADED]] to double
201 ; CI-NEXT: br i1 [[SUCCESS]], label [[ATOMICRMW_END:%.*]], label [[ATOMICRMW_START]]
203 ; CI-NEXT: ret double [[TMP6]]
205 ; GFX9-LABEL: @test_atomicrmw_fadd_f64_global(
206 ; GFX9-NEXT: [[TMP1:%.*]] = load double, double addrspace(1)* [[PTR:%.*]], align 8
207 ; GFX9-NEXT: br label [[ATOMICRMW_START:%.*]]
208 ; GFX9: atomicrmw.start:
209 ; GFX9-NEXT: [[LOADED:%.*]] = phi double [ [[TMP1]], [[TMP0:%.*]] ], [ [[TMP6:%.*]], [[ATOMICRMW_START]] ]
210 ; GFX9-NEXT: [[NEW:%.*]] = fadd double [[LOADED]], [[VALUE:%.*]]
211 ; GFX9-NEXT: [[TMP2:%.*]] = bitcast double addrspace(1)* [[PTR]] to i64 addrspace(1)*
212 ; GFX9-NEXT: [[TMP3:%.*]] = bitcast double [[NEW]] to i64
213 ; GFX9-NEXT: [[TMP4:%.*]] = bitcast double [[LOADED]] to i64
214 ; GFX9-NEXT: [[TMP5:%.*]] = cmpxchg i64 addrspace(1)* [[TMP2]], i64 [[TMP4]], i64 [[TMP3]] seq_cst seq_cst
215 ; GFX9-NEXT: [[SUCCESS:%.*]] = extractvalue { i64, i1 } [[TMP5]], 1
216 ; GFX9-NEXT: [[NEWLOADED:%.*]] = extractvalue { i64, i1 } [[TMP5]], 0
217 ; GFX9-NEXT: [[TMP6]] = bitcast i64 [[NEWLOADED]] to double
218 ; GFX9-NEXT: br i1 [[SUCCESS]], label [[ATOMICRMW_END:%.*]], label [[ATOMICRMW_START]]
219 ; GFX9: atomicrmw.end:
220 ; GFX9-NEXT: ret double [[TMP6]]
222 %res = atomicrmw fadd double addrspace(1)* %ptr, double %value seq_cst
226 define double @test_atomicrmw_fadd_f64_local(double addrspace(3)* %ptr, double %value) {
227 ; CI-LABEL: @test_atomicrmw_fadd_f64_local(
228 ; CI-NEXT: [[TMP1:%.*]] = load double, double addrspace(3)* [[PTR:%.*]], align 8
229 ; CI-NEXT: br label [[ATOMICRMW_START:%.*]]
230 ; CI: atomicrmw.start:
231 ; CI-NEXT: [[LOADED:%.*]] = phi double [ [[TMP1]], [[TMP0:%.*]] ], [ [[TMP6:%.*]], [[ATOMICRMW_START]] ]
232 ; CI-NEXT: [[NEW:%.*]] = fadd double [[LOADED]], [[VALUE:%.*]]
233 ; CI-NEXT: [[TMP2:%.*]] = bitcast double addrspace(3)* [[PTR]] to i64 addrspace(3)*
234 ; CI-NEXT: [[TMP3:%.*]] = bitcast double [[NEW]] to i64
235 ; CI-NEXT: [[TMP4:%.*]] = bitcast double [[LOADED]] to i64
236 ; CI-NEXT: [[TMP5:%.*]] = cmpxchg i64 addrspace(3)* [[TMP2]], i64 [[TMP4]], i64 [[TMP3]] seq_cst seq_cst
237 ; CI-NEXT: [[SUCCESS:%.*]] = extractvalue { i64, i1 } [[TMP5]], 1
238 ; CI-NEXT: [[NEWLOADED:%.*]] = extractvalue { i64, i1 } [[TMP5]], 0
239 ; CI-NEXT: [[TMP6]] = bitcast i64 [[NEWLOADED]] to double
240 ; CI-NEXT: br i1 [[SUCCESS]], label [[ATOMICRMW_END:%.*]], label [[ATOMICRMW_START]]
242 ; CI-NEXT: ret double [[TMP6]]
244 ; GFX9-LABEL: @test_atomicrmw_fadd_f64_local(
245 ; GFX9-NEXT: [[TMP1:%.*]] = load double, double addrspace(3)* [[PTR:%.*]], align 8
246 ; GFX9-NEXT: br label [[ATOMICRMW_START:%.*]]
247 ; GFX9: atomicrmw.start:
248 ; GFX9-NEXT: [[LOADED:%.*]] = phi double [ [[TMP1]], [[TMP0:%.*]] ], [ [[TMP6:%.*]], [[ATOMICRMW_START]] ]
249 ; GFX9-NEXT: [[NEW:%.*]] = fadd double [[LOADED]], [[VALUE:%.*]]
250 ; GFX9-NEXT: [[TMP2:%.*]] = bitcast double addrspace(3)* [[PTR]] to i64 addrspace(3)*
251 ; GFX9-NEXT: [[TMP3:%.*]] = bitcast double [[NEW]] to i64
252 ; GFX9-NEXT: [[TMP4:%.*]] = bitcast double [[LOADED]] to i64
253 ; GFX9-NEXT: [[TMP5:%.*]] = cmpxchg i64 addrspace(3)* [[TMP2]], i64 [[TMP4]], i64 [[TMP3]] seq_cst seq_cst
254 ; GFX9-NEXT: [[SUCCESS:%.*]] = extractvalue { i64, i1 } [[TMP5]], 1
255 ; GFX9-NEXT: [[NEWLOADED:%.*]] = extractvalue { i64, i1 } [[TMP5]], 0
256 ; GFX9-NEXT: [[TMP6]] = bitcast i64 [[NEWLOADED]] to double
257 ; GFX9-NEXT: br i1 [[SUCCESS]], label [[ATOMICRMW_END:%.*]], label [[ATOMICRMW_START]]
258 ; GFX9: atomicrmw.end:
259 ; GFX9-NEXT: ret double [[TMP6]]
261 %res = atomicrmw fadd double addrspace(3)* %ptr, double %value seq_cst