1 ; Test 32-bit signed comparisons between memory and a constant.
3 ; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
5 ; Check ordered comparisons with 0.
6 define double @f1(double %a, double %b, ptr %ptr) {
8 ; CHECK: chsi 0(%r2), 0
12 %val = load i32, ptr %ptr
13 %cond = icmp slt i32 %val, 0
14 %res = select i1 %cond, double %a, double %b
18 ; Check ordered comparisons with 1.
19 define double @f2(double %a, double %b, ptr %ptr) {
21 ; CHECK: chsi 0(%r2), 0
22 ; CHECK-NEXT: bler %r14
25 %val = load i32, ptr %ptr
26 %cond = icmp slt i32 %val, 1
27 %res = select i1 %cond, double %a, double %b
31 ; Check ordered comparisons with the high end of the signed 16-bit range.
32 define double @f3(double %a, double %b, ptr %ptr) {
34 ; CHECK: chsi 0(%r2), 32767
35 ; CHECK-NEXT: blr %r14
38 %val = load i32, ptr %ptr
39 %cond = icmp slt i32 %val, 32767
40 %res = select i1 %cond, double %a, double %b
44 ; Check the next value up, which can't use CHSI.
45 define double @f4(double %a, double %b, ptr %ptr) {
49 %val = load i32, ptr %ptr
50 %cond = icmp slt i32 %val, 32768
51 %res = select i1 %cond, double %a, double %b
55 ; Check ordered comparisons with -1.
56 define double @f5(double %a, double %b, ptr %ptr) {
58 ; CHECK: chsi 0(%r2), -1
59 ; CHECK-NEXT: blr %r14
62 %val = load i32, ptr %ptr
63 %cond = icmp slt i32 %val, -1
64 %res = select i1 %cond, double %a, double %b
68 ; Check ordered comparisons with the low end of the 16-bit signed range.
69 define double @f6(double %a, double %b, ptr %ptr) {
71 ; CHECK: chsi 0(%r2), -32768
72 ; CHECK-NEXT: blr %r14
75 %val = load i32, ptr %ptr
76 %cond = icmp slt i32 %val, -32768
77 %res = select i1 %cond, double %a, double %b
81 ; Check the next value down, which can't use CHSI.
82 define double @f7(double %a, double %b, ptr %ptr) {
86 %val = load i32, ptr %ptr
87 %cond = icmp slt i32 %val, -32769
88 %res = select i1 %cond, double %a, double %b
92 ; Check equality comparisons with 0.
93 define double @f8(double %a, double %b, ptr %ptr) {
95 ; CHECK: chsi 0(%r2), 0
96 ; CHECK-NEXT: ber %r14
99 %val = load i32, ptr %ptr
100 %cond = icmp eq i32 %val, 0
101 %res = select i1 %cond, double %a, double %b
105 ; Check equality comparisons with 1.
106 define double @f9(double %a, double %b, ptr %ptr) {
108 ; CHECK: chsi 0(%r2), 1
109 ; CHECK-NEXT: ber %r14
110 ; CHECK: ldr %f0, %f2
112 %val = load i32, ptr %ptr
113 %cond = icmp eq i32 %val, 1
114 %res = select i1 %cond, double %a, double %b
118 ; Check equality comparisons with the high end of the signed 16-bit range.
119 define double @f10(double %a, double %b, ptr %ptr) {
121 ; CHECK: chsi 0(%r2), 32767
122 ; CHECK-NEXT: ber %r14
123 ; CHECK: ldr %f0, %f2
125 %val = load i32, ptr %ptr
126 %cond = icmp eq i32 %val, 32767
127 %res = select i1 %cond, double %a, double %b
131 ; Check the next value up, which can't use CHSI.
132 define double @f11(double %a, double %b, ptr %ptr) {
136 %val = load i32, ptr %ptr
137 %cond = icmp eq i32 %val, 32768
138 %res = select i1 %cond, double %a, double %b
142 ; Check equality comparisons with -1.
143 define double @f12(double %a, double %b, ptr %ptr) {
145 ; CHECK: chsi 0(%r2), -1
146 ; CHECK-NEXT: ber %r14
147 ; CHECK: ldr %f0, %f2
149 %val = load i32, ptr %ptr
150 %cond = icmp eq i32 %val, -1
151 %res = select i1 %cond, double %a, double %b
155 ; Check equality comparisons with the low end of the 16-bit signed range.
156 define double @f13(double %a, double %b, ptr %ptr) {
158 ; CHECK: chsi 0(%r2), -32768
159 ; CHECK-NEXT: ber %r14
160 ; CHECK: ldr %f0, %f2
162 %val = load i32, ptr %ptr
163 %cond = icmp eq i32 %val, -32768
164 %res = select i1 %cond, double %a, double %b
168 ; Check the next value down, which should be treated as a positive value.
169 define double @f14(double %a, double %b, ptr %ptr) {
173 %val = load i32, ptr %ptr
174 %cond = icmp eq i32 %val, -32769
175 %res = select i1 %cond, double %a, double %b
179 ; Check the high end of the CHSI range.
180 define double @f15(double %a, double %b, i32 %i1, ptr %base) {
182 ; CHECK: chsi 4092(%r3), 0
183 ; CHECK-NEXT: blr %r14
184 ; CHECK: ldr %f0, %f2
186 %ptr = getelementptr i32, ptr %base, i64 1023
187 %val = load i32, ptr %ptr
188 %cond = icmp slt i32 %val, 0
189 %res = select i1 %cond, double %a, double %b
193 ; Check the next word up, which needs separate address logic,
194 define double @f16(double %a, double %b, ptr %base) {
196 ; CHECK: aghi %r2, 4096
197 ; CHECK: chsi 0(%r2), 0
198 ; CHECK-NEXT: blr %r14
199 ; CHECK: ldr %f0, %f2
201 %ptr = getelementptr i32, ptr %base, i64 1024
202 %val = load i32, ptr %ptr
203 %cond = icmp slt i32 %val, 0
204 %res = select i1 %cond, double %a, double %b
208 ; Check negative offsets, which also need separate address logic.
209 define double @f17(double %a, double %b, ptr %base) {
211 ; CHECK: aghi %r2, -4
212 ; CHECK: chsi 0(%r2), 0
213 ; CHECK-NEXT: blr %r14
214 ; CHECK: ldr %f0, %f2
216 %ptr = getelementptr i32, ptr %base, i64 -1
217 %val = load i32, ptr %ptr
218 %cond = icmp slt i32 %val, 0
219 %res = select i1 %cond, double %a, double %b
223 ; Check that CHSI does not allow indices.
224 define double @f18(double %a, double %b, i64 %base, i64 %index) {
226 ; CHECK: agr {{%r2, %r3|%r3, %r2}}
227 ; CHECK: chsi 0({{%r[23]}}), 0
228 ; CHECK-NEXT: blr %r14
229 ; CHECK: ldr %f0, %f2
231 %add = add i64 %base, %index
232 %ptr = inttoptr i64 %add to ptr
233 %val = load i32, ptr %ptr
234 %cond = icmp slt i32 %val, 0
235 %res = select i1 %cond, double %a, double %b