1; Test 8-bit atomic ANDs.
2;
3; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
4; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s -check-prefix=CHECK-SHIFT1
5; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s -check-prefix=CHECK-SHIFT2
6
7; Check AND of a variable.
8; - CHECK is for the main loop.
9; - CHECK-SHIFT1 makes sure that the negated shift count used by the second
10;   RLL is set up correctly.  The negation is independent of the NILL and L
11;   tested in CHECK.
12; - CHECK-SHIFT2 makes sure that %b is shifted into the high part of the word
13;   before being used, and that the low bits are set to 1.  This sequence is
14;   independent of the other loop prologue instructions.
15define i8 @f1(i8 *%src, i8 %b) {
16; CHECK-LABEL: f1:
17; CHECK: risbg [[RISBG:%r[1-9]+]], %r2, 0, 189, 0
18; CHECK: l [[OLD:%r[0-9]+]], 0([[RISBG]])
19; CHECK: [[LABEL:\.[^:]*]]:
20; CHECK: rll [[ROT:%r[0-9]+]], [[OLD]], 0(%r2)
21; CHECK: nr [[ROT]], %r3
22; CHECK: rll [[NEW:%r[0-9]+]], [[ROT]], 0({{%r[1-9]+}})
23; CHECK: cs [[OLD]], [[NEW]], 0([[RISBG]])
24; CHECK: jl [[LABEL]]
25; CHECK: rll %r2, [[OLD]], 8(%r2)
26; CHECK: br %r14
27;
28; CHECK-SHIFT1-LABEL: f1:
29; CHECK-SHIFT1: sll %r2, 3
30; CHECK-SHIFT1: lcr [[NEGSHIFT:%r[1-9]+]], %r2
31; CHECK-SHIFT1: rll
32; CHECK-SHIFT1: rll {{%r[0-9]+}}, {{%r[0-9]+}}, 0([[NEGSHIFT]])
33; CHECK-SHIFT1: rll
34; CHECK-SHIFT1: br %r14
35;
36; CHECK-SHIFT2-LABEL: f1:
37; CHECK-SHIFT2: sll %r3, 24
38; CHECK-SHIFT2: oilf %r3, 16777215
39; CHECK-SHIFT2: rll
40; CHECK-SHIFT2: nr {{%r[0-9]+}}, %r3
41; CHECK-SHIFT2: rll
42; CHECK-SHIFT2: rll
43; CHECK-SHIFT2: br %r14
44  %res = atomicrmw and i8 *%src, i8 %b seq_cst
45  ret i8 %res
46}
47
48; Check the minimum signed value.  We AND the rotated word with 0x80ffffff.
49define i8 @f2(i8 *%src) {
50; CHECK-LABEL: f2:
51; CHECK: risbg [[RISBG:%r[1-9]+]], %r2, 0, 189, 0
52; CHECK: sll %r2, 3
53; CHECK: l [[OLD:%r[0-9]+]], 0([[RISBG]])
54; CHECK: [[LABEL:\.[^:]*]]:
55; CHECK: rll [[ROT:%r[0-9]+]], [[OLD]], 0(%r2)
56; CHECK: nilh [[ROT]], 33023
57; CHECK: rll [[NEW:%r[0-9]+]], [[ROT]], 0([[NEGSHIFT:%r[1-9]+]])
58; CHECK: cs [[OLD]], [[NEW]], 0([[RISBG]])
59; CHECK: jl [[LABEL]]
60; CHECK: rll %r2, [[OLD]], 8(%r2)
61; CHECK: br %r14
62;
63; CHECK-SHIFT1-LABEL: f2:
64; CHECK-SHIFT1: sll %r2, 3
65; CHECK-SHIFT1: lcr [[NEGSHIFT:%r[1-9]+]], %r2
66; CHECK-SHIFT1: rll
67; CHECK-SHIFT1: rll {{%r[0-9]+}}, {{%r[0-9]+}}, 0([[NEGSHIFT]])
68; CHECK-SHIFT1: rll
69; CHECK-SHIFT1: br %r14
70;
71; CHECK-SHIFT2-LABEL: f2:
72; CHECK-SHIFT2: br %r14
73  %res = atomicrmw and i8 *%src, i8 -128 seq_cst
74  ret i8 %res
75}
76
77; Check ANDs of -2 (-1 isn't useful).  We AND the rotated word with 0xfeffffff.
78define i8 @f3(i8 *%src) {
79; CHECK-LABEL: f3:
80; CHECK: nilh [[ROT]], 65279
81; CHECK: br %r14
82;
83; CHECK-SHIFT1-LABEL: f3:
84; CHECK-SHIFT1: br %r14
85; CHECK-SHIFT2-LABEL: f3:
86; CHECK-SHIFT2: br %r14
87  %res = atomicrmw and i8 *%src, i8 -2 seq_cst
88  ret i8 %res
89}
90
91; Check ANDs of 1.  We AND the rotated word with 0x01ffffff.
92define i8 @f4(i8 *%src) {
93; CHECK-LABEL: f4:
94; CHECK: nilh [[ROT]], 511
95; CHECK: br %r14
96;
97; CHECK-SHIFT1-LABEL: f4:
98; CHECK-SHIFT1: br %r14
99; CHECK-SHIFT2-LABEL: f4:
100; CHECK-SHIFT2: br %r14
101  %res = atomicrmw and i8 *%src, i8 1 seq_cst
102  ret i8 %res
103}
104
105; Check the maximum signed value.  We AND the rotated word with 0x7fffffff.
106define i8 @f5(i8 *%src) {
107; CHECK-LABEL: f5:
108; CHECK: nilh [[ROT]], 32767
109; CHECK: br %r14
110;
111; CHECK-SHIFT1-LABEL: f5:
112; CHECK-SHIFT1: br %r14
113; CHECK-SHIFT2-LABEL: f5:
114; CHECK-SHIFT2: br %r14
115  %res = atomicrmw and i8 *%src, i8 127 seq_cst
116  ret i8 %res
117}
118
119; Check ANDs of a large unsigned value.  We AND the rotated word with
120; 0xfdffffff.
121define i8 @f6(i8 *%src) {
122; CHECK-LABEL: f6:
123; CHECK: nilh [[ROT]], 65023
124; CHECK: br %r14
125;
126; CHECK-SHIFT1-LABEL: f6:
127; CHECK-SHIFT1: br %r14
128; CHECK-SHIFT2-LABEL: f6:
129; CHECK-SHIFT2: br %r14
130  %res = atomicrmw and i8 *%src, i8 253 seq_cst
131  ret i8 %res
132}
133