1; RUN: llc < %s -mtriple=arm-linux-gnueabi -asm-verbose=false -verify-machineinstrs | FileCheck %s -check-prefix=CHECK-ARM
2; RUN: llc < %s -mtriple=thumb-linux-gnueabi -asm-verbose=false -verify-machineinstrs | FileCheck %s -check-prefix=CHECK-THUMB
3
4; RUN: llc < %s -mtriple=armv6-linux-gnueabi -asm-verbose=false -verify-machineinstrs | FileCheck %s -check-prefix=CHECK-ARMV6
5; RUN: llc < %s -mtriple=thumbv6-linux-gnueabi -asm-verbose=false -verify-machineinstrs | FileCheck %s -check-prefix=CHECK-THUMBV6
6
7; RUN: llc < %s -mtriple=armv7-linux-gnueabi -asm-verbose=false -verify-machineinstrs | FileCheck %s -check-prefix=CHECK-ARMV7
8; RUN: llc < %s -mtriple=thumbv7-linux-gnueabi -asm-verbose=false -verify-machineinstrs | FileCheck %s -check-prefix=CHECK-THUMBV7
9
10define zeroext i1 @test_cmpxchg_res_i8(i8* %addr, i8 %desired, i8 zeroext %new) {
11entry:
12  %0 = cmpxchg i8* %addr, i8 %desired, i8 %new monotonic monotonic
13  %1 = extractvalue { i8, i1 } %0, 1
14  ret i1 %1
15}
16
17; CHECK-ARM-LABEL: test_cmpxchg_res_i8
18; CHECK-ARM: bl __sync_val_compare_and_swap_1
19; CHECK-ARM: mov [[REG:r[0-9]+]], #0
20; CHECK-ARM: cmp r0, {{r[0-9]+}}
21; CHECK-ARM: moveq [[REG]], #1
22; CHECK-ARM: mov r0, [[REG]]
23
24; CHECK-THUMB-LABEL: test_cmpxchg_res_i8
25; CHECK-THUMB: bl __sync_val_compare_and_swap_1
26; CHECK-THUMB-NOT: mov [[R1:r[0-7]]], r0
27; CHECK-THUMB: push  {r0}
28; CHECK-THUMB: pop {[[R1:r[0-7]]]}
29; CHECK-THUMB: movs r0, #1
30; CHECK-THUMB: movs [[R2:r[0-9]+]], #0
31; CHECK-THUMB: cmp [[R1]], {{r[0-9]+}}
32; CHECK-THUMB: beq
33; CHECK-THUMB: push  {[[R2]]}
34; CHECK-THUMB: pop {r0}
35
36; CHECK-ARMV6-LABEL: test_cmpxchg_res_i8:
37; CHECK-ARMV6-NEXT:  .fnstart
38; CHECK-ARMV6-NEXT: uxtb [[DESIRED:r[0-9]+]], r1
39; CHECK-ARMV6-NEXT: [[TRY:.LBB[0-9_]+]]:
40; CHECK-ARMV6-NEXT: ldrexb [[LD:r[0-9]+]], [r0]
41; CHECK-ARMV6-NEXT: mov [[RES:r[0-9]+]], #0
42; CHECK-ARMV6-NEXT: cmp [[LD]], [[DESIRED]]
43; CHECK-ARMV6-NEXT: bne [[END:.LBB[0-9_]+]]
44; CHECK-ARMV6-NEXT: strexb [[SUCCESS:r[0-9]+]], r2, [r0]
45; CHECK-ARMV6-NEXT: mov [[RES]], #1
46; CHECK-ARMV6-NEXT: cmp [[SUCCESS]], #0
47; CHECK-ARMV6-NEXT: bne [[TRY]]
48; CHECK-ARMV6-NEXT: [[END]]:
49; CHECK-ARMV6-NEXT: mov r0, [[RES]]
50; CHECK-ARMV6-NEXT: bx lr
51
52; CHECK-THUMBV6-LABEL: test_cmpxchg_res_i8:
53; CHECK-THUMBV6:       mov [[EXPECTED:r[0-9]+]], r1
54; CHECK-THUMBV6-NEXT:  bl __sync_val_compare_and_swap_1
55; CHECK-THUMBV6-NEXT:  mov [[RES:r[0-9]+]], r0
56; CHECK-THUMBV6-NEXT:  movs r0, #1
57; CHECK-THUMBV6-NEXT:  movs [[ZERO:r[0-9]+]], #0
58; CHECK-THUMBV6-NEXT:  cmp [[RES]], [[EXPECTED]]
59; CHECK-THUMBV6-NEXT:  beq [[END:.LBB[0-9_]+]]
60; CHECK-THUMBV6-NEXT:  mov r0, [[ZERO]]
61; CHECK-THUMBV6-NEXT: [[END]]:
62; CHECK-THUMBV6-NEXT:  pop {{.*}}pc}
63
64; CHECK-ARMV7-LABEL: test_cmpxchg_res_i8:
65; CHECK-ARMV7-NEXT: .fnstart
66; CHECK-ARMV7-NEXT: uxtb [[DESIRED:r[0-9]+]], r1
67; CHECK-ARMV7-NEXT: [[TRY:.LBB[0-9_]+]]:
68; CHECK-ARMV7-NEXT: ldrexb [[LD:r[0-9]+]], [r0]
69; CHECK-ARMV7-NEXT: cmp [[LD]], [[DESIRED]]
70; CHECK-ARMV7-NEXT: bne [[FAIL:.LBB[0-9_]+]]
71; CHECK-ARMV7-NEXT: strexb [[SUCCESS:r[0-9]+]], r2, [r0]
72; CHECK-ARMV7-NEXT: mov [[RES:r[0-9]+]], #1
73; CHECK-ARMV7-NEXT: cmp [[SUCCESS]], #0
74; CHECK-ARMV7-NEXT: bne [[TRY]]
75; CHECK-ARMV7-NEXT: b [[END:.LBB[0-9_]+]]
76; CHECK-ARMV7-NEXT: [[FAIL]]:
77; CHECK-ARMV7-NEXT: clrex
78; CHECK-ARMV7-NEXT: mov [[RES]], #0
79; CHECK-ARMV7-NEXT: [[END]]:
80; CHECK-ARMV7-NEXT: mov r0, [[RES]]
81; CHECK-ARMV7-NEXT: bx lr
82
83; CHECK-THUMBV7-LABEL: test_cmpxchg_res_i8:
84; CHECK-THUMBV7-NEXT: .fnstart
85; CHECK-THUMBV7-NEXT: uxtb [[DESIRED:r[0-9]+]], r1
86; CHECK-THUMBV7-NEXT: b [[TRYLD:.LBB[0-9_]+]]
87; CHECK-THUMBV7-NEXT: [[TRYST:.LBB[0-9_]+]]:
88; CHECK-THUMBV7-NEXT: strexb [[SUCCESS:r[0-9]+]], r2, [r0]
89; CHECK-THUMBV7-NEXT: cmp [[SUCCESS]], #0
90; CHECK-THUMBV7-NEXT: itt eq
91; CHECK-THUMBV7-NEXT: moveq r0, #1
92; CHECK-THUMBV7-NEXT: bxeq lr
93; CHECK-THUMBV7-NEXT: [[TRYLD]]:
94; CHECK-THUMBV7-NEXT: ldrexb [[LD:r[0-9]+]], [r0]
95; CHECK-THUMBV7-NEXT: cmp [[LD]], [[DESIRED]]
96; CHECK-THUMBV7-NEXT: beq [[TRYST:.LBB[0-9_]+]]
97; CHECK-THUMBV7-NEXT: clrex
98; CHECK-THUMBV7-NEXT: movs r0, #0
99; CHECK-THUMBV7-NEXT: bx lr
100