1*9e3577ffSUlrich Weigand; Test insertions of 32-bit constants into one half of an i64.
2*9e3577ffSUlrich Weigand;
3*9e3577ffSUlrich Weigand; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
4*9e3577ffSUlrich Weigand
5*9e3577ffSUlrich Weigand; Prefer LHI over IILF for signed 16-bit constants.
6*9e3577ffSUlrich Weiganddefine i64 @f1(i64 %a) {
7*9e3577ffSUlrich Weigand; CHECK: f1:
8*9e3577ffSUlrich Weigand; CHECK-NOT: ni
9*9e3577ffSUlrich Weigand; CHECK: lhi %r2, 1
10*9e3577ffSUlrich Weigand; CHECK: br %r14
11*9e3577ffSUlrich Weigand  %and = and i64 %a, 18446744069414584320
12*9e3577ffSUlrich Weigand  %or = or i64 %and, 1
13*9e3577ffSUlrich Weigand  ret i64 %or
14*9e3577ffSUlrich Weigand}
15*9e3577ffSUlrich Weigand
16*9e3577ffSUlrich Weigand; Check the high end of the LHI range.
17*9e3577ffSUlrich Weiganddefine i64 @f2(i64 %a) {
18*9e3577ffSUlrich Weigand; CHECK: f2:
19*9e3577ffSUlrich Weigand; CHECK-NOT: ni
20*9e3577ffSUlrich Weigand; CHECK: lhi %r2, 32767
21*9e3577ffSUlrich Weigand; CHECK: br %r14
22*9e3577ffSUlrich Weigand  %and = and i64 %a, 18446744069414584320
23*9e3577ffSUlrich Weigand  %or = or i64 %and, 32767
24*9e3577ffSUlrich Weigand  ret i64 %or
25*9e3577ffSUlrich Weigand}
26*9e3577ffSUlrich Weigand
27*9e3577ffSUlrich Weigand; Check the next value up, which should use IILF instead.
28*9e3577ffSUlrich Weiganddefine i64 @f3(i64 %a) {
29*9e3577ffSUlrich Weigand; CHECK: f3:
30*9e3577ffSUlrich Weigand; CHECK-NOT: ni
31*9e3577ffSUlrich Weigand; CHECK: iilf %r2, 32768
32*9e3577ffSUlrich Weigand; CHECK: br %r14
33*9e3577ffSUlrich Weigand  %and = and i64 %a, 18446744069414584320
34*9e3577ffSUlrich Weigand  %or = or i64 %and, 32768
35*9e3577ffSUlrich Weigand  ret i64 %or
36*9e3577ffSUlrich Weigand}
37*9e3577ffSUlrich Weigand
38*9e3577ffSUlrich Weigand; Check a value in which the lower 16 bits are clear.
39*9e3577ffSUlrich Weiganddefine i64 @f4(i64 %a) {
40*9e3577ffSUlrich Weigand; CHECK: f4:
41*9e3577ffSUlrich Weigand; CHECK-NOT: ni
42*9e3577ffSUlrich Weigand; CHECK: iilf %r2, 65536
43*9e3577ffSUlrich Weigand; CHECK: br %r14
44*9e3577ffSUlrich Weigand  %and = and i64 %a, 18446744069414584320
45*9e3577ffSUlrich Weigand  %or = or i64 %and, 65536
46*9e3577ffSUlrich Weigand  ret i64 %or
47*9e3577ffSUlrich Weigand}
48*9e3577ffSUlrich Weigand
49*9e3577ffSUlrich Weigand; Check the highest useful IILF value (-0x8001).
50*9e3577ffSUlrich Weiganddefine i64 @f5(i64 %a) {
51*9e3577ffSUlrich Weigand; CHECK: f5:
52*9e3577ffSUlrich Weigand; CHECK-NOT: ni
53*9e3577ffSUlrich Weigand; CHECK: iilf %r2, 4294934527
54*9e3577ffSUlrich Weigand; CHECK: br %r14
55*9e3577ffSUlrich Weigand  %and = and i64 %a, 18446744069414584320
56*9e3577ffSUlrich Weigand  %or = or i64 %and, 4294934527
57*9e3577ffSUlrich Weigand  ret i64 %or
58*9e3577ffSUlrich Weigand}
59*9e3577ffSUlrich Weigand
60*9e3577ffSUlrich Weigand; Check the next value up, which should use LHI instead.
61*9e3577ffSUlrich Weiganddefine i64 @f6(i64 %a) {
62*9e3577ffSUlrich Weigand; CHECK: f6:
63*9e3577ffSUlrich Weigand; CHECK-NOT: ni
64*9e3577ffSUlrich Weigand; CHECK: lhi %r2, -32768
65*9e3577ffSUlrich Weigand; CHECK: br %r14
66*9e3577ffSUlrich Weigand  %and = and i64 %a, 18446744069414584320
67*9e3577ffSUlrich Weigand  %or = or i64 %and, 4294934528
68*9e3577ffSUlrich Weigand  ret i64 %or
69*9e3577ffSUlrich Weigand}
70*9e3577ffSUlrich Weigand
71*9e3577ffSUlrich Weigand; Check the highest useful LHI value.  (We use OILF for -1 instead, although
72*9e3577ffSUlrich Weigand; LHI might be better there too.)
73*9e3577ffSUlrich Weiganddefine i64 @f7(i64 %a) {
74*9e3577ffSUlrich Weigand; CHECK: f7:
75*9e3577ffSUlrich Weigand; CHECK-NOT: ni
76*9e3577ffSUlrich Weigand; CHECK: lhi %r2, -2
77*9e3577ffSUlrich Weigand; CHECK: br %r14
78*9e3577ffSUlrich Weigand  %and = and i64 %a, 18446744069414584320
79*9e3577ffSUlrich Weigand  %or = or i64 %and, 4294967294
80*9e3577ffSUlrich Weigand  ret i64 %or
81*9e3577ffSUlrich Weigand}
82*9e3577ffSUlrich Weigand
83*9e3577ffSUlrich Weigand; Check that SRLG is still used if some of the high bits are known to be 0
84*9e3577ffSUlrich Weigand; (and so might be removed from the mask).
85*9e3577ffSUlrich Weiganddefine i64 @f8(i64 %a) {
86*9e3577ffSUlrich Weigand; CHECK: f8:
87*9e3577ffSUlrich Weigand; CHECK: srlg %r2, %r2, 1
88*9e3577ffSUlrich Weigand; CHECK-NEXT: iilf %r2, 32768
89*9e3577ffSUlrich Weigand; CHECK: br %r14
90*9e3577ffSUlrich Weigand  %shifted = lshr i64 %a, 1
91*9e3577ffSUlrich Weigand  %and = and i64 %shifted, 18446744069414584320
92*9e3577ffSUlrich Weigand  %or = or i64 %and, 32768
93*9e3577ffSUlrich Weigand  ret i64 %or
94*9e3577ffSUlrich Weigand}
95*9e3577ffSUlrich Weigand
96*9e3577ffSUlrich Weigand; Repeat f8 with addition, which is known to be equivalent to OR in this case.
97*9e3577ffSUlrich Weiganddefine i64 @f9(i64 %a) {
98*9e3577ffSUlrich Weigand; CHECK: f9:
99*9e3577ffSUlrich Weigand; CHECK: srlg %r2, %r2, 1
100*9e3577ffSUlrich Weigand; CHECK-NEXT: iilf %r2, 32768
101*9e3577ffSUlrich Weigand; CHECK: br %r14
102*9e3577ffSUlrich Weigand  %shifted = lshr i64 %a, 1
103*9e3577ffSUlrich Weigand  %and = and i64 %shifted, 18446744069414584320
104*9e3577ffSUlrich Weigand  %or = add i64 %and, 32768
105*9e3577ffSUlrich Weigand  ret i64 %or
106*9e3577ffSUlrich Weigand}
107*9e3577ffSUlrich Weigand
108*9e3577ffSUlrich Weigand; Repeat f8 with already-zero bits removed from the mask.
109*9e3577ffSUlrich Weiganddefine i64 @f10(i64 %a) {
110*9e3577ffSUlrich Weigand; CHECK: f10:
111*9e3577ffSUlrich Weigand; CHECK: srlg %r2, %r2, 1
112*9e3577ffSUlrich Weigand; CHECK-NEXT: iilf %r2, 32768
113*9e3577ffSUlrich Weigand; CHECK: br %r14
114*9e3577ffSUlrich Weigand  %shifted = lshr i64 %a, 1
115*9e3577ffSUlrich Weigand  %and = and i64 %shifted, 9223372032559808512
116*9e3577ffSUlrich Weigand  %or = or i64 %and, 32768
117*9e3577ffSUlrich Weigand  ret i64 %or
118*9e3577ffSUlrich Weigand}
119*9e3577ffSUlrich Weigand
120*9e3577ffSUlrich Weigand; Repeat f10 with addition, which is known to be equivalent to OR in this case.
121*9e3577ffSUlrich Weiganddefine i64 @f11(i64 %a) {
122*9e3577ffSUlrich Weigand; CHECK: f11:
123*9e3577ffSUlrich Weigand; CHECK: srlg %r2, %r2, 1
124*9e3577ffSUlrich Weigand; CHECK-NEXT: iilf %r2, 32768
125*9e3577ffSUlrich Weigand; CHECK: br %r14
126*9e3577ffSUlrich Weigand  %shifted = lshr i64 %a, 1
127*9e3577ffSUlrich Weigand  %and = and i64 %shifted, 9223372032559808512
128*9e3577ffSUlrich Weigand  %or = add i64 %and, 32768
129*9e3577ffSUlrich Weigand  ret i64 %or
130*9e3577ffSUlrich Weigand}
131*9e3577ffSUlrich Weigand
132*9e3577ffSUlrich Weigand; Check the lowest useful IIHF value.
133*9e3577ffSUlrich Weiganddefine i64 @f12(i64 %a) {
134*9e3577ffSUlrich Weigand; CHECK: f12:
135*9e3577ffSUlrich Weigand; CHECK-NOT: ni
136*9e3577ffSUlrich Weigand; CHECK: iihf %r2, 1
137*9e3577ffSUlrich Weigand; CHECK: br %r14
138*9e3577ffSUlrich Weigand  %and = and i64 %a, 4294967295
139*9e3577ffSUlrich Weigand  %or = or i64 %and, 4294967296
140*9e3577ffSUlrich Weigand  ret i64 %or
141*9e3577ffSUlrich Weigand}
142*9e3577ffSUlrich Weigand
143*9e3577ffSUlrich Weigand; Check a value in which the lower 16 bits are clear.
144*9e3577ffSUlrich Weiganddefine i64 @f13(i64 %a) {
145*9e3577ffSUlrich Weigand; CHECK: f13:
146*9e3577ffSUlrich Weigand; CHECK-NOT: ni
147*9e3577ffSUlrich Weigand; CHECK: iihf %r2, 2147483648
148*9e3577ffSUlrich Weigand; CHECK: br %r14
149*9e3577ffSUlrich Weigand  %and = and i64 %a, 4294967295
150*9e3577ffSUlrich Weigand  %or = or i64 %and, 9223372036854775808
151*9e3577ffSUlrich Weigand  ret i64 %or
152*9e3577ffSUlrich Weigand}
153*9e3577ffSUlrich Weigand
154*9e3577ffSUlrich Weigand; Check the highest useful IIHF value (0xfffffffe).
155*9e3577ffSUlrich Weiganddefine i64 @f14(i64 %a) {
156*9e3577ffSUlrich Weigand; CHECK: f14:
157*9e3577ffSUlrich Weigand; CHECK-NOT: ni
158*9e3577ffSUlrich Weigand; CHECK: iihf %r2, 4294967294
159*9e3577ffSUlrich Weigand; CHECK: br %r14
160*9e3577ffSUlrich Weigand  %and = and i64 %a, 4294967295
161*9e3577ffSUlrich Weigand  %or = or i64 %and, 18446744065119617024
162*9e3577ffSUlrich Weigand  ret i64 %or
163*9e3577ffSUlrich Weigand}
164*9e3577ffSUlrich Weigand
165*9e3577ffSUlrich Weigand; Check a case in which some of the low 32 bits are known to be clear,
166*9e3577ffSUlrich Weigand; and so could be removed from the AND mask.
167*9e3577ffSUlrich Weiganddefine i64 @f15(i64 %a) {
168*9e3577ffSUlrich Weigand; CHECK: f15:
169*9e3577ffSUlrich Weigand; CHECK: sllg %r2, %r2, 1
170*9e3577ffSUlrich Weigand; CHECK-NEXT: iihf %r2, 1
171*9e3577ffSUlrich Weigand; CHECK: br %r14
172*9e3577ffSUlrich Weigand  %shifted = shl i64 %a, 1
173*9e3577ffSUlrich Weigand  %and = and i64 %shifted, 4294967295
174*9e3577ffSUlrich Weigand  %or = or i64 %and, 4294967296
175*9e3577ffSUlrich Weigand  ret i64 %or
176*9e3577ffSUlrich Weigand}
177*9e3577ffSUlrich Weigand
178*9e3577ffSUlrich Weigand; Repeat f15 with the zero bits explicitly removed from the mask.
179*9e3577ffSUlrich Weiganddefine i64 @f16(i64 %a) {
180*9e3577ffSUlrich Weigand; CHECK: f16:
181*9e3577ffSUlrich Weigand; CHECK: sllg %r2, %r2, 1
182*9e3577ffSUlrich Weigand; CHECK-NEXT: iihf %r2, 1
183*9e3577ffSUlrich Weigand; CHECK: br %r14
184*9e3577ffSUlrich Weigand  %shifted = shl i64 %a, 1
185*9e3577ffSUlrich Weigand  %and = and i64 %shifted, 4294967294
186*9e3577ffSUlrich Weigand  %or = or i64 %and, 4294967296
187*9e3577ffSUlrich Weigand  ret i64 %or
188*9e3577ffSUlrich Weigand}
189*9e3577ffSUlrich Weigand
190*9e3577ffSUlrich Weigand; Check concatenation of two i32s.
191*9e3577ffSUlrich Weiganddefine i64 @f17(i32 %a) {
192*9e3577ffSUlrich Weigand; CHECK: f17:
193*9e3577ffSUlrich Weigand; CHECK: msr %r2, %r2
194*9e3577ffSUlrich Weigand; CHECK-NEXT: iihf %r2, 1
195*9e3577ffSUlrich Weigand; CHECK: br %r14
196*9e3577ffSUlrich Weigand  %mul = mul i32 %a, %a
197*9e3577ffSUlrich Weigand  %ext = zext i32 %mul to i64
198*9e3577ffSUlrich Weigand  %or = or i64 %ext, 4294967296
199*9e3577ffSUlrich Weigand  ret i64 %or
200*9e3577ffSUlrich Weigand}
201*9e3577ffSUlrich Weigand
202*9e3577ffSUlrich Weigand; Repeat f17 with the operands reversed.
203*9e3577ffSUlrich Weiganddefine i64 @f18(i32 %a) {
204*9e3577ffSUlrich Weigand; CHECK: f18:
205*9e3577ffSUlrich Weigand; CHECK: msr %r2, %r2
206*9e3577ffSUlrich Weigand; CHECK-NEXT: iihf %r2, 1
207*9e3577ffSUlrich Weigand; CHECK: br %r14
208*9e3577ffSUlrich Weigand  %mul = mul i32 %a, %a
209*9e3577ffSUlrich Weigand  %ext = zext i32 %mul to i64
210*9e3577ffSUlrich Weigand  %or = or i64 4294967296, %ext
211*9e3577ffSUlrich Weigand  ret i64 %or
212*9e3577ffSUlrich Weigand}
213*9e3577ffSUlrich Weigand
214*9e3577ffSUlrich Weigand; The truncation here isn't free; we need an explicit zero extension.
215*9e3577ffSUlrich Weiganddefine i64 @f19(i32 %a) {
216*9e3577ffSUlrich Weigand; CHECK: f19:
217*9e3577ffSUlrich Weigand; CHECK: llgcr %r2, %r2
218*9e3577ffSUlrich Weigand; CHECK: oihl %r2, 1
219*9e3577ffSUlrich Weigand; CHECK: br %r14
220*9e3577ffSUlrich Weigand  %trunc = trunc i32 %a to i8
221*9e3577ffSUlrich Weigand  %ext = zext i8 %trunc to i64
222*9e3577ffSUlrich Weigand  %or = or i64 %ext, 4294967296
223*9e3577ffSUlrich Weigand  ret i64 %or
224*9e3577ffSUlrich Weigand}
225