1; Test 16-bit unsigned comparisons between memory and a constant.
2;
3; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
4
5; Check a value near the low end of the unsigned 16-bit range.
6define double @f1(double %a, double %b, i16 *%ptr) {
7; CHECK-LABEL: f1:
8; CHECK: clhhsi 0(%r2), 1
9; CHECK-NEXT: bhr %r14
10; CHECK: ldr %f0, %f2
11; CHECK: br %r14
12  %val = load i16, i16 *%ptr
13  %cond = icmp ugt i16 %val, 1
14  %res = select i1 %cond, double %a, double %b
15  ret double %res
16}
17
18; Check a value near the high end of the unsigned 16-bit range.
19define double @f2(double %a, double %b, i16 *%ptr) {
20; CHECK-LABEL: f2:
21; CHECK: clhhsi 0(%r2), 65534
22; CHECK-NEXT: blr %r14
23; CHECK: ldr %f0, %f2
24; CHECK: br %r14
25  %val = load i16, i16 *%ptr
26  %cond = icmp ult i16 %val, 65534
27  %res = select i1 %cond, double %a, double %b
28  ret double %res
29}
30
31; Check the high end of the CLHHSI range.
32define double @f3(double %a, double %b, i16 %i1, i16 *%base) {
33; CHECK-LABEL: f3:
34; CHECK: clhhsi 4094(%r3), 1
35; CHECK-NEXT: bhr %r14
36; CHECK: ldr %f0, %f2
37; CHECK: br %r14
38  %ptr = getelementptr i16, i16 *%base, i64 2047
39  %val = load i16, i16 *%ptr
40  %cond = icmp ugt i16 %val, 1
41  %res = select i1 %cond, double %a, double %b
42  ret double %res
43}
44
45; Check the next halfword up, which needs separate address logic,
46define double @f4(double %a, double %b, i16 *%base) {
47; CHECK-LABEL: f4:
48; CHECK: aghi %r2, 4096
49; CHECK: clhhsi 0(%r2), 1
50; CHECK-NEXT: bhr %r14
51; CHECK: ldr %f0, %f2
52; CHECK: br %r14
53  %ptr = getelementptr i16, i16 *%base, i64 2048
54  %val = load i16, i16 *%ptr
55  %cond = icmp ugt i16 %val, 1
56  %res = select i1 %cond, double %a, double %b
57  ret double %res
58}
59
60; Check negative offsets, which also need separate address logic.
61define double @f5(double %a, double %b, i16 *%base) {
62; CHECK-LABEL: f5:
63; CHECK: aghi %r2, -2
64; CHECK: clhhsi 0(%r2), 1
65; CHECK-NEXT: bhr %r14
66; CHECK: ldr %f0, %f2
67; CHECK: br %r14
68  %ptr = getelementptr i16, i16 *%base, i64 -1
69  %val = load i16, i16 *%ptr
70  %cond = icmp ugt i16 %val, 1
71  %res = select i1 %cond, double %a, double %b
72  ret double %res
73}
74
75; Check that CLHHSI does not allow indices.
76define double @f6(double %a, double %b, i64 %base, i64 %index) {
77; CHECK-LABEL: f6:
78; CHECK: agr {{%r2, %r3|%r3, %r2}}
79; CHECK: clhhsi 0({{%r[23]}}), 1
80; CHECK-NEXT: bhr %r14
81; CHECK: ldr %f0, %f2
82; CHECK: br %r14
83  %add = add i64 %base, %index
84  %ptr = inttoptr i64 %add to i16 *
85  %val = load i16, i16 *%ptr
86  %cond = icmp ugt i16 %val, 1
87  %res = select i1 %cond, double %a, double %b
88  ret double %res
89}
90