1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=aarch64-apple-ios7.0 -o - %s | FileCheck %s
3 ; RUN: llc -mtriple=aarch64-apple-ios7.0 -mattr=+outline-atomics -o - %s | FileCheck %s --check-prefix=OUTLINE-ATOMICS
5 define i32 @test_return(ptr %p, i32 %oldval, i32 %newval) {
6 ; CHECK-LABEL: test_return:
8 ; CHECK-NEXT: LBB0_1: ; %cmpxchg.start
9 ; CHECK-NEXT: ; =>This Inner Loop Header: Depth=1
10 ; CHECK-NEXT: ldaxr w8, [x0]
11 ; CHECK-NEXT: cmp w8, w1
12 ; CHECK-NEXT: b.ne LBB0_4
13 ; CHECK-NEXT: ; %bb.2: ; %cmpxchg.trystore
14 ; CHECK-NEXT: ; in Loop: Header=BB0_1 Depth=1
15 ; CHECK-NEXT: stlxr w8, w2, [x0]
16 ; CHECK-NEXT: cbnz w8, LBB0_1
17 ; CHECK-NEXT: ; %bb.3:
18 ; CHECK-NEXT: mov w0, #1 ; =0x1
20 ; CHECK-NEXT: LBB0_4: ; %cmpxchg.nostore
21 ; CHECK-NEXT: mov w0, wzr
25 ; OUTLINE-ATOMICS-LABEL: test_return:
26 ; OUTLINE-ATOMICS: ; %bb.0:
27 ; OUTLINE-ATOMICS-NEXT: stp x20, x19, [sp, #-32]! ; 16-byte Folded Spill
28 ; OUTLINE-ATOMICS-NEXT: stp x29, x30, [sp, #16] ; 16-byte Folded Spill
29 ; OUTLINE-ATOMICS-NEXT: .cfi_def_cfa_offset 32
30 ; OUTLINE-ATOMICS-NEXT: .cfi_offset w30, -8
31 ; OUTLINE-ATOMICS-NEXT: .cfi_offset w29, -16
32 ; OUTLINE-ATOMICS-NEXT: .cfi_offset w19, -24
33 ; OUTLINE-ATOMICS-NEXT: .cfi_offset w20, -32
34 ; OUTLINE-ATOMICS-NEXT: mov x8, x0
35 ; OUTLINE-ATOMICS-NEXT: mov w19, w1
36 ; OUTLINE-ATOMICS-NEXT: mov w0, w1
37 ; OUTLINE-ATOMICS-NEXT: mov w1, w2
38 ; OUTLINE-ATOMICS-NEXT: mov x2, x8
39 ; OUTLINE-ATOMICS-NEXT: bl ___aarch64_cas4_acq_rel
40 ; OUTLINE-ATOMICS-NEXT: ldp x29, x30, [sp, #16] ; 16-byte Folded Reload
41 ; OUTLINE-ATOMICS-NEXT: cmp w0, w19
42 ; OUTLINE-ATOMICS-NEXT: cset w0, eq
43 ; OUTLINE-ATOMICS-NEXT: ldp x20, x19, [sp], #32 ; 16-byte Folded Reload
44 ; OUTLINE-ATOMICS-NEXT: ret
45 %pair = cmpxchg ptr %p, i32 %oldval, i32 %newval seq_cst seq_cst
46 %success = extractvalue { i32, i1 } %pair, 1
47 %conv = zext i1 %success to i32
51 ; FIXME: DAG combine should be able to deal with this EOR better.
52 define i1 @test_return_bool(ptr %value, i8 %oldValue, i8 %newValue) {
53 ; CHECK-LABEL: test_return_bool:
55 ; CHECK-NEXT: and w8, w1, #0xff
56 ; CHECK-NEXT: ; kill: def $w2 killed $w2 def $x2
57 ; CHECK-NEXT: LBB1_1: ; %cmpxchg.start
58 ; CHECK-NEXT: ; =>This Inner Loop Header: Depth=1
59 ; CHECK-NEXT: ldaxrb w9, [x0]
60 ; CHECK-NEXT: cmp w9, w8
61 ; CHECK-NEXT: b.ne LBB1_4
62 ; CHECK-NEXT: ; %bb.2: ; %cmpxchg.trystore
63 ; CHECK-NEXT: ; in Loop: Header=BB1_1 Depth=1
64 ; CHECK-NEXT: stlxrb w9, w2, [x0]
65 ; CHECK-NEXT: cbnz w9, LBB1_1
66 ; CHECK-NEXT: ; %bb.3:
67 ; CHECK-NEXT: mov w8, #1 ; =0x1
68 ; CHECK-NEXT: eor w0, w8, #0x1
70 ; CHECK-NEXT: LBB1_4: ; %cmpxchg.nostore
71 ; CHECK-NEXT: eor w0, wzr, #0x1
75 ; OUTLINE-ATOMICS-LABEL: test_return_bool:
76 ; OUTLINE-ATOMICS: ; %bb.0:
77 ; OUTLINE-ATOMICS-NEXT: stp x20, x19, [sp, #-32]! ; 16-byte Folded Spill
78 ; OUTLINE-ATOMICS-NEXT: stp x29, x30, [sp, #16] ; 16-byte Folded Spill
79 ; OUTLINE-ATOMICS-NEXT: .cfi_def_cfa_offset 32
80 ; OUTLINE-ATOMICS-NEXT: .cfi_offset w30, -8
81 ; OUTLINE-ATOMICS-NEXT: .cfi_offset w29, -16
82 ; OUTLINE-ATOMICS-NEXT: .cfi_offset w19, -24
83 ; OUTLINE-ATOMICS-NEXT: .cfi_offset w20, -32
84 ; OUTLINE-ATOMICS-NEXT: mov x8, x0
85 ; OUTLINE-ATOMICS-NEXT: mov w19, w1
86 ; OUTLINE-ATOMICS-NEXT: mov w0, w1
87 ; OUTLINE-ATOMICS-NEXT: mov w1, w2
88 ; OUTLINE-ATOMICS-NEXT: mov x2, x8
89 ; OUTLINE-ATOMICS-NEXT: bl ___aarch64_cas1_acq_rel
90 ; OUTLINE-ATOMICS-NEXT: cmp w0, w19, uxtb
91 ; OUTLINE-ATOMICS-NEXT: ldp x29, x30, [sp, #16] ; 16-byte Folded Reload
92 ; OUTLINE-ATOMICS-NEXT: cset w8, eq
93 ; OUTLINE-ATOMICS-NEXT: eor w0, w8, #0x1
94 ; OUTLINE-ATOMICS-NEXT: ldp x20, x19, [sp], #32 ; 16-byte Folded Reload
95 ; OUTLINE-ATOMICS-NEXT: ret
96 %pair = cmpxchg ptr %value, i8 %oldValue, i8 %newValue acq_rel monotonic
97 %success = extractvalue { i8, i1 } %pair, 1
98 %failure = xor i1 %success, 1
102 define void @test_conditional(ptr %p, i32 %oldval, i32 %newval) {
103 ; CHECK-LABEL: test_conditional:
105 ; CHECK-NEXT: LBB2_1: ; %cmpxchg.start
106 ; CHECK-NEXT: ; =>This Inner Loop Header: Depth=1
107 ; CHECK-NEXT: ldaxr w8, [x0]
108 ; CHECK-NEXT: cmp w8, w1
109 ; CHECK-NEXT: b.ne LBB2_4
110 ; CHECK-NEXT: ; %bb.2: ; %cmpxchg.trystore
111 ; CHECK-NEXT: ; in Loop: Header=BB2_1 Depth=1
112 ; CHECK-NEXT: stlxr w8, w2, [x0]
113 ; CHECK-NEXT: cbnz w8, LBB2_1
114 ; CHECK-NEXT: ; %bb.3: ; %true
116 ; CHECK-NEXT: LBB2_4: ; %cmpxchg.nostore
120 ; OUTLINE-ATOMICS-LABEL: test_conditional:
121 ; OUTLINE-ATOMICS: ; %bb.0:
122 ; OUTLINE-ATOMICS-NEXT: stp x20, x19, [sp, #-32]! ; 16-byte Folded Spill
123 ; OUTLINE-ATOMICS-NEXT: stp x29, x30, [sp, #16] ; 16-byte Folded Spill
124 ; OUTLINE-ATOMICS-NEXT: .cfi_def_cfa_offset 32
125 ; OUTLINE-ATOMICS-NEXT: .cfi_offset w30, -8
126 ; OUTLINE-ATOMICS-NEXT: .cfi_offset w29, -16
127 ; OUTLINE-ATOMICS-NEXT: .cfi_offset w19, -24
128 ; OUTLINE-ATOMICS-NEXT: .cfi_offset w20, -32
129 ; OUTLINE-ATOMICS-NEXT: mov x8, x0
130 ; OUTLINE-ATOMICS-NEXT: mov w19, w1
131 ; OUTLINE-ATOMICS-NEXT: mov w0, w1
132 ; OUTLINE-ATOMICS-NEXT: mov w1, w2
133 ; OUTLINE-ATOMICS-NEXT: mov x2, x8
134 ; OUTLINE-ATOMICS-NEXT: bl ___aarch64_cas4_acq_rel
135 ; OUTLINE-ATOMICS-NEXT: cmp w0, w19
136 ; OUTLINE-ATOMICS-NEXT: b.ne LBB2_2
137 ; OUTLINE-ATOMICS-NEXT: ; %bb.1: ; %true
138 ; OUTLINE-ATOMICS-NEXT: ldp x29, x30, [sp, #16] ; 16-byte Folded Reload
139 ; OUTLINE-ATOMICS-NEXT: ldp x20, x19, [sp], #32 ; 16-byte Folded Reload
140 ; OUTLINE-ATOMICS-NEXT: b _bar
141 ; OUTLINE-ATOMICS-NEXT: LBB2_2: ; %false
142 ; OUTLINE-ATOMICS-NEXT: ldp x29, x30, [sp, #16] ; 16-byte Folded Reload
143 ; OUTLINE-ATOMICS-NEXT: ldp x20, x19, [sp], #32 ; 16-byte Folded Reload
144 ; OUTLINE-ATOMICS-NEXT: b _baz
145 %pair = cmpxchg ptr %p, i32 %oldval, i32 %newval seq_cst seq_cst
146 %success = extractvalue { i32, i1 } %pair, 1
147 br i1 %success, label %true, label %false
150 tail call void @bar() #2
154 tail call void @baz() #2
164 ; verify the preheader is simplified by simplifycfg.
165 define i1 @test_conditional2(i32 %a, i32 %b, ptr %c) {
166 ; CHECK-LABEL: test_conditional2:
167 ; CHECK: ; %bb.0: ; %entry
168 ; CHECK-NEXT: stp x22, x21, [sp, #-48]! ; 16-byte Folded Spill
169 ; CHECK-NEXT: stp x20, x19, [sp, #16] ; 16-byte Folded Spill
170 ; CHECK-NEXT: stp x29, x30, [sp, #32] ; 16-byte Folded Spill
171 ; CHECK-NEXT: .cfi_def_cfa_offset 48
172 ; CHECK-NEXT: .cfi_offset w30, -8
173 ; CHECK-NEXT: .cfi_offset w29, -16
174 ; CHECK-NEXT: .cfi_offset w19, -24
175 ; CHECK-NEXT: .cfi_offset w20, -32
176 ; CHECK-NEXT: .cfi_offset w21, -40
177 ; CHECK-NEXT: .cfi_offset w22, -48
178 ; CHECK-NEXT: mov x19, x2
179 ; CHECK-NEXT: mov w20, w1
180 ; CHECK-NEXT: mov w21, w0
181 ; CHECK-NEXT: LBB3_1: ; %cmpxchg.start
182 ; CHECK-NEXT: ; =>This Inner Loop Header: Depth=1
183 ; CHECK-NEXT: ldaxr w8, [x19]
184 ; CHECK-NEXT: cmp w8, w21
185 ; CHECK-NEXT: b.ne LBB3_4
186 ; CHECK-NEXT: ; %bb.2: ; %cmpxchg.trystore
187 ; CHECK-NEXT: ; in Loop: Header=BB3_1 Depth=1
188 ; CHECK-NEXT: stlxr w8, w20, [x19]
189 ; CHECK-NEXT: cbnz w8, LBB3_1
190 ; CHECK-NEXT: ; %bb.3:
191 ; CHECK-NEXT: mov w8, #1 ; =0x1
192 ; CHECK-NEXT: b LBB3_5
193 ; CHECK-NEXT: LBB3_4: ; %cmpxchg.nostore
194 ; CHECK-NEXT: mov w8, wzr
196 ; CHECK-NEXT: LBB3_5: ; %for.cond.preheader
197 ; CHECK-NEXT: mov w22, #2 ; =0x2
198 ; CHECK-NEXT: LBB3_6: ; %for.cond
199 ; CHECK-NEXT: ; =>This Inner Loop Header: Depth=1
200 ; CHECK-NEXT: cbz w22, LBB3_9
201 ; CHECK-NEXT: ; %bb.7: ; %for.body
202 ; CHECK-NEXT: ; in Loop: Header=BB3_6 Depth=1
203 ; CHECK-NEXT: sub w22, w22, #1
204 ; CHECK-NEXT: orr w9, w21, w20
205 ; CHECK-NEXT: ldr w10, [x19, w22, sxtw #2]
206 ; CHECK-NEXT: cmp w9, w10
207 ; CHECK-NEXT: b.eq LBB3_6
208 ; CHECK-NEXT: ; %bb.8: ; %if.then
209 ; CHECK-NEXT: ; in Loop: Header=BB3_6 Depth=1
210 ; CHECK-NEXT: sxtw x8, w22
211 ; CHECK-NEXT: str w9, [x19, x8, lsl #2]
212 ; CHECK-NEXT: bl _foo
213 ; CHECK-NEXT: mov w8, wzr
214 ; CHECK-NEXT: b LBB3_6
215 ; CHECK-NEXT: LBB3_9: ; %for.cond.cleanup
216 ; CHECK-NEXT: ldp x29, x30, [sp, #32] ; 16-byte Folded Reload
217 ; CHECK-NEXT: and w0, w8, #0x1
218 ; CHECK-NEXT: ldp x20, x19, [sp, #16] ; 16-byte Folded Reload
219 ; CHECK-NEXT: ldp x22, x21, [sp], #48 ; 16-byte Folded Reload
222 ; OUTLINE-ATOMICS-LABEL: test_conditional2:
223 ; OUTLINE-ATOMICS: ; %bb.0: ; %entry
224 ; OUTLINE-ATOMICS-NEXT: stp x22, x21, [sp, #-48]! ; 16-byte Folded Spill
225 ; OUTLINE-ATOMICS-NEXT: stp x20, x19, [sp, #16] ; 16-byte Folded Spill
226 ; OUTLINE-ATOMICS-NEXT: stp x29, x30, [sp, #32] ; 16-byte Folded Spill
227 ; OUTLINE-ATOMICS-NEXT: .cfi_def_cfa_offset 48
228 ; OUTLINE-ATOMICS-NEXT: .cfi_offset w30, -8
229 ; OUTLINE-ATOMICS-NEXT: .cfi_offset w29, -16
230 ; OUTLINE-ATOMICS-NEXT: .cfi_offset w19, -24
231 ; OUTLINE-ATOMICS-NEXT: .cfi_offset w20, -32
232 ; OUTLINE-ATOMICS-NEXT: .cfi_offset w21, -40
233 ; OUTLINE-ATOMICS-NEXT: .cfi_offset w22, -48
234 ; OUTLINE-ATOMICS-NEXT: mov x19, x2
235 ; OUTLINE-ATOMICS-NEXT: mov w20, w1
236 ; OUTLINE-ATOMICS-NEXT: mov w21, w0
237 ; OUTLINE-ATOMICS-NEXT: bl ___aarch64_cas4_acq_rel
238 ; OUTLINE-ATOMICS-NEXT: cmp w0, w21
239 ; OUTLINE-ATOMICS-NEXT: mov w22, #2 ; =0x2
240 ; OUTLINE-ATOMICS-NEXT: cset w8, eq
241 ; OUTLINE-ATOMICS-NEXT: LBB3_1: ; %for.cond
242 ; OUTLINE-ATOMICS-NEXT: ; =>This Inner Loop Header: Depth=1
243 ; OUTLINE-ATOMICS-NEXT: cbz w22, LBB3_4
244 ; OUTLINE-ATOMICS-NEXT: ; %bb.2: ; %for.body
245 ; OUTLINE-ATOMICS-NEXT: ; in Loop: Header=BB3_1 Depth=1
246 ; OUTLINE-ATOMICS-NEXT: sub w22, w22, #1
247 ; OUTLINE-ATOMICS-NEXT: orr w9, w21, w20
248 ; OUTLINE-ATOMICS-NEXT: ldr w10, [x19, w22, sxtw #2]
249 ; OUTLINE-ATOMICS-NEXT: cmp w9, w10
250 ; OUTLINE-ATOMICS-NEXT: b.eq LBB3_1
251 ; OUTLINE-ATOMICS-NEXT: ; %bb.3: ; %if.then
252 ; OUTLINE-ATOMICS-NEXT: ; in Loop: Header=BB3_1 Depth=1
253 ; OUTLINE-ATOMICS-NEXT: sxtw x8, w22
254 ; OUTLINE-ATOMICS-NEXT: str w9, [x19, x8, lsl #2]
255 ; OUTLINE-ATOMICS-NEXT: bl _foo
256 ; OUTLINE-ATOMICS-NEXT: mov w8, wzr
257 ; OUTLINE-ATOMICS-NEXT: b LBB3_1
258 ; OUTLINE-ATOMICS-NEXT: LBB3_4: ; %for.cond.cleanup
259 ; OUTLINE-ATOMICS-NEXT: ldp x29, x30, [sp, #32] ; 16-byte Folded Reload
260 ; OUTLINE-ATOMICS-NEXT: and w0, w8, #0x1
261 ; OUTLINE-ATOMICS-NEXT: ldp x20, x19, [sp, #16] ; 16-byte Folded Reload
262 ; OUTLINE-ATOMICS-NEXT: ldp x22, x21, [sp], #48 ; 16-byte Folded Reload
263 ; OUTLINE-ATOMICS-NEXT: ret
265 %pair = cmpxchg ptr %c, i32 %a, i32 %b seq_cst seq_cst
266 %success = extractvalue { i32, i1 } %pair, 1
269 for.cond: ; preds = %if.end, %entry
270 %i.0 = phi i32 [ 2, %entry ], [ %dec, %if.end ]
271 %changed.0.off0 = phi i1 [ %success, %entry ], [ %changed.1.off0, %if.end ]
272 %dec = add nsw i32 %i.0, -1
273 %tobool = icmp eq i32 %i.0, 0
274 br i1 %tobool, label %for.cond.cleanup, label %for.body
276 for.cond.cleanup: ; preds = %for.cond
277 %changed.0.off0.lcssa = phi i1 [ %changed.0.off0, %for.cond ]
278 ret i1 %changed.0.off0.lcssa
280 for.body: ; preds = %for.cond
282 %idxprom = sext i32 %dec to i64
283 %arrayidx = getelementptr inbounds i32, ptr %c, i64 %idxprom
284 %0 = load i32, ptr %arrayidx, align 4
285 %cmp = icmp eq i32 %or, %0
286 br i1 %cmp, label %if.end, label %if.then
288 if.then: ; preds = %for.body
289 store i32 %or, ptr %arrayidx, align 4
290 tail call void @foo()
293 if.end: ; preds = %for.body, %if.then
294 %changed.1.off0 = phi i1 [ false, %if.then ], [ %changed.0.off0, %for.body ]