xref: /aosp_15_r20/external/llvm/test/CodeGen/AArch64/cmpxchg-idioms.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: llc -mtriple=aarch64-apple-ios7.0 -o - %s | FileCheck %s
2*9880d681SAndroid Build Coastguard Worker
3*9880d681SAndroid Build Coastguard Workerdefine i32 @test_return(i32* %p, i32 %oldval, i32 %newval) {
4*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test_return:
5*9880d681SAndroid Build Coastguard Worker
6*9880d681SAndroid Build Coastguard Worker; CHECK: [[LOOP:LBB[0-9]+_[0-9]+]]:
7*9880d681SAndroid Build Coastguard Worker; CHECK: ldaxr [[LOADED:w[0-9]+]], [x0]
8*9880d681SAndroid Build Coastguard Worker; CHECK: cmp [[LOADED]], w1
9*9880d681SAndroid Build Coastguard Worker; CHECK: b.ne [[FAILED:LBB[0-9]+_[0-9]+]]
10*9880d681SAndroid Build Coastguard Worker
11*9880d681SAndroid Build Coastguard Worker; CHECK: stlxr [[STATUS:w[0-9]+]], {{w[0-9]+}}, [x0]
12*9880d681SAndroid Build Coastguard Worker; CHECK: cbnz [[STATUS]], [[LOOP]]
13*9880d681SAndroid Build Coastguard Worker
14*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: cmp {{w[0-9]+}}, {{w[0-9]+}}
15*9880d681SAndroid Build Coastguard Worker; CHECK: orr w0, wzr, #0x1
16*9880d681SAndroid Build Coastguard Worker; CHECK: ret
17*9880d681SAndroid Build Coastguard Worker
18*9880d681SAndroid Build Coastguard Worker; CHECK: [[FAILED]]:
19*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: cmp {{w[0-9]+}}, {{w[0-9]+}}
20*9880d681SAndroid Build Coastguard Worker; CHECK: mov w0, wzr
21*9880d681SAndroid Build Coastguard Worker; CHECK: ret
22*9880d681SAndroid Build Coastguard Worker
23*9880d681SAndroid Build Coastguard Worker  %pair = cmpxchg i32* %p, i32 %oldval, i32 %newval seq_cst seq_cst
24*9880d681SAndroid Build Coastguard Worker  %success = extractvalue { i32, i1 } %pair, 1
25*9880d681SAndroid Build Coastguard Worker  %conv = zext i1 %success to i32
26*9880d681SAndroid Build Coastguard Worker  ret i32 %conv
27*9880d681SAndroid Build Coastguard Worker}
28*9880d681SAndroid Build Coastguard Worker
29*9880d681SAndroid Build Coastguard Workerdefine i1 @test_return_bool(i8* %value, i8 %oldValue, i8 %newValue) {
30*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test_return_bool:
31*9880d681SAndroid Build Coastguard Worker
32*9880d681SAndroid Build Coastguard Worker; CHECK: [[LOOP:LBB[0-9]+_[0-9]+]]:
33*9880d681SAndroid Build Coastguard Worker; CHECK: ldaxrb [[LOADED:w[0-9]+]], [x0]
34*9880d681SAndroid Build Coastguard Worker; CHECK: cmp [[LOADED]], w1, uxtb
35*9880d681SAndroid Build Coastguard Worker; CHECK: b.ne [[FAILED:LBB[0-9]+_[0-9]+]]
36*9880d681SAndroid Build Coastguard Worker
37*9880d681SAndroid Build Coastguard Worker; CHECK: stlxrb [[STATUS:w[0-9]+]], {{w[0-9]+}}, [x0]
38*9880d681SAndroid Build Coastguard Worker; CHECK: cbnz [[STATUS]], [[LOOP]]
39*9880d681SAndroid Build Coastguard Worker
40*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: cmp {{w[0-9]+}}, {{w[0-9]+}}
41*9880d681SAndroid Build Coastguard Worker  ; FIXME: DAG combine should be able to deal with this.
42*9880d681SAndroid Build Coastguard Worker; CHECK: orr [[TMP:w[0-9]+]], wzr, #0x1
43*9880d681SAndroid Build Coastguard Worker; CHECK: eor w0, [[TMP]], #0x1
44*9880d681SAndroid Build Coastguard Worker; CHECK: ret
45*9880d681SAndroid Build Coastguard Worker
46*9880d681SAndroid Build Coastguard Worker; CHECK: [[FAILED]]:
47*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: cmp {{w[0-9]+}}, {{w[0-9]+}}
48*9880d681SAndroid Build Coastguard Worker; CHECK: mov [[TMP:w[0-9]+]], wzr
49*9880d681SAndroid Build Coastguard Worker; CHECK: eor w0, [[TMP]], #0x1
50*9880d681SAndroid Build Coastguard Worker; CHECK: ret
51*9880d681SAndroid Build Coastguard Worker
52*9880d681SAndroid Build Coastguard Worker  %pair = cmpxchg i8* %value, i8 %oldValue, i8 %newValue acq_rel monotonic
53*9880d681SAndroid Build Coastguard Worker  %success = extractvalue { i8, i1 } %pair, 1
54*9880d681SAndroid Build Coastguard Worker  %failure = xor i1 %success, 1
55*9880d681SAndroid Build Coastguard Worker  ret i1 %failure
56*9880d681SAndroid Build Coastguard Worker}
57*9880d681SAndroid Build Coastguard Worker
58*9880d681SAndroid Build Coastguard Workerdefine void @test_conditional(i32* %p, i32 %oldval, i32 %newval) {
59*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test_conditional:
60*9880d681SAndroid Build Coastguard Worker
61*9880d681SAndroid Build Coastguard Worker; CHECK: [[LOOP:LBB[0-9]+_[0-9]+]]:
62*9880d681SAndroid Build Coastguard Worker; CHECK: ldaxr [[LOADED:w[0-9]+]], [x0]
63*9880d681SAndroid Build Coastguard Worker; CHECK: cmp [[LOADED]], w1
64*9880d681SAndroid Build Coastguard Worker; CHECK: b.ne [[FAILED:LBB[0-9]+_[0-9]+]]
65*9880d681SAndroid Build Coastguard Worker
66*9880d681SAndroid Build Coastguard Worker; CHECK: stlxr [[STATUS:w[0-9]+]], w2, [x0]
67*9880d681SAndroid Build Coastguard Worker; CHECK: cbnz [[STATUS]], [[LOOP]]
68*9880d681SAndroid Build Coastguard Worker
69*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: cmp {{w[0-9]+}}, {{w[0-9]+}}
70*9880d681SAndroid Build Coastguard Worker; CHECK: b _bar
71*9880d681SAndroid Build Coastguard Worker
72*9880d681SAndroid Build Coastguard Worker; CHECK: [[FAILED]]:
73*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: cmp {{w[0-9]+}}, {{w[0-9]+}}
74*9880d681SAndroid Build Coastguard Worker; CHECK: b _baz
75*9880d681SAndroid Build Coastguard Worker
76*9880d681SAndroid Build Coastguard Worker  %pair = cmpxchg i32* %p, i32 %oldval, i32 %newval seq_cst seq_cst
77*9880d681SAndroid Build Coastguard Worker  %success = extractvalue { i32, i1 } %pair, 1
78*9880d681SAndroid Build Coastguard Worker  br i1 %success, label %true, label %false
79*9880d681SAndroid Build Coastguard Worker
80*9880d681SAndroid Build Coastguard Workertrue:
81*9880d681SAndroid Build Coastguard Worker  tail call void @bar() #2
82*9880d681SAndroid Build Coastguard Worker  br label %end
83*9880d681SAndroid Build Coastguard Worker
84*9880d681SAndroid Build Coastguard Workerfalse:
85*9880d681SAndroid Build Coastguard Worker  tail call void @baz() #2
86*9880d681SAndroid Build Coastguard Worker  br label %end
87*9880d681SAndroid Build Coastguard Worker
88*9880d681SAndroid Build Coastguard Workerend:
89*9880d681SAndroid Build Coastguard Worker  ret void
90*9880d681SAndroid Build Coastguard Worker}
91*9880d681SAndroid Build Coastguard Worker
92*9880d681SAndroid Build Coastguard Workerdeclare void @bar()
93*9880d681SAndroid Build Coastguard Workerdeclare void @baz()
94