1 ; Test 8-bit compare and swap.
3 ; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s -check-prefix=CHECK-MAIN
4 ; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s -check-prefix=CHECK-SHIFT
6 ; Check compare and swap with a variable.
7 ; - CHECK is for the main loop.
8 ; - CHECK-SHIFT makes sure that the negated shift count used by the second
9 ; RLL is set up correctly. The negation is independent of the NILL and L
10 ; tested in CHECK. CHECK-SHIFT also checks that %r3 is not modified before
11 ; being used in the RISBG (in contrast to things like atomic addition,
12 ; which shift %r3 left so that %b is at the high end of the word).
13 define i8 @f1(i8 %dummy, ptr %src, i8 %cmp, i8 %swap) {
14 ; CHECK-MAIN-LABEL: f1:
15 ; CHECK-MAIN: risbg [[RISBG:%r[1-9]+]], %r3, 0, 189, 0{{$}}
16 ; CHECK-MAIN-DAG: sll %r3, 3
17 ; CHECK-MAIN-DAG: l [[OLD:%r[0-9]+]], 0([[RISBG]])
18 ; CHECK-MAIN-DAG: llcr %r4, %r4
19 ; CHECK-MAIN: [[LOOP:\.[^ ]*]]:
20 ; CHECK-MAIN: rll %r2, [[OLD]], 8(%r3)
21 ; CHECK-MAIN: risbg %r5, %r2, 32, 55, 0
22 ; CHECK-MAIN: llcr %r2, %r2
23 ; CHECK-MAIN: crjlh %r2, %r4, [[EXIT:\.[^ ]*]]
24 ; CHECK-MAIN: rll [[NEW:%r[0-9]+]], %r5, -8({{%r[1-9]+}})
25 ; CHECK-MAIN: cs [[OLD]], [[NEW]], 0([[RISBG]])
26 ; CHECK-MAIN: jl [[LOOP]]
27 ; CHECK-MAIN: [[EXIT]]:
31 ; CHECK-SHIFT-LABEL: f1:
32 ; CHECK-SHIFT: sll [[SHIFT:%r[1-9]+]], 3
33 ; CHECK-SHIFT: lcr [[NEGSHIFT:%r[1-9]+]], [[SHIFT]]
35 ; CHECK-SHIFT: rll {{%r[0-9]+}}, %r5, -8([[NEGSHIFT]])
36 %pair = cmpxchg ptr %src, i8 %cmp, i8 %swap seq_cst seq_cst
37 %res = extractvalue { i8, i1 } %pair, 0
41 ; Check compare and swap with constants. We should force the constants into
42 ; registers and use the sequence above.
43 define i8 @f2(ptr %src) {
45 ; CHECK: lhi [[CMP:%r[0-9]+]], 42
46 ; CHECK: risbg [[CMP]], {{%r[0-9]+}}, 32, 55, 0
50 ; CHECK-SHIFT-LABEL: f2:
51 ; CHECK-SHIFT: lhi [[SWAP:%r[0-9]+]], 88
52 ; CHECK-SHIFT: risbg [[SWAP]], {{%r[0-9]+}}, 32, 55, 0
53 ; CHECK-SHIFT: br %r14
54 %pair = cmpxchg ptr %src, i8 42, i8 88 seq_cst seq_cst
55 %res = extractvalue { i8, i1 } %pair, 0
59 ; Check generating the comparison result.
60 define i32 @f3(i8 %dummy, ptr %src, i8 %cmp, i8 %swap) {
61 ; CHECK-MAIN-LABEL: f3:
62 ; CHECK-MAIN: risbg [[RISBG:%r[1-9]+]], %r3, 0, 189, 0{{$}}
63 ; CHECK-MAIN-DAG: sll %r3, 3
64 ; CHECK-MAIN-DAG: l [[OLD:%r[0-9]+]], 0([[RISBG]])
65 ; CHECK-MAIN-DAG: llcr %r2, %r4
66 ; CHECK-MAIN: [[LOOP:\.[^ ]*]]:
67 ; CHECK-MAIN: rll [[TMP:%r[0-9]+]], [[OLD]], 8(%r3)
68 ; CHECK-MAIN: risbg %r5, [[TMP]], 32, 55, 0
69 ; CHECK-MAIN: llcr [[TMP2:%r[0-9]+]], [[TMP]]
70 ; CHECK-MAIN: cr [[TMP2]], %r2
71 ; CHECK-MAIN: jlh [[EXIT:\.[^ ]*]]
72 ; CHECK-MAIN: rll [[NEW:%r[0-9]+]], %r5, -8({{%r[1-9]+}})
73 ; CHECK-MAIN: cs [[OLD]], [[NEW]], 0([[RISBG]])
74 ; CHECK-MAIN: jl [[LOOP]]
75 ; CHECK-MAIN: [[EXIT]]:
76 ; CHECK-MAIN-NEXT: ipm %r2
77 ; CHECK-MAIN-NEXT: afi %r2, -268435456
78 ; CHECK-MAIN-NEXT: srl %r2, 31
82 ; CHECK-SHIFT-LABEL: f3:
83 ; CHECK-SHIFT: sll [[SHIFT:%r[1-9]+]], 3
84 ; CHECK-SHIFT: lcr [[NEGSHIFT:%r[1-9]+]], [[SHIFT]]
86 ; CHECK-SHIFT: rll {{%r[0-9]+}}, %r5, -8([[NEGSHIFT]])
87 %pair = cmpxchg ptr %src, i8 %cmp, i8 %swap seq_cst seq_cst
88 %val = extractvalue { i8, i1 } %pair, 1
89 %res = zext i1 %val to i32
96 ; Check using the comparison result for a branch.
98 ; CHECK-MAIN-LABEL: f4:
99 ; CHECK-MAIN: risbg [[RISBG:%r[1-9]+]], %r2, 0, 189, 0{{$}}
100 ; CHECK-MAIN-DAG: sll %r2, 3
101 ; CHECK-MAIN-DAG: l [[OLD:%r[0-9]+]], 0([[RISBG]])
102 ; CHECK-MAIN-DAG: llcr %r3, %r3
103 ; CHECK-MAIN: [[LOOP:\.[^ ]*]]:
104 ; CHECK-MAIN: rll [[TMP:%r[0-9]+]], [[OLD]], 8(%r2)
105 ; CHECK-MAIN: risbg %r4, [[TMP]], 32, 55, 0
106 ; CHECK-MAIN: llcr [[TMP]], [[TMP]]
107 ; CHECK-MAIN: cr [[TMP]], %r3
108 ; CHECK-MAIN: jlh [[EXIT:\.[^ ]*]]
109 ; CHECK-MAIN: rll [[NEW:%r[0-9]+]], %r4, -8({{%r[1-9]+}})
110 ; CHECK-MAIN: cs [[OLD]], [[NEW]], 0([[RISBG]])
111 ; CHECK-MAIN: jl [[LOOP]]
112 ; CHECK-MAIN: [[EXIT]]:
113 ; CHECK-MAIN-NEXT: jlh [[LABEL:\.[^ ]*]]
115 ; CHECK-MAIN: [[LABEL]]:
116 ; CHECK-MAIN: br %r14
118 ; CHECK-SHIFT-LABEL: f4:
119 ; CHECK-SHIFT: sll %r2, 3
120 ; CHECK-SHIFT: lcr [[NEGSHIFT:%r[1-9]+]], %r2
122 ; CHECK-SHIFT: rll {{%r[0-9]+}}, %r4, -8([[NEGSHIFT]])
123 define void @f4(ptr %src, i8 %cmp, i8 %swap) {
124 %pair = cmpxchg ptr %src, i8 %cmp, i8 %swap seq_cst seq_cst
125 %cond = extractvalue { i8, i1 } %pair, 1
126 br i1 %cond, label %call, label %exit
136 ; ... and the same with the inverted direction.
137 ; CHECK-MAIN-LABEL: f5:
138 ; CHECK-MAIN: risbg [[RISBG:%r[1-9]+]], %r2, 0, 189, 0{{$}}
139 ; CHECK-MAIN-DAG: sll %r2, 3
140 ; CHECK-MAIN-DAG: l [[OLD:%r[0-9]+]], 0([[RISBG]])
141 ; CHECK-MAIN-DAG: llcr %r3, %r3
142 ; CHECK-MAIN: [[LOOP:\.[^ ]*]]:
143 ; CHECK-MAIN: rll [[TMP:%r[0-9]+]], [[OLD]], 8(%r2)
144 ; CHECK-MAIN: risbg %r4, [[TMP]], 32, 55, 0
145 ; CHECK-MAIN: llcr [[TMP]], [[TMP]]
146 ; CHECK-MAIN: cr [[TMP]], %r3
147 ; CHECK-MAIN: jlh [[EXIT:\.[^ ]*]]
148 ; CHECK-MAIN: rll [[NEW:%r[0-9]+]], %r4, -8({{%r[1-9]+}})
149 ; CHECK-MAIN: cs [[OLD]], [[NEW]], 0([[RISBG]])
150 ; CHECK-MAIN: jl [[LOOP]]
151 ; CHECK-MAIN: [[EXIT]]:
152 ; CHECK-MAIN-NEXT: jlh [[LABEL:\.[^ ]*]]
153 ; CHECK-MAIN: br %r14
154 ; CHECK-MAIN: [[LABEL]]:
157 ; CHECK-SHIFT-LABEL: f5:
158 ; CHECK-SHIFT: sll %r2, 3
159 ; CHECK-SHIFT: lcr [[NEGSHIFT:%r[1-9]+]], %r2
161 ; CHECK-SHIFT: rll {{%r[0-9]+}}, %r4, -8([[NEGSHIFT]])
162 define void @f5(ptr %src, i8 %cmp, i8 %swap) {
163 %pair = cmpxchg ptr %src, i8 %cmp, i8 %swap seq_cst seq_cst
164 %cond = extractvalue { i8, i1 } %pair, 1
165 br i1 %cond, label %exit, label %call