1 ; RUN: llc -verify-machineinstrs -mtriple=armv7-linux-gnu -O0 %s -o - | FileCheck %s
2 ; RUN: llc -verify-machineinstrs -mtriple=thumbv8-linux-gnu -O0 %s -o - | FileCheck %s
3 ; RUN: llc -verify-machineinstrs -mtriple=thumbv6m-none-eabi -O0 %s -o - | FileCheck %s --check-prefix=CHECK-T1
8 define { i8, i1 } @test_cmpxchg_8(i8* %addr, i8 %desired, i8 %new) nounwind {
9 ; CHECK-LABEL: test_cmpxchg_8:
10 ; CHECK-DAG: mov [[ADDR:r[0-9]+]], r0
11 ; CHECK-DAG: mov [[NEW:r[0-9]+]], r2
13 ; CHECK: uxtb [[DESIRED:r[0-9]+]], [[DESIRED]]
14 ; CHECK: [[RETRY:.LBB[0-9]+_[0-9]+]]:
15 ; CHECK: ldrexb [[OLD:[lr0-9]+]], {{\[}}[[ADDR]]{{\]}}
16 ; CHECK: cmp [[OLD]], [[DESIRED]]
17 ; CHECK: bne [[DONE:.LBB[0-9]+_[0-9]+]]
18 ; CHECK: strexb [[STATUS:r[0-9]+]], [[NEW]], {{\[}}[[ADDR]]{{\]}}
19 ; CHECK: cmp{{(\.w)?}} [[STATUS]], #0
20 ; CHECK: bne [[RETRY]]
22 ; Materialisation of a boolean is done with sub/clz/lsr
23 ; CHECK: uxtb [[CMP1:r[0-9]+]], [[DESIRED]]
24 ; CHECK: sub{{(\.w|s)?}} [[CMP1]], [[OLD]], [[CMP1]]
25 ; CHECK: clz [[CMP2:r[0-9]+]], [[CMP1]]
26 ; CHECK: lsr{{(s)?}} {{r[0-9]+}}, [[CMP2]], #5
28 %res = cmpxchg i8* %addr, i8 %desired, i8 %new seq_cst monotonic
32 define { i16, i1 } @test_cmpxchg_16(i16* %addr, i16 %desired, i16 %new) nounwind {
33 ; CHECK-LABEL: test_cmpxchg_16:
34 ; CHECK-DAG: mov [[ADDR:r[0-9]+]], r0
35 ; CHECK-DAG: mov [[NEW:r[0-9]+]], r2
37 ; CHECK: uxth [[DESIRED:r[0-9]+]], [[DESIRED]]
38 ; CHECK: [[RETRY:.LBB[0-9]+_[0-9]+]]:
39 ; CHECK: ldrexh [[OLD:[lr0-9]+]], {{\[}}[[ADDR]]{{\]}}
40 ; CHECK: cmp [[OLD]], [[DESIRED]]
41 ; CHECK: bne [[DONE:.LBB[0-9]+_[0-9]+]]
42 ; CHECK: strexh [[STATUS:r[0-9]+]], [[NEW]], {{\[}}[[ADDR]]{{\]}}
43 ; CHECK: cmp{{(\.w)?}} [[STATUS]], #0
44 ; CHECK: bne [[RETRY]]
46 ; Materialisation of a boolean is done with sub/clz/lsr
47 ; CHECK: uxth [[CMP1:r[0-9]+]], [[DESIRED]]
48 ; CHECK: sub{{(\.w|s)?}} [[CMP1]], [[OLD]], [[CMP1]]
49 ; CHECK: clz [[CMP2:r[0-9]+]], [[CMP1]]
50 ; CHECK: lsr{{(s)?}} {{r[0-9]+}}, [[CMP2]], #5
52 %res = cmpxchg i16* %addr, i16 %desired, i16 %new seq_cst monotonic
56 define { i32, i1 } @test_cmpxchg_32(i32* %addr, i32 %desired, i32 %new) nounwind {
57 ; CHECK-LABEL: test_cmpxchg_32:
58 ; CHECK-DAG: mov [[ADDR:r[0-9]+]], r0
59 ; CHECK-DAG: mov [[NEW:r[0-9]+]], r2
62 ; CHECK: [[RETRY:.LBB[0-9]+_[0-9]+]]:
63 ; CHECK: ldrex [[OLD:r[0-9]+]], {{\[}}[[ADDR]]{{\]}}
64 ; CHECK: cmp [[OLD]], [[DESIRED]]
65 ; CHECK: bne [[DONE:.LBB[0-9]+_[0-9]+]]
66 ; CHECK: strex [[STATUS:r[0-9]+]], [[NEW]], {{\[}}[[ADDR]]{{\]}}
67 ; CHECK: cmp{{(\.w)?}} [[STATUS]], #0
68 ; CHECK: bne [[RETRY]]
70 ; Materialisation of a boolean is done with sub/clz/lsr
71 ; CHECK: sub{{(s)?}} [[CMP1:r[0-9]+]], [[OLD]], [[DESIRED]]
72 ; CHECK: clz [[CMP2:r[0-9]+]], [[CMP1]]
73 ; CHECK: lsr{{(s)?}} {{r[0-9]+}}, [[CMP2]], #5
75 %res = cmpxchg i32* %addr, i32 %desired, i32 %new seq_cst monotonic
79 define { i64, i1 } @test_cmpxchg_64(i64* %addr, i64 %desired, i64 %new) nounwind {
80 ; CHECK-LABEL: test_cmpxchg_64:
81 ; CHECK: mov [[ADDR:r[0-9]+]], r0
84 ; CHECK: [[RETRY:.LBB[0-9]+_[0-9]+]]:
85 ; CHECK: ldrexd [[OLDLO:r[0-9]+]], [[OLDHI:r[0-9]+]], {{\[}}[[ADDR]]{{\]}}
86 ; CHECK: cmp [[OLDLO]], r6
87 ; CHECK: cmpeq [[OLDHI]], r7
88 ; CHECK: bne [[DONE:.LBB[0-9]+_[0-9]+]]
89 ; CHECK: strexd [[STATUS:[lr0-9]+]], r8, r9, [r1]
90 ; CHECK: cmp{{(\.w)?}} [[STATUS]], #0
91 ; CHECK: bne [[RETRY]]
94 %res = cmpxchg i64* %addr, i64 %desired, i64 %new seq_cst monotonic
98 define { i64, i1 } @test_nontrivial_args(i64* %addr, i64 %desired, i64 %new) {
99 ; CHECK-LABEL: test_nontrivial_args:
100 ; CHECK: mov [[ADDR:r[0-9]+]], r0
103 ; CHECK: [[RETRY:.LBB[0-9]+_[0-9]+]]:
104 ; CHECK: ldrexd [[OLDLO:r[0-9]+]], [[OLDHI:r[0-9]+]], {{\[}}[[ADDR]]{{\]}}
105 ; CHECK: cmp [[OLDLO]], {{r[0-9]+}}
106 ; CHECK: cmpeq [[OLDHI]], {{r[0-9]+}}
107 ; CHECK: bne [[DONE:.LBB[0-9]+_[0-9]+]]
108 ; CHECK: strexd [[STATUS:r[0-9]+]], {{r[0-9]+}}, {{r[0-9]+}}, {{\[}}[[ADDR]]{{\]}}
109 ; CHECK: cmp{{(\.w)?}} [[STATUS]], #0
110 ; CHECK: bne [[RETRY]]
114 %desired1 = add i64 %desired, 1
115 %new1 = add i64 %new, 1
116 %res = cmpxchg i64* %addr, i64 %desired1, i64 %new1 seq_cst seq_cst
120 ; The following used to trigger an assertion when creating a spill on thumb2
121 ; for a physreg with RC==GPRPairRegClass.
122 ; CHECK-LABEL: test_cmpxchg_spillbug:
126 define void @test_cmpxchg_spillbug() {
127 %v = cmpxchg i64* undef, i64 undef, i64 undef seq_cst seq_cst