1 ; Test insertions of 32-bit constants into one half of an i64.
3 ; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
5 ; Prefer LHI over IILF for signed 16-bit constants.
6 define i64 @f1(i64 %a) {
11 %and = and i64 %a, 18446744069414584320
16 ; Check the high end of the LHI range.
17 define i64 @f2(i64 %a) {
20 ; CHECK: lhi %r2, 32767
22 %and = and i64 %a, 18446744069414584320
23 %or = or i64 %and, 32767
27 ; Check the next value up, which should use IILF instead.
28 define i64 @f3(i64 %a) {
31 ; CHECK: iilf %r2, 32768
33 %and = and i64 %a, 18446744069414584320
34 %or = or i64 %and, 32768
38 ; Check a value in which the lower 16 bits are clear.
39 define i64 @f4(i64 %a) {
42 ; CHECK: iilf %r2, 65536
44 %and = and i64 %a, 18446744069414584320
45 %or = or i64 %and, 65536
49 ; Check the highest useful IILF value (-0x8001).
50 define i64 @f5(i64 %a) {
53 ; CHECK: iilf %r2, 4294934527
55 %and = and i64 %a, 18446744069414584320
56 %or = or i64 %and, 4294934527
60 ; Check the next value up, which should use LHI instead.
61 define i64 @f6(i64 %a) {
64 ; CHECK: lhi %r2, -32768
66 %and = and i64 %a, 18446744069414584320
67 %or = or i64 %and, 4294934528
71 ; Check the highest useful LHI value. (We use OILF for -1 instead, although
72 ; LHI might be better there too.)
73 define i64 @f7(i64 %a) {
78 %and = and i64 %a, 18446744069414584320
79 %or = or i64 %and, 4294967294
83 ; Check that SRLG is still used if some of the high bits are known to be 0
84 ; (and so might be removed from the mask).
85 define i64 @f8(i64 %a) {
87 ; CHECK: srlg %r2, %r2, 1
88 ; CHECK-NEXT: iilf %r2, 32768
90 %shifted = lshr i64 %a, 1
91 %and = and i64 %shifted, 18446744069414584320
92 %or = or i64 %and, 32768
96 ; Repeat f8 with addition, which is known to be equivalent to OR in this case.
97 define i64 @f9(i64 %a) {
99 ; CHECK: srlg %r2, %r2, 1
100 ; CHECK-NEXT: iilf %r2, 32768
102 %shifted = lshr i64 %a, 1
103 %and = and i64 %shifted, 18446744069414584320
104 %or = add i64 %and, 32768
108 ; Repeat f8 with already-zero bits removed from the mask.
109 define i64 @f10(i64 %a) {
111 ; CHECK: srlg %r2, %r2, 1
112 ; CHECK-NEXT: iilf %r2, 32768
114 %shifted = lshr i64 %a, 1
115 %and = and i64 %shifted, 9223372032559808512
116 %or = or i64 %and, 32768
120 ; Repeat f10 with addition, which is known to be equivalent to OR in this case.
121 define i64 @f11(i64 %a) {
123 ; CHECK: srlg %r2, %r2, 1
124 ; CHECK-NEXT: iilf %r2, 32768
126 %shifted = lshr i64 %a, 1
127 %and = and i64 %shifted, 9223372032559808512
128 %or = add i64 %and, 32768
132 ; Check the lowest useful IIHF value.
133 define i64 @f12(i64 %a) {
138 %and = and i64 %a, 4294967295
139 %or = or i64 %and, 4294967296
143 ; Check a value in which the lower 16 bits are clear.
144 define i64 @f13(i64 %a) {
147 ; CHECK: iihf %r2, 2147483648
149 %and = and i64 %a, 4294967295
150 %or = or i64 %and, 9223372036854775808
154 ; Check the highest useful IIHF value (0xfffffffe).
155 define i64 @f14(i64 %a) {
158 ; CHECK: iihf %r2, 4294967294
160 %and = and i64 %a, 4294967295
161 %or = or i64 %and, 18446744065119617024
165 ; Check a case in which some of the low 32 bits are known to be clear,
166 ; and so could be removed from the AND mask.
167 define i64 @f15(i64 %a) {
169 ; CHECK: sllg %r2, %r2, 1
170 ; CHECK-NEXT: iihf %r2, 1
172 %shifted = shl i64 %a, 1
173 %and = and i64 %shifted, 4294967295
174 %or = or i64 %and, 4294967296
178 ; Repeat f15 with the zero bits explicitly removed from the mask.
179 define i64 @f16(i64 %a) {
181 ; CHECK: sllg %r2, %r2, 1
182 ; CHECK-NEXT: iihf %r2, 1
184 %shifted = shl i64 %a, 1
185 %and = and i64 %shifted, 4294967294
186 %or = or i64 %and, 4294967296
190 ; Check concatenation of two i32s.
191 define i64 @f17(i32 %a) {
193 ; CHECK: msr %r2, %r2
194 ; CHECK-NEXT: iihf %r2, 1
196 %mul = mul i32 %a, %a
197 %ext = zext i32 %mul to i64
198 %or = or i64 %ext, 4294967296
202 ; Repeat f17 with the operands reversed.
203 define i64 @f18(i32 %a) {
205 ; CHECK: msr %r2, %r2
206 ; CHECK-NEXT: iihf %r2, 1
208 %mul = mul i32 %a, %a
209 %ext = zext i32 %mul to i64
210 %or = or i64 4294967296, %ext
214 ; The truncation here isn't free; we need an explicit zero extension.
215 define i64 @f19(i32 %a) {
217 ; CHECK: llgcr %r2, %r2
220 %trunc = trunc i32 %a to i8
221 %ext = zext i8 %trunc to i64
222 %or = or i64 %ext, 4294967296