1 ; Test 64-bit compare and swap.
3 ; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
5 ; Check CSG without a displacement.
6 define i64 @f1(i64 %cmp, i64 %swap, ptr %src) {
8 ; CHECK: csg %r2, %r3, 0(%r4)
10 %pairval = cmpxchg ptr %src, i64 %cmp, i64 %swap seq_cst seq_cst
11 %val = extractvalue { i64, i1 } %pairval, 0
15 ; Check the high end of the aligned CSG range.
16 define i64 @f2(i64 %cmp, i64 %swap, ptr %src) {
18 ; CHECK: csg %r2, %r3, 524280(%r4)
20 %ptr = getelementptr i64, ptr %src, i64 65535
21 %pairval = cmpxchg ptr %ptr, i64 %cmp, i64 %swap seq_cst seq_cst
22 %val = extractvalue { i64, i1 } %pairval, 0
26 ; Check the next doubleword up, which needs separate address logic.
27 ; Other sequences besides this one would be OK.
28 define i64 @f3(i64 %cmp, i64 %swap, ptr %src) {
30 ; CHECK: agfi %r4, 524288
31 ; CHECK: csg %r2, %r3, 0(%r4)
33 %ptr = getelementptr i64, ptr %src, i64 65536
34 %pairval = cmpxchg ptr %ptr, i64 %cmp, i64 %swap seq_cst seq_cst
35 %val = extractvalue { i64, i1 } %pairval, 0
39 ; Check the high end of the negative aligned CSG range.
40 define i64 @f4(i64 %cmp, i64 %swap, ptr %src) {
42 ; CHECK: csg %r2, %r3, -8(%r4)
44 %ptr = getelementptr i64, ptr %src, i64 -1
45 %pairval = cmpxchg ptr %ptr, i64 %cmp, i64 %swap seq_cst seq_cst
46 %val = extractvalue { i64, i1 } %pairval, 0
50 ; Check the low end of the CSG range.
51 define i64 @f5(i64 %cmp, i64 %swap, ptr %src) {
53 ; CHECK: csg %r2, %r3, -524288(%r4)
55 %ptr = getelementptr i64, ptr %src, i64 -65536
56 %pairval = cmpxchg ptr %ptr, i64 %cmp, i64 %swap seq_cst seq_cst
57 %val = extractvalue { i64, i1 } %pairval, 0
61 ; Check the next doubleword down, which needs separate address logic.
62 ; Other sequences besides this one would be OK.
63 define i64 @f6(i64 %cmp, i64 %swap, ptr %src) {
65 ; CHECK: agfi %r4, -524296
66 ; CHECK: csg %r2, %r3, 0(%r4)
68 %ptr = getelementptr i64, ptr %src, i64 -65537
69 %pairval = cmpxchg ptr %ptr, i64 %cmp, i64 %swap seq_cst seq_cst
70 %val = extractvalue { i64, i1 } %pairval, 0
74 ; Check that CSG does not allow an index.
75 define i64 @f7(i64 %cmp, i64 %swap, i64 %src, i64 %index) {
78 ; CHECK: csg %r2, %r3, 0(%r4)
80 %add1 = add i64 %src, %index
81 %ptr = inttoptr i64 %add1 to ptr
82 %pairval = cmpxchg ptr %ptr, i64 %cmp, i64 %swap seq_cst seq_cst
83 %val = extractvalue { i64, i1 } %pairval, 0
87 ; Check that a constant %cmp value is loaded into a register first.
88 define i64 @f8(i64 %dummy, i64 %swap, ptr %ptr) {
90 ; CHECK: lghi %r2, 1001
91 ; CHECK: csg %r2, %r3, 0(%r4)
93 %pairval = cmpxchg ptr %ptr, i64 1001, i64 %swap seq_cst seq_cst
94 %val = extractvalue { i64, i1 } %pairval, 0
98 ; Check that a constant %swap value is loaded into a register first.
99 define i64 @f9(i64 %cmp, ptr %ptr) {
101 ; CHECK: lghi [[SWAP:%r[0-9]+]], 1002
102 ; CHECK: csg %r2, [[SWAP]], 0(%r3)
104 %pairval = cmpxchg ptr %ptr, i64 %cmp, i64 1002 seq_cst seq_cst
105 %val = extractvalue { i64, i1 } %pairval, 0
109 ; Check generating the comparison result.
111 ; CHECK: csg %r2, %r3, 0(%r4)
112 ; CHECK-NEXT: ipm %r2
113 ; CHECK-NEXT: afi %r2, -268435456
114 ; CHECK-NEXT: srl %r2, 31
116 define i32 @f10(i64 %cmp, i64 %swap, ptr %src) {
117 %pairval = cmpxchg ptr %src, i64 %cmp, i64 %swap seq_cst seq_cst
118 %val = extractvalue { i64, i1 } %pairval, 1
119 %res = zext i1 %val to i32
125 ; Check using the comparison result for a branch.
127 ; CHECK: csg %r2, %r3, 0(%r4)
130 define void @f11(i64 %cmp, i64 %swap, ptr %src) {
131 %pairval = cmpxchg ptr %src, i64 %cmp, i64 %swap seq_cst seq_cst
132 %cond = extractvalue { i64, i1 } %pairval, 1
133 br i1 %cond, label %call, label %exit
143 ; ... and the same with the inverted direction.
145 ; CHECK: csg %r2, %r3, 0(%r4)
148 define void @f12(i64 %cmp, i64 %swap, ptr %src) {
149 %pairval = cmpxchg ptr %src, i64 %cmp, i64 %swap seq_cst seq_cst
150 %cond = extractvalue { i64, i1 } %pairval, 1
151 br i1 %cond, label %exit, label %call