1; Test 16-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 i16 @f1(i16 *%src, i16 %b) {
16; CHECK-LABEL: f1:
17; CHECK: risbg [[RISBG:%r[1-9]+]], %r2, 0, 189, 0{{$}}
18; CHECK: sll %r2, 3
19; CHECK: l [[OLD:%r[0-9]+]], 0([[RISBG]])
20; CHECK: [[LABEL:\.[^:]*]]:
21; CHECK: rll [[ROT:%r[0-9]+]], [[OLD]], 0(%r2)
22; CHECK: nr [[ROT]], %r3
23; CHECK: rll [[NEW:%r[0-9]+]], [[ROT]], 0({{%r[1-9]+}})
24; CHECK: cs [[OLD]], [[NEW]], 0([[RISBG]])
25; CHECK: jl [[LABEL]]
26; CHECK: rll %r2, [[OLD]], 16(%r2)
27; CHECK: br %r14
28;
29; CHECK-SHIFT1-LABEL: f1:
30; CHECK-SHIFT1: sll %r2, 3
31; CHECK-SHIFT1: lcr [[NEGSHIFT:%r[1-9]+]], %r2
32; CHECK-SHIFT1: rll
33; CHECK-SHIFT1: rll {{%r[0-9]+}}, {{%r[0-9]+}}, 0([[NEGSHIFT]])
34; CHECK-SHIFT1: rll
35; CHECK-SHIFT1: br %r14
36;
37; CHECK-SHIFT2-LABEL: f1:
38; CHECK-SHIFT2: sll %r3, 16
39; CHECK-SHIFT2: oill %r3, 65535
40; CHECK-SHIFT2: rll
41; CHECK-SHIFT2: nr {{%r[0-9]+}}, %r3
42; CHECK-SHIFT2: rll
43; CHECK-SHIFT2: rll
44; CHECK-SHIFT2: br %r14
45  %res = atomicrmw and i16 *%src, i16 %b seq_cst
46  ret i16 %res
47}
48
49; Check the minimum signed value.  We AND the rotated word with 0x8000ffff.
50define i16 @f2(i16 *%src) {
51; CHECK-LABEL: f2:
52; CHECK: risbg [[RISBG:%r[1-9]+]], %r2, 0, 189, 0{{$}}
53; CHECK: sll %r2, 3
54; CHECK: l [[OLD:%r[0-9]+]], 0([[RISBG]])
55; CHECK: [[LABEL:\.[^:]*]]:
56; CHECK: rll [[ROT:%r[0-9]+]], [[OLD]], 0(%r2)
57; CHECK: nilh [[ROT]], 32768
58; CHECK: rll [[NEW:%r[0-9]+]], [[ROT]], 0([[NEGSHIFT:%r[1-9]+]])
59; CHECK: cs [[OLD]], [[NEW]], 0([[RISBG]])
60; CHECK: jl [[LABEL]]
61; CHECK: rll %r2, [[OLD]], 16(%r2)
62; CHECK: br %r14
63;
64; CHECK-SHIFT1-LABEL: f2:
65; CHECK-SHIFT1: sll %r2, 3
66; CHECK-SHIFT1: lcr [[NEGSHIFT:%r[1-9]+]], %r2
67; CHECK-SHIFT1: rll
68; CHECK-SHIFT1: rll {{%r[0-9]+}}, {{%r[0-9]+}}, 0([[NEGSHIFT]])
69; CHECK-SHIFT1: rll
70; CHECK-SHIFT1: br %r14
71;
72; CHECK-SHIFT2-LABEL: f2:
73; CHECK-SHIFT2: br %r14
74  %res = atomicrmw and i16 *%src, i16 -32768 seq_cst
75  ret i16 %res
76}
77
78; Check ANDs of -2 (-1 isn't useful).  We AND the rotated word with 0xfffeffff.
79define i16 @f3(i16 *%src) {
80; CHECK-LABEL: f3:
81; CHECK: nilh [[ROT]], 65534
82; CHECK: br %r14
83;
84; CHECK-SHIFT1-LABEL: f3:
85; CHECK-SHIFT1: br %r14
86; CHECK-SHIFT2-LABEL: f3:
87; CHECK-SHIFT2: br %r14
88  %res = atomicrmw and i16 *%src, i16 -2 seq_cst
89  ret i16 %res
90}
91
92; Check ANDs of 1.  We AND the rotated word with 0x0001ffff.
93define i16 @f4(i16 *%src) {
94; CHECK-LABEL: f4:
95; CHECK: nilh [[ROT]], 1
96; CHECK: br %r14
97;
98; CHECK-SHIFT1-LABEL: f4:
99; CHECK-SHIFT1: br %r14
100; CHECK-SHIFT2-LABEL: f4:
101; CHECK-SHIFT2: br %r14
102  %res = atomicrmw and i16 *%src, i16 1 seq_cst
103  ret i16 %res
104}
105
106; Check the maximum signed value.  We AND the rotated word with 0x7fffffff.
107define i16 @f5(i16 *%src) {
108; CHECK-LABEL: f5:
109; CHECK: nilh [[ROT]], 32767
110; CHECK: br %r14
111;
112; CHECK-SHIFT1-LABEL: f5:
113; CHECK-SHIFT1: br %r14
114; CHECK-SHIFT2-LABEL: f5:
115; CHECK-SHIFT2: br %r14
116  %res = atomicrmw and i16 *%src, i16 32767 seq_cst
117  ret i16 %res
118}
119
120; Check ANDs of a large unsigned value.  We AND the rotated word with
121; 0xfffdffff.
122define i16 @f6(i16 *%src) {
123; CHECK-LABEL: f6:
124; CHECK: nilh [[ROT]], 65533
125; CHECK: br %r14
126;
127; CHECK-SHIFT1-LABEL: f6:
128; CHECK-SHIFT1: br %r14
129; CHECK-SHIFT2-LABEL: f6:
130; CHECK-SHIFT2: br %r14
131  %res = atomicrmw and i16 *%src, i16 65533 seq_cst
132  ret i16 %res
133}
134