1 ; Test 64-bit signed comparison in which the second operand is sign-extended
2 ; from an i16 memory value.
4 ; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
6 ; Check CGH with no displacement.
7 define void @f1(i64 %lhs, ptr %src, ptr %dst) {
9 ; CHECK: cgh %r2, 0(%r3)
11 %half = load i16, ptr %src
12 %rhs = sext i16 %half to i64
13 %cond = icmp slt i64 %lhs, %rhs
14 %res = select i1 %cond, i64 100, i64 200
15 store i64 %res, ptr %dst
19 ; Check the high end of the aligned CGH range.
20 define void @f2(i64 %lhs, ptr %src, ptr %dst) {
22 ; CHECK: cgh %r2, 524286(%r3)
24 %ptr = getelementptr i16, ptr %src, i64 262143
25 %half = load i16, ptr %ptr
26 %rhs = sext i16 %half to i64
27 %cond = icmp slt i64 %lhs, %rhs
28 %res = select i1 %cond, i64 100, i64 200
29 store i64 %res, ptr %dst
33 ; Check the next halfword up, which needs separate address logic.
34 ; Other sequences besides this one would be OK.
35 define void @f3(i64 %lhs, ptr %src, ptr %dst) {
37 ; CHECK: agfi %r3, 524288
38 ; CHECK: cgh %r2, 0(%r3)
40 %ptr = getelementptr i16, ptr %src, i64 262144
41 %half = load i16, ptr %ptr
42 %rhs = sext i16 %half to i64
43 %cond = icmp slt i64 %lhs, %rhs
44 %res = select i1 %cond, i64 100, i64 200
45 store i64 %res, ptr %dst
49 ; Check the high end of the negative aligned CGH range.
50 define void @f4(i64 %lhs, ptr %src, ptr %dst) {
52 ; CHECK: cgh %r2, -2(%r3)
54 %ptr = getelementptr i16, ptr %src, i64 -1
55 %half = load i16, ptr %ptr
56 %rhs = sext i16 %half to i64
57 %cond = icmp slt i64 %lhs, %rhs
58 %res = select i1 %cond, i64 100, i64 200
59 store i64 %res, ptr %dst
63 ; Check the low end of the CGH range.
64 define void @f5(i64 %lhs, ptr %src, ptr %dst) {
66 ; CHECK: cgh %r2, -524288(%r3)
68 %ptr = getelementptr i16, ptr %src, i64 -262144
69 %half = load i16, ptr %ptr
70 %rhs = sext i16 %half to i64
71 %cond = icmp slt i64 %lhs, %rhs
72 %res = select i1 %cond, i64 100, i64 200
73 store i64 %res, ptr %dst
77 ; Check the next halfword down, which needs separate address logic.
78 ; Other sequences besides this one would be OK.
79 define void @f6(i64 %lhs, ptr %src, ptr %dst) {
81 ; CHECK: agfi %r3, -524290
82 ; CHECK: cgh %r2, 0(%r3)
84 %ptr = getelementptr i16, ptr %src, i64 -262145
85 %half = load i16, ptr %ptr
86 %rhs = sext i16 %half to i64
87 %cond = icmp slt i64 %lhs, %rhs
88 %res = select i1 %cond, i64 100, i64 200
89 store i64 %res, ptr %dst
93 ; Check that CGH allows an index.
94 define void @f7(i64 %lhs, i64 %base, i64 %index, ptr %dst) {
96 ; CHECK: cgh %r2, 4096({{%r4,%r3|%r3,%r4}})
98 %add1 = add i64 %base, %index
99 %add2 = add i64 %add1, 4096
100 %ptr = inttoptr i64 %add2 to ptr
101 %half = load i16, ptr %ptr
102 %rhs = sext i16 %half to i64
103 %cond = icmp slt i64 %lhs, %rhs
104 %res = select i1 %cond, i64 100, i64 200
105 store i64 %res, ptr %dst
109 ; Check the comparison can be reversed if that allows CGH to be used.
110 define double @f8(double %a, double %b, i64 %rhs, ptr %src) {
112 ; CHECK: cgh %r2, 0(%r3)
113 ; CHECK-NEXT: bhr %r14
114 ; CHECK: ldr %f0, %f2
116 %half = load i16, ptr %src
117 %lhs = sext i16 %half to i64
118 %cond = icmp slt i64 %lhs, %rhs
119 %res = select i1 %cond, double %a, double %b