1 ; Test 64-bit ordered comparisons that are really between a memory halfword
4 ; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
6 ; Check unsigned comparison near the low end of the CLHHSI range, using zero
8 define double @f1(double %a, double %b, i16 *%ptr) {
10 ; CHECK: clhhsi 0(%r2), 1
11 ; CHECK-NEXT: bhr %r14
13 %val = load i16, i16 *%ptr
14 %ext = zext i16 %val to i64
15 %cond = icmp ugt i64 %ext, 1
16 %res = select i1 %cond, double %a, double %b
20 ; Check unsigned comparison near the low end of the CLHHSI range, using sign
22 define double @f2(double %a, double %b, i16 *%ptr) {
24 ; CHECK: clhhsi 0(%r2), 1
25 ; CHECK-NEXT: bhr %r14
27 %val = load i16, i16 *%ptr
28 %ext = sext i16 %val to i64
29 %cond = icmp ugt i64 %ext, 1
30 %res = select i1 %cond, double %a, double %b
34 ; Check unsigned comparison near the high end of the CLHHSI range, using zero
36 define double @f3(double %a, double %b, i16 *%ptr) {
38 ; CHECK: clhhsi 0(%r2), 65534
39 ; CHECK-NEXT: blr %r14
41 %val = load i16, i16 *%ptr
42 %ext = zext i16 %val to i64
43 %cond = icmp ult i64 %ext, 65534
44 %res = select i1 %cond, double %a, double %b
48 ; Check unsigned comparison near the high end of the CLHHSI range, using sign
50 define double @f4(double %a, double %b, i16 *%ptr) {
52 ; CHECK: clhhsi 0(%r2), 65534
53 ; CHECK-NEXT: blr %r14
55 %val = load i16, i16 *%ptr
56 %ext = sext i16 %val to i64
57 %cond = icmp ult i64 %ext, -2
58 %res = select i1 %cond, double %a, double %b
62 ; Check unsigned comparison above the high end of the CLHHSI range, using zero
63 ; extension. The condition is always true.
64 define double @f5(double %a, double %b, i16 *%ptr) {
68 %val = load i16, i16 *%ptr
69 %ext = zext i16 %val to i64
70 %cond = icmp ult i64 %ext, 65536
71 %res = select i1 %cond, double %a, double %b
75 ; When using unsigned comparison with sign extension, equality with values
76 ; in the range [32768, MAX-32769] is impossible, and ordered comparisons with
77 ; those values are effectively sign tests. Since such comparisons are
78 ; unlikely to occur in practice, we don't bother optimizing the second case,
79 ; and simply ignore CLHHSI for this range. First check the low end of the
81 define double @f6(double %a, double %b, i16 *%ptr) {
85 %val = load i16, i16 *%ptr
86 %ext = sext i16 %val to i64
87 %cond = icmp ult i64 %ext, 32768
88 %res = select i1 %cond, double %a, double %b
92 ; ...and then the high end.
93 define double @f7(double %a, double %b, i16 *%ptr) {
97 %val = load i16, i16 *%ptr
98 %ext = sext i16 %val to i64
99 %cond = icmp ult i64 %ext, -32769
100 %res = select i1 %cond, double %a, double %b
104 ; Check signed comparison near the low end of the CLHHSI range, using zero
105 ; extension. This is equivalent to unsigned comparison.
106 define double @f8(double %a, double %b, i16 *%ptr) {
108 ; CHECK: clhhsi 0(%r2), 1
109 ; CHECK-NEXT: bhr %r14
111 %val = load i16, i16 *%ptr
112 %ext = zext i16 %val to i64
113 %cond = icmp sgt i64 %ext, 1
114 %res = select i1 %cond, double %a, double %b
118 ; Check signed comparison near the low end of the CLHHSI range, using sign
119 ; extension. This should use CHHSI instead.
120 define double @f9(double %a, double %b, i16 *%ptr) {
122 ; CHECK: chhsi 0(%r2), 1
123 ; CHECK-NEXT: bhr %r14
125 %val = load i16, i16 *%ptr
126 %ext = sext i16 %val to i64
127 %cond = icmp sgt i64 %ext, 1
128 %res = select i1 %cond, double %a, double %b
132 ; Check signed comparison near the high end of the CLHHSI range, using zero
133 ; extension. This is equivalent to unsigned comparison.
134 define double @f10(double %a, double %b, i16 *%ptr) {
136 ; CHECK: clhhsi 0(%r2), 65534
137 ; CHECK-NEXT: blr %r14
139 %val = load i16, i16 *%ptr
140 %ext = zext i16 %val to i64
141 %cond = icmp slt i64 %ext, 65534
142 %res = select i1 %cond, double %a, double %b
146 ; Check signed comparison near the high end of the CLHHSI range, using sign
147 ; extension. This should use CHHSI instead.
148 define double @f11(double %a, double %b, i16 *%ptr) {
150 ; CHECK: chhsi 0(%r2), -2
151 ; CHECK-NEXT: blr %r14
153 %val = load i16, i16 *%ptr
154 %ext = sext i16 %val to i64
155 %cond = icmp slt i64 %ext, -2
156 %res = select i1 %cond, double %a, double %b
160 ; Check signed comparison above the high end of the CLHHSI range, using zero
161 ; extension. The condition is always true.
162 define double @f12(double %a, double %b, i16 *%ptr) {
166 %val = load i16, i16 *%ptr
167 %ext = zext i16 %val to i64
168 %cond = icmp slt i64 %ext, 65536
169 %res = select i1 %cond, double %a, double %b
173 ; Check signed comparison near the high end of the CHHSI range, using sign
175 define double @f13(double %a, double %b, i16 *%ptr) {
177 ; CHECK: chhsi 0(%r2), 32766
178 ; CHECK-NEXT: blr %r14
180 %val = load i16, i16 *%ptr
181 %ext = sext i16 %val to i64
182 %cond = icmp slt i64 %ext, 32766
183 %res = select i1 %cond, double %a, double %b
187 ; Check signed comparison above the high end of the CHHSI range, using sign
188 ; extension. This condition is always true.
189 define double @f14(double %a, double %b, i16 *%ptr) {
193 %val = load i16, i16 *%ptr
194 %ext = sext i16 %val to i64
195 %cond = icmp slt i64 %ext, 32768
196 %res = select i1 %cond, double %a, double %b
200 ; Check signed comparison near the low end of the CHHSI range, using sign
202 define double @f15(double %a, double %b, i16 *%ptr) {
204 ; CHECK: chhsi 0(%r2), -32767
205 ; CHECK-NEXT: bhr %r14
207 %val = load i16, i16 *%ptr
208 %ext = sext i16 %val to i64
209 %cond = icmp sgt i64 %ext, -32767
210 %res = select i1 %cond, double %a, double %b
214 ; Check signed comparison below the low end of the CHHSI range, using sign
215 ; extension. This condition is always true.
216 define double @f16(double %a, double %b, i16 *%ptr) {
220 %val = load i16, i16 *%ptr
221 %ext = sext i16 %val to i64
222 %cond = icmp sgt i64 %ext, -32769
223 %res = select i1 %cond, double %a, double %b