1 ; RUN: llc -mtriple=aarch64-apple-ios7.0 -o - %s | FileCheck %s
3 define i32 @test_return(i32* %p, i32 %oldval, i32 %newval) {
4 ; CHECK-LABEL: test_return:
6 ; CHECK: [[LOOP:LBB[0-9]+_[0-9]+]]:
7 ; CHECK: ldaxr [[LOADED:w[0-9]+]], [x0]
8 ; CHECK: cmp [[LOADED]], w1
9 ; CHECK: b.ne [[FAILED:LBB[0-9]+_[0-9]+]]
11 ; CHECK: stlxr [[STATUS:w[0-9]+]], {{w[0-9]+}}, [x0]
12 ; CHECK: cbnz [[STATUS]], [[LOOP]]
14 ; CHECK-NOT: cmp {{w[0-9]+}}, {{w[0-9]+}}
19 ; CHECK-NOT: cmp {{w[0-9]+}}, {{w[0-9]+}}
23 %pair = cmpxchg i32* %p, i32 %oldval, i32 %newval seq_cst seq_cst
24 %success = extractvalue { i32, i1 } %pair, 1
25 %conv = zext i1 %success to i32
29 define i1 @test_return_bool(i8* %value, i8 %oldValue, i8 %newValue) {
30 ; CHECK-LABEL: test_return_bool:
32 ; CHECK: [[LOOP:LBB[0-9]+_[0-9]+]]:
33 ; CHECK: ldaxrb [[LOADED:w[0-9]+]], [x0]
34 ; CHECK: cmp [[LOADED]], w1, uxtb
35 ; CHECK: b.ne [[FAILED:LBB[0-9]+_[0-9]+]]
37 ; CHECK: stlxrb [[STATUS:w[0-9]+]], {{w[0-9]+}}, [x0]
38 ; CHECK: cbnz [[STATUS]], [[LOOP]]
40 ; CHECK-NOT: cmp {{w[0-9]+}}, {{w[0-9]+}}
41 ; FIXME: DAG combine should be able to deal with this.
42 ; CHECK: mov [[TMP:w[0-9]+]], #1
43 ; CHECK: eor w0, [[TMP]], #0x1
47 ; CHECK-NOT: cmp {{w[0-9]+}}, {{w[0-9]+}}
48 ; CHECK: eor w0, wzr, #0x1
51 %pair = cmpxchg i8* %value, i8 %oldValue, i8 %newValue acq_rel monotonic
52 %success = extractvalue { i8, i1 } %pair, 1
53 %failure = xor i1 %success, 1
57 define void @test_conditional(i32* %p, i32 %oldval, i32 %newval) {
58 ; CHECK-LABEL: test_conditional:
60 ; CHECK: [[LOOP:LBB[0-9]+_[0-9]+]]:
61 ; CHECK: ldaxr [[LOADED:w[0-9]+]], [x0]
62 ; CHECK: cmp [[LOADED]], w1
63 ; CHECK: b.ne [[FAILED:LBB[0-9]+_[0-9]+]]
65 ; CHECK: stlxr [[STATUS:w[0-9]+]], w2, [x0]
66 ; CHECK: cbnz [[STATUS]], [[LOOP]]
68 ; CHECK-NOT: cmp {{w[0-9]+}}, {{w[0-9]+}}
72 ; CHECK-NOT: cmp {{w[0-9]+}}, {{w[0-9]+}}
75 %pair = cmpxchg i32* %p, i32 %oldval, i32 %newval seq_cst seq_cst
76 %success = extractvalue { i32, i1 } %pair, 1
77 br i1 %success, label %true, label %false
80 tail call void @bar() #2
84 tail call void @baz() #2
94 define i1 @test_conditional2(i32 %a, i32 %b, i32* %c) {
95 ; CHECK-LABEL: test_conditional2:
96 ; CHECK: [[LOOP:LBB[0-9]+_[0-9]+]]:
97 ; CHECK: ldaxr [[LOADED:w[0-9]+]], [x19]
98 ; CHECK: cmp [[LOADED]], w21
99 ; CHECK: b.ne [[FAILED:LBB[0-9]+_[0-9]+]]
101 ; CHECK: stlxr [[STATUS:w[0-9]+]], w20, [x19]
102 ; CHECK: cbnz [[STATUS]], [[LOOP]]
103 ; CHECK: mov [[STATUS]], #1
104 ; CHECK: b [[PH:LBB[0-9]+_[0-9]+]]
107 ; CHECK-NOT: cmp {{w[0-9]+}}, {{w[0-9]+}}
109 ; verify the preheader is simplified by simplifycfg.
112 ; CHECK-NOT: mov w22, #4
113 ; CHECK-NOT: cmn w22, #4
114 ; CHECK: [[LOOP2:LBB[0-9]+_[0-9]+]]: ; %for.cond
115 ; CHECK-NOT: b.ne [[LOOP2]]
116 ; CHECK-NOT: b {{LBB[0-9]+_[0-9]+}}
119 %pair = cmpxchg i32* %c, i32 %a, i32 %b seq_cst seq_cst
120 %success = extractvalue { i32, i1 } %pair, 1
123 for.cond: ; preds = %if.end, %entry
124 %i.0 = phi i32 [ 2, %entry ], [ %dec, %if.end ]
125 %changed.0.off0 = phi i1 [ %success, %entry ], [ %changed.1.off0, %if.end ]
126 %dec = add nsw i32 %i.0, -1
127 %tobool = icmp eq i32 %i.0, 0
128 br i1 %tobool, label %for.cond.cleanup, label %for.body
130 for.cond.cleanup: ; preds = %for.cond
131 %changed.0.off0.lcssa = phi i1 [ %changed.0.off0, %for.cond ]
132 ret i1 %changed.0.off0.lcssa
134 for.body: ; preds = %for.cond
136 %idxprom = sext i32 %dec to i64
137 %arrayidx = getelementptr inbounds i32, i32* %c, i64 %idxprom
138 %0 = load i32, i32* %arrayidx, align 4
139 %cmp = icmp eq i32 %or, %0
140 br i1 %cmp, label %if.end, label %if.then
142 if.then: ; preds = %for.body
143 store i32 %or, i32* %arrayidx, align 4
144 tail call void @foo()
147 if.end: ; preds = %for.body, %if.then
148 %changed.1.off0 = phi i1 [ false, %if.then ], [ %changed.0.off0, %for.body ]