1; RUN: sed -e "s/ORDER/monotonic/" -e "s/BINARY_OP/add/" %s | llc -march=hexagon | FileCheck %s
2; RUN: sed -e "s/ORDER/acquire/"   -e "s/BINARY_OP/add/" %s | llc -march=hexagon | FileCheck %s
3; RUN: sed -e "s/ORDER/release/"   -e "s/BINARY_OP/add/" %s | llc -march=hexagon | FileCheck %s
4; RUN: sed -e "s/ORDER/acq_rel/"   -e "s/BINARY_OP/add/" %s | llc -march=hexagon | FileCheck %s
5; RUN: sed -e "s/ORDER/seq_cst/"   -e "s/BINARY_OP/add/" %s | llc -march=hexagon | FileCheck %s
6; RUN: sed -e "s/ORDER/monotonic/" -e "s/BINARY_OP/sub/" %s | llc -march=hexagon | FileCheck %s
7; RUN: sed -e "s/ORDER/acquire/"   -e "s/BINARY_OP/sub/" %s | llc -march=hexagon | FileCheck %s
8; RUN: sed -e "s/ORDER/release/"   -e "s/BINARY_OP/sub/" %s | llc -march=hexagon | FileCheck %s
9; RUN: sed -e "s/ORDER/acq_rel/"   -e "s/BINARY_OP/sub/" %s | llc -march=hexagon | FileCheck %s
10; RUN: sed -e "s/ORDER/seq_cst/"   -e "s/BINARY_OP/sub/" %s | llc -march=hexagon | FileCheck %s
11
12%struct.Obj = type { [100 x i32] }
13
14@i32First   = global i32 0, align 4
15@i32Second  = global i32 0, align 4
16@i32Result  = global i32 0, align 4
17@i64First   = global i64 0, align 8
18@i64Second  = global i64 0, align 8
19@i64Result  = global i64 0, align 8
20@ptrFirst   = global %struct.Obj* null, align 4
21@ptrSecond  = global %struct.Obj* null, align 4
22@ptrResult  = global %struct.Obj* null, align 4
23
24define void @atomicrmw_op_i32() #0 {
25BINARY_OP_entry:
26  %i32First = load i32, i32* @i32First, align 4
27  %i32Result = atomicrmw BINARY_OP i32* @i32Second, i32 %i32First ORDER
28  store i32 %i32Result, i32* @i32Result, align 4
29  ret void
30}
31; CHECK-LABEL: atomicrmw_op_i32:
32; CHECK: // %[[BINARY_OP:[a-z_]*]]_entry
33; CHECK-DAG: [[SECOND_ADDR:r[0-9]+]] = ##i32Second
34; CHECK-DAG: [[FIRST_VALUE:r[0-9]+]] = memw(gp+#i32First)
35
36; CHECK: [[FAIL_LABEL:\.LBB.*]]:
37
38; CHECK: [[LOCKED_READ_REG:r[0-9]+]] = memw_locked([[SECOND_ADDR]])
39; CHECK: [[RESULT_REG:r[0-9]+]] = [[BINARY_OP]]([[LOCKED_READ_REG]],[[FIRST_VALUE]])
40; CHECK: memw_locked([[SECOND_ADDR]],[[LOCK_PRED_REG:p[0-9]+]]) = [[RESULT_REG]]
41
42; CHECK: if (![[LOCK_PRED_REG]]) jump{{.*}}[[FAIL_LABEL]]
43; CHECK-DAG: memw(gp+#i32Result) = [[LOCKED_READ_REG]]
44; CHECK-DAG: jumpr r31
45
46define void @atomicrmw_op_i64() #0 {
47entry:
48  %i64First = load i64, i64* @i64First, align 8
49  %i64Result = atomicrmw BINARY_OP i64* @i64Second, i64 %i64First ORDER
50  store i64 %i64Result, i64* @i64Result, align 8
51  ret void
52}
53; CHECK-LABEL: atomicrmw_op_i64:
54; CHECK-DAG: [[SECOND_ADDR:r[0-9]+]] = ##i64Second
55; CHECK-DAG: [[FIRST_VALUE:r[0-9]+:[0-9]+]] = memd(gp+#i64First)
56
57; CHECK: [[FAIL_LABEL:\.LBB.*]]:
58
59; CHECK-DAG: [[LOCKED_READ_REG:r[0-9]+:[0-9]+]] = memd_locked([[SECOND_ADDR]])
60; CHECK: [[RESULT_REG:r[0-9]+:[0-9]+]] = [[BINARY_OP]]([[LOCKED_READ_REG]],[[FIRST_VALUE]])
61; CHECK: memd_locked([[SECOND_ADDR]],[[LOCK_PRED_REG:p[0-9]+]]) = [[RESULT_REG]]
62
63; CHECK: if (![[LOCK_PRED_REG]]) jump{{.*}}[[FAIL_LABEL]]
64; CHECK-DAG: memd(gp+#i64Result) = [[LOCKED_READ_REG]]
65; CHECK-DAG: jumpr r31
66
67define void @atomicrmw_op_ptr() #0 {
68entry:
69  %ptrFirst = load i32, i32* bitcast (%struct.Obj** @ptrFirst to i32*), align 4
70  %ptrResult = atomicrmw BINARY_OP i32* bitcast (%struct.Obj** @ptrSecond to i32*), i32 %ptrFirst ORDER
71  store i32 %ptrResult, i32* bitcast (%struct.Obj** @ptrResult to i32*), align 4
72  ret void
73}
74; CHECK-LABEL: atomicrmw_op_ptr:
75; CHECK-DAG: [[SECOND_ADDR:r[0-9]+]] = ##ptrSecond
76; CHECK-DAG: [[FIRST_VALUE:r[0-9]+]] = memw(gp+#ptrFirst)
77
78; CHECK: [[FAIL_LABEL:\.LBB.*]]:
79
80; CHECK-DAG: [[LOCKED_READ_REG:r[0-9]+]] = memw_locked([[SECOND_ADDR]])
81; CHECK: [[RESULT_REG:r[0-9]+]] = [[BINARY_OP]]([[LOCKED_READ_REG]],[[FIRST_VALUE]])
82; CHECK: memw_locked([[SECOND_ADDR]],[[LOCK_PRED_REG:p[0-9]+]]) = [[RESULT_REG]]
83
84; CHECK: if (![[LOCK_PRED_REG]]) jump{{.*}}[[FAIL_LABEL]]
85; CHECK-DAG: memw(gp+#ptrResult) = [[LOCKED_READ_REG]]
86; CHECK-DAG: jumpr r31
87
88