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