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