• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: llc -mtriple=thumbv7s-apple-ios7.0 -o - %s | FileCheck %s
2
3define i32 @test_return(i32* %p, i32 %oldval, i32 %newval) {
4; CHECK-LABEL: test_return:
5
6; CHECK: dmb ishst
7
8; CHECK: [[LOOP:LBB[0-9]+_[0-9]+]]:
9; CHECK: ldrex [[LOADED:r[0-9]+]], [r0]
10; CHECK: cmp [[LOADED]], r1
11; CHECK: bne [[FAILED:LBB[0-9]+_[0-9]+]]
12
13; CHECK: strex [[STATUS:r[0-9]+]], {{r[0-9]+}}, [r0]
14; CHECK: cmp [[STATUS]], #0
15; CHECK: bne [[LOOP]]
16
17; CHECK-NOT: cmp {{r[0-9]+}}, {{r[0-9]+}}
18; CHECK: dmb ish
19; CHECK: movs r0, #1
20; CHECK: bx lr
21
22; CHECK: [[FAILED]]:
23; CHECK-NOT: cmp {{r[0-9]+}}, {{r[0-9]+}}
24; CHECK: dmb ish
25; CHECK: movs r0, #0
26; CHECK: bx lr
27
28  %pair = cmpxchg i32* %p, i32 %oldval, i32 %newval seq_cst seq_cst
29  %success = extractvalue { i32, i1 } %pair, 1
30  %conv = zext i1 %success to i32
31  ret i32 %conv
32}
33
34define i1 @test_return_bool(i8* %value, i8 %oldValue, i8 %newValue) {
35; CHECK-LABEL: test_return_bool:
36
37; CHECK: dmb ishst
38; CHECK: uxtb [[OLDBYTE:r[0-9]+]], r1
39
40; CHECK: [[LOOP:LBB[0-9]+_[0-9]+]]:
41; CHECK: ldrexb [[LOADED:r[0-9]+]], [r0]
42; CHECK: cmp [[LOADED]], [[OLDBYTE]]
43; CHECK: bne [[FAIL:LBB[0-9]+_[0-9]+]]
44
45; CHECK: strexb [[STATUS:r[0-9]+]], {{r[0-9]+}}, [r0]
46; CHECK: cmp [[STATUS]], #0
47; CHECK: bne [[LOOP]]
48
49  ; FIXME: this eor is redundant. Need to teach DAG combine that.
50; CHECK-NOT: cmp {{r[0-9]+}}, {{r[0-9]+}}
51; CHECK: movs [[TMP:r[0-9]+]], #1
52; CHECK: eor r0, [[TMP]], #1
53; CHECK: bx lr
54
55; CHECK: [[FAIL]]:
56; CHECK: movs [[TMP:r[0-9]+]], #0
57; CHECK: eor r0, [[TMP]], #1
58; CHECK: bx lr
59
60
61  %pair = cmpxchg i8* %value, i8 %oldValue, i8 %newValue acq_rel monotonic
62  %success = extractvalue { i8, i1 } %pair, 1
63  %failure = xor i1 %success, 1
64  ret i1 %failure
65}
66
67define void @test_conditional(i32* %p, i32 %oldval, i32 %newval) {
68; CHECK-LABEL: test_conditional:
69
70; CHECK: dmb ishst
71
72; CHECK: [[LOOP:LBB[0-9]+_[0-9]+]]:
73; CHECK: ldrex [[LOADED:r[0-9]+]], [r0]
74; CHECK: cmp [[LOADED]], r1
75; CHECK: bne [[FAILED:LBB[0-9]+_[0-9]+]]
76
77; CHECK: strex [[STATUS:r[0-9]+]], r2, [r0]
78; CHECK: cmp [[STATUS]], #0
79; CHECK: bne [[LOOP]]
80
81; CHECK-NOT: cmp {{r[0-9]+}}, {{r[0-9]+}}
82; CHECK: dmb ish
83; CHECK: b.w _bar
84
85; CHECK: [[FAILED]]:
86; CHECK-NOT: cmp {{r[0-9]+}}, {{r[0-9]+}}
87; CHECK: dmb ish
88; CHECK: b.w _baz
89
90  %pair = cmpxchg i32* %p, i32 %oldval, i32 %newval seq_cst seq_cst
91  %success = extractvalue { i32, i1 } %pair, 1
92  br i1 %success, label %true, label %false
93
94true:
95  tail call void @bar() #2
96  br label %end
97
98false:
99  tail call void @baz() #2
100  br label %end
101
102end:
103  ret void
104}
105
106declare void @bar()
107declare void @baz()
108