1 ; RUN: llc -mtriple=arm64_32-apple-ios7.0 -o - %s | FileCheck %s
2 ; RUN: llc -mtriple=arm64_32-apple-ios7.0 -mattr=+outline-atomics -o - %s | FileCheck %s -check-prefix=OUTLINE-ATOMICS
4 define i8 @test_load_8(i8* %addr) {
5 ; CHECK-LABAL: test_load_8:
6 ; CHECK: ldarb w0, [x0]
7 %val = load atomic i8, i8* %addr seq_cst, align 1
11 define i16 @test_load_16(i16* %addr) {
12 ; CHECK-LABAL: test_load_16:
13 ; CHECK: ldarh w0, [x0]
14 %val = load atomic i16, i16* %addr acquire, align 2
18 define i32 @test_load_32(i32* %addr) {
19 ; CHECK-LABAL: test_load_32:
20 ; CHECK: ldar w0, [x0]
21 %val = load atomic i32, i32* %addr seq_cst, align 4
25 define i64 @test_load_64(i64* %addr) {
26 ; CHECK-LABAL: test_load_64:
27 ; CHECK: ldar x0, [x0]
28 %val = load atomic i64, i64* %addr seq_cst, align 8
32 define i8* @test_load_ptr(i8** %addr) {
33 ; CHECK-LABAL: test_load_ptr:
34 ; CHECK: ldar w0, [x0]
35 %val = load atomic i8*, i8** %addr seq_cst, align 8
39 define void @test_store_8(i8* %addr) {
40 ; CHECK-LABAL: test_store_8:
41 ; CHECK: stlrb wzr, [x0]
42 store atomic i8 0, i8* %addr seq_cst, align 1
46 define void @test_store_16(i16* %addr) {
47 ; CHECK-LABAL: test_store_16:
48 ; CHECK: stlrh wzr, [x0]
49 store atomic i16 0, i16* %addr seq_cst, align 2
53 define void @test_store_32(i32* %addr) {
54 ; CHECK-LABAL: test_store_32:
55 ; CHECK: stlr wzr, [x0]
56 store atomic i32 0, i32* %addr seq_cst, align 4
60 define void @test_store_64(i64* %addr) {
61 ; CHECK-LABAL: test_store_64:
62 ; CHECK: stlr xzr, [x0]
63 store atomic i64 0, i64* %addr seq_cst, align 8
67 define void @test_store_ptr(i8** %addr) {
68 ; CHECK-LABAL: test_store_ptr:
69 ; CHECK: stlr wzr, [x0]
70 store atomic i8* null, i8** %addr seq_cst, align 8
74 declare i64 @llvm.aarch64.ldxr.p0i8(i8* %addr)
75 declare i64 @llvm.aarch64.ldxr.p0i16(i16* %addr)
76 declare i64 @llvm.aarch64.ldxr.p0i32(i32* %addr)
77 declare i64 @llvm.aarch64.ldxr.p0i64(i64* %addr)
79 define i8 @test_ldxr_8(i8* %addr) {
80 ; CHECK-LABEL: test_ldxr_8:
81 ; CHECK: ldxrb w0, [x0]
83 %val = call i64 @llvm.aarch64.ldxr.p0i8(i8* %addr)
84 %val8 = trunc i64 %val to i8
88 define i16 @test_ldxr_16(i16* %addr) {
89 ; CHECK-LABEL: test_ldxr_16:
90 ; CHECK: ldxrh w0, [x0]
92 %val = call i64 @llvm.aarch64.ldxr.p0i16(i16* %addr)
93 %val16 = trunc i64 %val to i16
97 define i32 @test_ldxr_32(i32* %addr) {
98 ; CHECK-LABEL: test_ldxr_32:
99 ; CHECK: ldxr w0, [x0]
101 %val = call i64 @llvm.aarch64.ldxr.p0i32(i32* %addr)
102 %val32 = trunc i64 %val to i32
106 define i64 @test_ldxr_64(i64* %addr) {
107 ; CHECK-LABEL: test_ldxr_64:
108 ; CHECK: ldxr x0, [x0]
110 %val = call i64 @llvm.aarch64.ldxr.p0i64(i64* %addr)
114 declare i64 @llvm.aarch64.ldaxr.p0i8(i8* %addr)
115 declare i64 @llvm.aarch64.ldaxr.p0i16(i16* %addr)
116 declare i64 @llvm.aarch64.ldaxr.p0i32(i32* %addr)
117 declare i64 @llvm.aarch64.ldaxr.p0i64(i64* %addr)
119 define i8 @test_ldaxr_8(i8* %addr) {
120 ; CHECK-LABEL: test_ldaxr_8:
121 ; CHECK: ldaxrb w0, [x0]
123 %val = call i64 @llvm.aarch64.ldaxr.p0i8(i8* %addr)
124 %val8 = trunc i64 %val to i8
128 define i16 @test_ldaxr_16(i16* %addr) {
129 ; CHECK-LABEL: test_ldaxr_16:
130 ; CHECK: ldaxrh w0, [x0]
132 %val = call i64 @llvm.aarch64.ldaxr.p0i16(i16* %addr)
133 %val16 = trunc i64 %val to i16
137 define i32 @test_ldaxr_32(i32* %addr) {
138 ; CHECK-LABEL: test_ldaxr_32:
139 ; CHECK: ldaxr w0, [x0]
141 %val = call i64 @llvm.aarch64.ldaxr.p0i32(i32* %addr)
142 %val32 = trunc i64 %val to i32
146 define i64 @test_ldaxr_64(i64* %addr) {
147 ; CHECK-LABEL: test_ldaxr_64:
148 ; CHECK: ldaxr x0, [x0]
150 %val = call i64 @llvm.aarch64.ldaxr.p0i64(i64* %addr)
154 declare i32 @llvm.aarch64.stxr.p0i8(i64, i8*)
155 declare i32 @llvm.aarch64.stxr.p0i16(i64, i16*)
156 declare i32 @llvm.aarch64.stxr.p0i32(i64, i32*)
157 declare i32 @llvm.aarch64.stxr.p0i64(i64, i64*)
159 define i32 @test_stxr_8(i8* %addr, i8 %val) {
160 ; CHECK-LABEL: test_stxr_8:
161 ; CHECK: stxrb [[TMP:w[0-9]+]], w1, [x0]
162 ; CHECK: mov w0, [[TMP]]
164 %extval = zext i8 %val to i64
165 %success = call i32 @llvm.aarch64.stxr.p0i8(i64 %extval, i8* %addr)
169 define i32 @test_stxr_16(i16* %addr, i16 %val) {
170 ; CHECK-LABEL: test_stxr_16:
171 ; CHECK: stxrh [[TMP:w[0-9]+]], w1, [x0]
172 ; CHECK: mov w0, [[TMP]]
174 %extval = zext i16 %val to i64
175 %success = call i32 @llvm.aarch64.stxr.p0i16(i64 %extval, i16* %addr)
179 define i32 @test_stxr_32(i32* %addr, i32 %val) {
180 ; CHECK-LABEL: test_stxr_32:
181 ; CHECK: stxr [[TMP:w[0-9]+]], w1, [x0]
182 ; CHECK: mov w0, [[TMP]]
184 %extval = zext i32 %val to i64
185 %success = call i32 @llvm.aarch64.stxr.p0i32(i64 %extval, i32* %addr)
189 define i32 @test_stxr_64(i64* %addr, i64 %val) {
190 ; CHECK-LABEL: test_stxr_64:
191 ; CHECK: stxr [[TMP:w[0-9]+]], x1, [x0]
192 ; CHECK: mov w0, [[TMP]]
194 %success = call i32 @llvm.aarch64.stxr.p0i64(i64 %val, i64* %addr)
198 declare i32 @llvm.aarch64.stlxr.p0i8(i64, i8*)
199 declare i32 @llvm.aarch64.stlxr.p0i16(i64, i16*)
200 declare i32 @llvm.aarch64.stlxr.p0i32(i64, i32*)
201 declare i32 @llvm.aarch64.stlxr.p0i64(i64, i64*)
203 define i32 @test_stlxr_8(i8* %addr, i8 %val) {
204 ; CHECK-LABEL: test_stlxr_8:
205 ; CHECK: stlxrb [[TMP:w[0-9]+]], w1, [x0]
206 ; CHECK: mov w0, [[TMP]]
208 %extval = zext i8 %val to i64
209 %success = call i32 @llvm.aarch64.stlxr.p0i8(i64 %extval, i8* %addr)
213 define i32 @test_stlxr_16(i16* %addr, i16 %val) {
214 ; CHECK-LABEL: test_stlxr_16:
215 ; CHECK: stlxrh [[TMP:w[0-9]+]], w1, [x0]
216 ; CHECK: mov w0, [[TMP]]
218 %extval = zext i16 %val to i64
219 %success = call i32 @llvm.aarch64.stlxr.p0i16(i64 %extval, i16* %addr)
223 define i32 @test_stlxr_32(i32* %addr, i32 %val) {
224 ; CHECK-LABEL: test_stlxr_32:
225 ; CHECK: stlxr [[TMP:w[0-9]+]], w1, [x0]
226 ; CHECK: mov w0, [[TMP]]
228 %extval = zext i32 %val to i64
229 %success = call i32 @llvm.aarch64.stlxr.p0i32(i64 %extval, i32* %addr)
233 define i32 @test_stlxr_64(i64* %addr, i64 %val) {
234 ; CHECK-LABEL: test_stlxr_64:
235 ; CHECK: stlxr [[TMP:w[0-9]+]], x1, [x0]
236 ; CHECK: mov w0, [[TMP]]
238 %success = call i32 @llvm.aarch64.stlxr.p0i64(i64 %val, i64* %addr)
242 define {i8*, i1} @test_cmpxchg_ptr(i8** %addr, i8* %cmp, i8* %new) {
243 ; OUTLINE-ATOMICS: bl ___aarch64_cas4_acq_rel
244 ; CHECK-LABEL: test_cmpxchg_ptr:
245 ; CHECK: [[LOOP:LBB[0-9]+_[0-9]+]]:
246 ; CHECK: ldaxr [[OLD:w[0-9]+]], [x0]
247 ; CHECK: cmp [[OLD]], w1
248 ; CHECK: b.ne [[DONE:LBB[0-9]+_[0-9]+]]
249 ; CHECK: stlxr [[SUCCESS:w[0-9]+]], w2, [x0]
250 ; CHECK: cbnz [[SUCCESS]], [[LOOP]]
253 ; CHECK: mov w0, [[OLD]]
259 ; CHECK: mov w0, [[OLD]]
261 %res = cmpxchg i8** %addr, i8* %cmp, i8* %new acq_rel acquire