1 ; Test 16-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 i16 @f1(i16 %dummy, ptr %src, i16 %cmp, i16 %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: llhr %r4, %r4
19 ; CHECK-MAIN: [[LOOP:\.[^ ]*]]:
20 ; CHECK-MAIN: rll %r2, [[OLD]], 16(%r3)
21 ; CHECK-MAIN: risbg %r5, %r2, 32, 47, 0
22 ; CHECK-MAIN: llhr %r2, %r2
23 ; CHECK-MAIN: crjlh %r2, %r4, [[EXIT:\.[^ ]*]]
24 ; CHECK-MAIN: rll [[NEW:%r[0-9]+]], %r5, -16({{%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 %r3, 3
33 ; CHECK-SHIFT: lcr [[NEGSHIFT:%r[1-9]+]], %r3
35 ; CHECK-SHIFT: rll {{%r[0-9]+}}, %r5, -16([[NEGSHIFT]])
36 %pair = cmpxchg ptr %src, i16 %cmp, i16 %swap seq_cst seq_cst
37 %res = extractvalue { i16, 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 i16 @f2(ptr %src) {
45 ; CHECK: lhi [[CMP:%r[0-9]+]], 42
46 ; CHECK: risbg [[CMP]], {{%r[0-9]+}}, 32, 47, 0
50 ; CHECK-SHIFT-LABEL: f2:
51 ; CHECK-SHIFT: lhi [[SWAP:%r[0-9]+]], 88
52 ; CHECK-SHIFT: risbg [[SWAP]], {{%r[0-9]+}}, 32, 47, 0
53 ; CHECK-SHIFT: br %r14
54 %pair = cmpxchg ptr %src, i16 42, i16 88 seq_cst seq_cst
55 %res = extractvalue { i16, i1 } %pair, 0
59 ; Check generating the comparison result.
60 define i32 @f3(i16 %dummy, ptr %src, i16 %cmp, i16 %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: llhr %r2, %r4
66 ; CHECK-MAIN: [[LOOP:\.[^ ]*]]:
67 ; CHECK-MAIN: rll [[TMP:%r[0-9]+]], [[OLD]], 16(%r3)
68 ; CHECK-MAIN: risbg %r5, [[TMP]], 32, 47, 0
69 ; CHECK-MAIN: llhr %r14, %r14
70 ; CHECK-MAIN: cr [[TMP]], %r2
71 ; CHECK-MAIN: jlh [[EXIT:\.[^ ]*]]
72 ; CHECK-MAIN: rll [[NEW:%r[0-9]+]], %r5, -16({{%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 %r3, 3
84 ; CHECK-SHIFT: lcr [[NEGSHIFT:%r[1-9]+]], %r3
86 ; CHECK-SHIFT: rll {{%r[0-9]+}}, %r5, -16([[NEGSHIFT]])
87 %pair = cmpxchg ptr %src, i16 %cmp, i16 %swap seq_cst seq_cst
88 %val = extractvalue { i16, i1 } %pair, 1
89 %res = zext i1 %val to i32
95 ; Check using the comparison result for a branch.
97 ; CHECK-MAIN-LABEL: f4:
98 ; CHECK-MAIN: risbg [[RISBG:%r[1-9]+]], %r2, 0, 189, 0{{$}}
99 ; CHECK-MAIN-DAG: sll %r2, 3
100 ; CHECK-MAIN-DAG: l [[OLD:%r[0-9]+]], 0([[RISBG]])
101 ; CHECK-MAIN-DAG: llhr %r3, %r3
102 ; CHECK-MAIN: [[LOOP:\.[^ ]*]]:
103 ; CHECK-MAIN: rll [[TMP:%r[0-9]+]], [[OLD]], 16(%r2)
104 ; CHECK-MAIN: risbg %r4, [[TMP]], 32, 47, 0
105 ; CHECK-MAIN: llhr %r14, %r14
106 ; CHECK-MAIN: cr [[TMP]], %r3
107 ; CHECK-MAIN: jlh [[EXIT:\.[^ ]*]]
108 ; CHECK-MAIN: rll [[NEW:%r[0-9]+]], %r4, -16({{%r[1-9]+}})
109 ; CHECK-MAIN: cs [[OLD]], [[NEW]], 0([[RISBG]])
110 ; CHECK-MAIN: jl [[LOOP]]
111 ; CHECK-MAIN: [[EXIT]]:
112 ; CHECK-MAIN-NEXT: jlh [[LABEL:\.[^ ]*]]
114 ; CHECK-MAIN: [[LABEL]]:
115 ; CHECK-MAIN: br %r14
117 ; CHECK-SHIFT-LABEL: f4:
118 ; CHECK-SHIFT: sll %r2, 3
119 ; CHECK-SHIFT: lcr [[NEGSHIFT:%r[1-9]+]], %r2
121 ; CHECK-SHIFT: rll {{%r[0-9]+}}, %r4, -16([[NEGSHIFT]])
122 define void @f4(ptr %src, i16 %cmp, i16 %swap) {
123 %pair = cmpxchg ptr %src, i16 %cmp, i16 %swap seq_cst seq_cst
124 %cond = extractvalue { i16, i1 } %pair, 1
125 br i1 %cond, label %call, label %exit
135 ; ... and the same with the inverted direction.
136 ; CHECK-MAIN-LABEL: f5:
137 ; CHECK-MAIN: risbg [[RISBG:%r[1-9]+]], %r2, 0, 189, 0{{$}}
138 ; CHECK-MAIN-DAG: sll %r2, 3
139 ; CHECK-MAIN-DAG: l [[OLD:%r[0-9]+]], 0([[RISBG]])
140 ; CHECK-MAIN-DAG: llhr %r3, %r3
141 ; CHECK-MAIN: [[LOOP:\.[^ ]*]]:
142 ; CHECK-MAIN: rll [[TMP:%r[0-9]+]], [[OLD]], 16(%r2)
143 ; CHECK-MAIN: risbg %r4, [[TMP]], 32, 47, 0
144 ; CHECK-MAIN: llhr %r14, %r14
145 ; CHECK-MAIN: cr [[TMP]], %r3
146 ; CHECK-MAIN: jlh [[EXIT:\.[^ ]*]]
147 ; CHECK-MAIN: rll [[NEW:%r[0-9]+]], %r4, -16({{%r[1-9]+}})
148 ; CHECK-MAIN: cs [[OLD]], [[NEW]], 0([[RISBG]])
149 ; CHECK-MAIN: jl [[LOOP]]
150 ; CHECK-MAIN: [[EXIT]]:
151 ; CHECK-MAIN-NEXT: jlh [[LABEL:\.[^ ]*]]
152 ; CHECK-MAIN: br %r14
153 ; CHECK-MAIN: [[LABEL]]:
156 ; CHECK-SHIFT-LABEL: f5:
157 ; CHECK-SHIFT: sll %r2, 3
158 ; CHECK-SHIFT: lcr [[NEGSHIFT:%r[1-9]+]], %r2
160 ; CHECK-SHIFT: rll {{%r[0-9]+}}, %r4, -16([[NEGSHIFT]])
161 define void @f5(ptr %src, i16 %cmp, i16 %swap) {
162 %pair = cmpxchg ptr %src, i16 %cmp, i16 %swap seq_cst seq_cst
163 %cond = extractvalue { i16, i1 } %pair, 1
164 br i1 %cond, label %exit, label %call