1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=aarch64-apple-ios7.0 -aarch64-enable-sink-fold=true -o - %s | FileCheck %s
3 ; RUN: llc -mtriple=aarch64-apple-ios7.0 -mattr=+outline-atomics -aarch64-enable-sink-fold=true -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: str w9, [x19, w22, sxtw #2]
211 ; CHECK-NEXT: bl _foo
212 ; CHECK-NEXT: mov w8, wzr
213 ; CHECK-NEXT: b LBB3_6
214 ; CHECK-NEXT: LBB3_9: ; %for.cond.cleanup
215 ; CHECK-NEXT: ldp x29, x30, [sp, #32] ; 16-byte Folded Reload
216 ; CHECK-NEXT: and w0, w8, #0x1
217 ; CHECK-NEXT: ldp x20, x19, [sp, #16] ; 16-byte Folded Reload
218 ; CHECK-NEXT: ldp x22, x21, [sp], #48 ; 16-byte Folded Reload
221 ; OUTLINE-ATOMICS-LABEL: test_conditional2:
222 ; OUTLINE-ATOMICS: ; %bb.0: ; %entry
223 ; OUTLINE-ATOMICS-NEXT: stp x22, x21, [sp, #-48]! ; 16-byte Folded Spill
224 ; OUTLINE-ATOMICS-NEXT: stp x20, x19, [sp, #16] ; 16-byte Folded Spill
225 ; OUTLINE-ATOMICS-NEXT: stp x29, x30, [sp, #32] ; 16-byte Folded Spill
226 ; OUTLINE-ATOMICS-NEXT: .cfi_def_cfa_offset 48
227 ; OUTLINE-ATOMICS-NEXT: .cfi_offset w30, -8
228 ; OUTLINE-ATOMICS-NEXT: .cfi_offset w29, -16
229 ; OUTLINE-ATOMICS-NEXT: .cfi_offset w19, -24
230 ; OUTLINE-ATOMICS-NEXT: .cfi_offset w20, -32
231 ; OUTLINE-ATOMICS-NEXT: .cfi_offset w21, -40
232 ; OUTLINE-ATOMICS-NEXT: .cfi_offset w22, -48
233 ; OUTLINE-ATOMICS-NEXT: mov x19, x2
234 ; OUTLINE-ATOMICS-NEXT: mov w20, w1
235 ; OUTLINE-ATOMICS-NEXT: mov w21, w0
236 ; OUTLINE-ATOMICS-NEXT: bl ___aarch64_cas4_acq_rel
237 ; OUTLINE-ATOMICS-NEXT: cmp w0, w21
238 ; OUTLINE-ATOMICS-NEXT: mov w22, #2 ; =0x2
239 ; OUTLINE-ATOMICS-NEXT: cset w8, eq
240 ; OUTLINE-ATOMICS-NEXT: LBB3_1: ; %for.cond
241 ; OUTLINE-ATOMICS-NEXT: ; =>This Inner Loop Header: Depth=1
242 ; OUTLINE-ATOMICS-NEXT: cbz w22, LBB3_4
243 ; OUTLINE-ATOMICS-NEXT: ; %bb.2: ; %for.body
244 ; OUTLINE-ATOMICS-NEXT: ; in Loop: Header=BB3_1 Depth=1
245 ; OUTLINE-ATOMICS-NEXT: sub w22, w22, #1
246 ; OUTLINE-ATOMICS-NEXT: orr w9, w21, w20
247 ; OUTLINE-ATOMICS-NEXT: ldr w10, [x19, w22, sxtw #2]
248 ; OUTLINE-ATOMICS-NEXT: cmp w9, w10
249 ; OUTLINE-ATOMICS-NEXT: b.eq LBB3_1
250 ; OUTLINE-ATOMICS-NEXT: ; %bb.3: ; %if.then
251 ; OUTLINE-ATOMICS-NEXT: ; in Loop: Header=BB3_1 Depth=1
252 ; OUTLINE-ATOMICS-NEXT: str w9, [x19, w22, sxtw #2]
253 ; OUTLINE-ATOMICS-NEXT: bl _foo
254 ; OUTLINE-ATOMICS-NEXT: mov w8, wzr
255 ; OUTLINE-ATOMICS-NEXT: b LBB3_1
256 ; OUTLINE-ATOMICS-NEXT: LBB3_4: ; %for.cond.cleanup
257 ; OUTLINE-ATOMICS-NEXT: ldp x29, x30, [sp, #32] ; 16-byte Folded Reload
258 ; OUTLINE-ATOMICS-NEXT: and w0, w8, #0x1
259 ; OUTLINE-ATOMICS-NEXT: ldp x20, x19, [sp, #16] ; 16-byte Folded Reload
260 ; OUTLINE-ATOMICS-NEXT: ldp x22, x21, [sp], #48 ; 16-byte Folded Reload
261 ; OUTLINE-ATOMICS-NEXT: ret
263 %pair = cmpxchg ptr %c, i32 %a, i32 %b seq_cst seq_cst
264 %success = extractvalue { i32, i1 } %pair, 1
267 for.cond: ; preds = %if.end, %entry
268 %i.0 = phi i32 [ 2, %entry ], [ %dec, %if.end ]
269 %changed.0.off0 = phi i1 [ %success, %entry ], [ %changed.1.off0, %if.end ]
270 %dec = add nsw i32 %i.0, -1
271 %tobool = icmp eq i32 %i.0, 0
272 br i1 %tobool, label %for.cond.cleanup, label %for.body
274 for.cond.cleanup: ; preds = %for.cond
275 %changed.0.off0.lcssa = phi i1 [ %changed.0.off0, %for.cond ]
276 ret i1 %changed.0.off0.lcssa
278 for.body: ; preds = %for.cond
280 %idxprom = sext i32 %dec to i64
281 %arrayidx = getelementptr inbounds i32, ptr %c, i64 %idxprom
282 %0 = load i32, ptr %arrayidx, align 4
283 %cmp = icmp eq i32 %or, %0
284 br i1 %cmp, label %if.end, label %if.then
286 if.then: ; preds = %for.body
287 store i32 %or, ptr %arrayidx, align 4
288 tail call void @foo()
291 if.end: ; preds = %for.body, %if.then
292 %changed.1.off0 = phi i1 [ false, %if.then ], [ %changed.0.off0, %for.body ]