1; Test 8-bit unsigned comparisons between memory and constants.
2;
3; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
4
5; Check ordered comparisons near the low end of the unsigned 8-bit range.
6define double @f1(double %a, double %b, i8 *%ptr) {
7; CHECK-LABEL: f1:
8; CHECK: cli 0(%r2), 1
9; CHECK-NEXT: bhr %r14
10; CHECK: br %r14
11  %val = load i8, i8 *%ptr
12  %cond = icmp ugt i8 %val, 1
13  %res = select i1 %cond, double %a, double %b
14  ret double %res
15}
16
17; Check ordered comparisons near the high end of the unsigned 8-bit range.
18define double @f2(double %a, double %b, i8 *%ptr) {
19; CHECK-LABEL: f2:
20; CHECK: cli 0(%r2), 254
21; CHECK-NEXT: blr %r14
22; CHECK: br %r14
23  %val = load i8, i8 *%ptr
24  %cond = icmp ult i8 %val, 254
25  %res = select i1 %cond, double %a, double %b
26  ret double %res
27}
28
29; Check tests for negative bytes.
30define double @f3(double %a, double %b, i8 *%ptr) {
31; CHECK-LABEL: f3:
32; CHECK: cli 0(%r2), 127
33; CHECK-NEXT: bhr %r14
34; CHECK: br %r14
35  %val = load i8, i8 *%ptr
36  %cond = icmp slt i8 %val, 0
37  %res = select i1 %cond, double %a, double %b
38  ret double %res
39}
40
41; ...and an alternative form.
42define double @f4(double %a, double %b, i8 *%ptr) {
43; CHECK-LABEL: f4:
44; CHECK: cli 0(%r2), 127
45; CHECK-NEXT: bhr %r14
46; CHECK: br %r14
47  %val = load i8, i8 *%ptr
48  %cond = icmp sle i8 %val, -1
49  %res = select i1 %cond, double %a, double %b
50  ret double %res
51}
52
53; Check tests for non-negative bytes.
54define double @f5(double %a, double %b, i8 *%ptr) {
55; CHECK-LABEL: f5:
56; CHECK: cli 0(%r2), 128
57; CHECK-NEXT: blr %r14
58; CHECK: br %r14
59  %val = load i8, i8 *%ptr
60  %cond = icmp sge i8 %val, 0
61  %res = select i1 %cond, double %a, double %b
62  ret double %res
63}
64
65; ...and an alternative form.
66define double @f6(double %a, double %b, i8 *%ptr) {
67; CHECK-LABEL: f6:
68; CHECK: cli 0(%r2), 128
69; CHECK-NEXT: blr %r14
70; CHECK: br %r14
71  %val = load i8, i8 *%ptr
72  %cond = icmp sgt i8 %val, -1
73  %res = select i1 %cond, double %a, double %b
74  ret double %res
75}
76
77; Check equality comparisons at the low end of the signed 8-bit range.
78define double @f7(double %a, double %b, i8 *%ptr) {
79; CHECK-LABEL: f7:
80; CHECK: cli 0(%r2), 128
81; CHECK-NEXT: ber %r14
82; CHECK: br %r14
83  %val = load i8, i8 *%ptr
84  %cond = icmp eq i8 %val, -128
85  %res = select i1 %cond, double %a, double %b
86  ret double %res
87}
88
89; Check equality comparisons at the low end of the unsigned 8-bit range.
90define double @f8(double %a, double %b, i8 *%ptr) {
91; CHECK-LABEL: f8:
92; CHECK: cli 0(%r2), 0
93; CHECK-NEXT: ber %r14
94; CHECK: br %r14
95  %val = load i8, i8 *%ptr
96  %cond = icmp eq i8 %val, 0
97  %res = select i1 %cond, double %a, double %b
98  ret double %res
99}
100
101; Check equality comparisons at the high end of the signed 8-bit range.
102define double @f9(double %a, double %b, i8 *%ptr) {
103; CHECK-LABEL: f9:
104; CHECK: cli 0(%r2), 127
105; CHECK-NEXT: ber %r14
106; CHECK: br %r14
107  %val = load i8, i8 *%ptr
108  %cond = icmp eq i8 %val, 127
109  %res = select i1 %cond, double %a, double %b
110  ret double %res
111}
112
113; Check equality comparisons at the high end of the unsigned 8-bit range.
114define double @f10(double %a, double %b, i8 *%ptr) {
115; CHECK-LABEL: f10:
116; CHECK: cli 0(%r2), 255
117; CHECK-NEXT: ber %r14
118; CHECK: br %r14
119  %val = load i8, i8 *%ptr
120  %cond = icmp eq i8 %val, 255
121  %res = select i1 %cond, double %a, double %b
122  ret double %res
123}
124
125; Check the high end of the CLI range.
126define double @f11(double %a, double %b, i8 *%src) {
127; CHECK-LABEL: f11:
128; CHECK: cli 4095(%r2), 127
129; CHECK: br %r14
130  %ptr = getelementptr i8, i8 *%src, i64 4095
131  %val = load i8, i8 *%ptr
132  %cond = icmp ult i8 %val, 127
133  %res = select i1 %cond, double %a, double %b
134  ret double %res
135}
136
137; Check the next byte up, which should use CLIY instead of CLI.
138define double @f12(double %a, double %b, i8 *%src) {
139; CHECK-LABEL: f12:
140; CHECK: cliy 4096(%r2), 127
141; CHECK: br %r14
142  %ptr = getelementptr i8, i8 *%src, i64 4096
143  %val = load i8, i8 *%ptr
144  %cond = icmp ult i8 %val, 127
145  %res = select i1 %cond, double %a, double %b
146  ret double %res
147}
148
149; Check the high end of the CLIY range.
150define double @f13(double %a, double %b, i8 *%src) {
151; CHECK-LABEL: f13:
152; CHECK: cliy 524287(%r2), 127
153; CHECK: br %r14
154  %ptr = getelementptr i8, i8 *%src, i64 524287
155  %val = load i8, i8 *%ptr
156  %cond = icmp ult i8 %val, 127
157  %res = select i1 %cond, double %a, double %b
158  ret double %res
159}
160
161; Check the next byte up, which needs separate address logic.
162; Other sequences besides this one would be OK.
163define double @f14(double %a, double %b, i8 *%src) {
164; CHECK-LABEL: f14:
165; CHECK: agfi %r2, 524288
166; CHECK: cli 0(%r2), 127
167; CHECK: br %r14
168  %ptr = getelementptr i8, i8 *%src, i64 524288
169  %val = load i8, i8 *%ptr
170  %cond = icmp ult i8 %val, 127
171  %res = select i1 %cond, double %a, double %b
172  ret double %res
173}
174
175; Check the high end of the negative CLIY range.
176define double @f15(double %a, double %b, i8 *%src) {
177; CHECK-LABEL: f15:
178; CHECK: cliy -1(%r2), 127
179; CHECK: br %r14
180  %ptr = getelementptr i8, i8 *%src, i64 -1
181  %val = load i8, i8 *%ptr
182  %cond = icmp ult i8 %val, 127
183  %res = select i1 %cond, double %a, double %b
184  ret double %res
185}
186
187; Check the low end of the CLIY range.
188define double @f16(double %a, double %b, i8 *%src) {
189; CHECK-LABEL: f16:
190; CHECK: cliy -524288(%r2), 127
191; CHECK: br %r14
192  %ptr = getelementptr i8, i8 *%src, i64 -524288
193  %val = load i8, i8 *%ptr
194  %cond = icmp ult i8 %val, 127
195  %res = select i1 %cond, double %a, double %b
196  ret double %res
197}
198
199; Check the next byte down, which needs separate address logic.
200; Other sequences besides this one would be OK.
201define double @f17(double %a, double %b, i8 *%src) {
202; CHECK-LABEL: f17:
203; CHECK: agfi %r2, -524289
204; CHECK: cli 0(%r2), 127
205; CHECK: br %r14
206  %ptr = getelementptr i8, i8 *%src, i64 -524289
207  %val = load i8, i8 *%ptr
208  %cond = icmp ult i8 %val, 127
209  %res = select i1 %cond, double %a, double %b
210  ret double %res
211}
212
213; Check that CLI does not allow an index
214define double @f18(double %a, double %b, i64 %base, i64 %index) {
215; CHECK-LABEL: f18:
216; CHECK: agr %r2, %r3
217; CHECK: cli 4095(%r2), 127
218; CHECK: br %r14
219  %add1 = add i64 %base, %index
220  %add2 = add i64 %add1, 4095
221  %ptr = inttoptr i64 %add2 to i8 *
222  %val = load i8, i8 *%ptr
223  %cond = icmp ult i8 %val, 127
224  %res = select i1 %cond, double %a, double %b
225  ret double %res
226}
227
228; Check that CLIY does not allow an index
229define double @f19(double %a, double %b, i64 %base, i64 %index) {
230; CHECK-LABEL: f19:
231; CHECK: agr %r2, %r3
232; CHECK: cliy 4096(%r2), 127
233; CHECK: br %r14
234  %add1 = add i64 %base, %index
235  %add2 = add i64 %add1, 4096
236  %ptr = inttoptr i64 %add2 to i8 *
237  %val = load i8, i8 *%ptr
238  %cond = icmp ult i8 %val, 127
239  %res = select i1 %cond, double %a, double %b
240  ret double %res
241}
242