1 ; Test sequences that can use RNSBG.
3 ; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
5 ; Test a simple mask, which is a wrap-around case.
6 define i32 @f1(i32 %a, i32 %b) {
8 ; CHECK: rnsbg %r2, %r3, 59, 56, 0
11 %and = and i32 %a, %orb
15 ; ...and again with i64.
16 define i64 @f2(i64 %a, i64 %b) {
18 ; CHECK: rnsbg %r2, %r3, 59, 56, 0
21 %and = and i64 %a, %orb
25 ; Test a case where no wraparound is needed.
26 define i32 @f3(i32 %a, i32 %b) {
28 ; CHECK: rnsbg %r2, %r3, 58, 61, 0
31 %and = and i32 %a, %orb
35 ; ...and again with i64.
36 define i64 @f4(i64 %a, i64 %b) {
38 ; CHECK: rnsbg %r2, %r3, 58, 61, 0
41 %and = and i64 %a, %orb
45 ; Test a case with just a left shift. This can't use RNSBG.
46 define i32 @f6(i32 %a, i32 %b) {
48 ; CHECK: sll {{%r[0-5]}}
49 ; CHECK: nr {{%r[0-5]}}
51 %shrb = shl i32 %b, 20
52 %and = and i32 %a, %shrb
56 ; ...and again with i64.
57 define i64 @f7(i64 %a, i64 %b) {
59 ; CHECK: sllg {{%r[0-5]}}
60 ; CHECK: ngr {{%r[0-5]}}
62 %shrb = shl i64 %b, 20
63 %and = and i64 %a, %shrb
67 ; Test a case with just a rotate. This can't use RNSBG.
68 define i32 @f8(i32 %a, i32 %b) {
70 ; CHECK: rll {{%r[0-5]}}
71 ; CHECK: nr {{%r[0-5]}}
73 %shlb = shl i32 %b, 22
74 %shrb = lshr i32 %b, 10
75 %rotlb = or i32 %shlb, %shrb
76 %and = and i32 %a, %rotlb
80 ; ...and again with i64, which can.
81 define i64 @f9(i64 %a, i64 %b) {
83 ; CHECK: rnsbg %r2, %r3, 0, 63, 44
85 %shlb = shl i64 %b, 44
86 %shrb = lshr i64 %b, 20
87 %rotlb = or i64 %shlb, %shrb
88 %and = and i64 %a, %rotlb
92 ; Test a case with a left shift and OR, where the OR covers all shifted bits.
93 ; We can do the whole thing using RNSBG.
94 define i32 @f10(i32 %a, i32 %b) {
96 ; CHECK: rnsbg %r2, %r3, 32, 56, 7
99 %orb = or i32 %shlb, 127
100 %and = and i32 %a, %orb
104 ; ...and again with i64.
105 define i64 @f11(i64 %a, i64 %b) {
107 ; CHECK: rnsbg %r2, %r3, 0, 56, 7
109 %shlb = shl i64 %b, 7
110 %orb = or i64 %shlb, 127
111 %and = and i64 %a, %orb
115 ; Test a case with a left shift and OR, where the OR doesn't cover all
116 ; shifted bits. We can't use RNSBG for the shift, but we can for the OR
118 define i32 @f12(i32 %a, i32 %b) {
121 ; CHECK: rnsbg %r2, %r3, 32, 57, 0
123 %shlb = shl i32 %b, 7
124 %orb = or i32 %shlb, 63
125 %and = and i32 %a, %orb
129 ; ...and again with i64.
130 define i64 @f13(i64 %a, i64 %b) {
132 ; CHECK: sllg [[REG:%r[01345]]], %r3, 7
133 ; CHECK: rnsbg %r2, [[REG]], 0, 57, 0
135 %shlb = shl i64 %b, 7
136 %orb = or i64 %shlb, 63
137 %and = and i64 %a, %orb
141 ; Test a case with a right shift and OR, where the OR covers all the shifted
142 ; bits. The whole thing can be done using RNSBG.
143 define i32 @f14(i32 %a, i32 %b) {
145 ; CHECK: rnsbg %r2, %r3, 60, 63, 37
147 %shrb = lshr i32 %b, 27
148 %orb = or i32 %shrb, -16
149 %and = and i32 %a, %orb
153 ; ...and again with i64.
154 define i64 @f15(i64 %a, i64 %b) {
156 ; CHECK: rnsbg %r2, %r3, 60, 63, 5
158 %shrb = lshr i64 %b, 59
159 %orb = or i64 %shrb, -16
160 %and = and i64 %a, %orb
164 ; Test a case with a right shift and OR, where the OR doesn't cover all the
165 ; shifted bits. The shift needs to be done separately, but the OR and AND
167 define i32 @f16(i32 %a, i32 %b) {
170 ; CHECK: rnsbg %r2, %r3, 60, 63, 0
172 %shrb = lshr i32 %b, 29
173 %orb = or i32 %shrb, -16
174 %and = and i32 %a, %orb
178 ; ...and again with i64.
179 define i64 @f17(i64 %a, i64 %b) {
181 ; CHECK: srlg [[REG:%r[01345]]], %r3, 61
182 ; CHECK: rnsbg %r2, [[REG]], 60, 63, 0
184 %shrb = lshr i64 %b, 61
185 %orb = or i64 %shrb, -16
186 %and = and i64 %a, %orb
190 ; Test a combination involving an ASHR in which the sign bits matter.
191 ; We can't use RNSBG for the ASHR in that case, but we can for the rest.
192 define i32 @f18(i32 %a, i32 %b, ptr %dest) {
195 ; CHECK: rnsbg %r2, %r3, 32, 62, 1
197 %ashrb = ashr i32 %b, 4
198 store i32 %ashrb, ptr %dest
199 %shlb = shl i32 %ashrb, 1
200 %orb = or i32 %shlb, 1
201 %and = and i32 %a, %orb
205 ; ...and again with i64.
206 define i64 @f19(i64 %a, i64 %b, ptr %dest) {
208 ; CHECK: srag [[REG:%r[0145]]], %r3, 34
209 ; CHECK: rnsbg %r2, [[REG]], 0, 62, 1
211 %ashrb = ashr i64 %b, 34
212 store i64 %ashrb, ptr %dest
213 %shlb = shl i64 %ashrb, 1
214 %orb = or i64 %shlb, 1
215 %and = and i64 %a, %orb
219 ; Test a combination involving an ASHR in which the sign bits don't matter.
220 define i32 @f20(i32 %a, i32 %b, ptr %dest) {
223 ; CHECK: rnsbg %r2, %r3, 48, 62, 1
225 %ashrb = ashr i32 %b, 17
226 store i32 %ashrb, ptr %dest
227 %shlb = shl i32 %ashrb, 1
228 %orb = or i32 %shlb, -65535
229 %and = and i32 %a, %orb
233 ; ...and again with i64.
234 define i64 @f21(i64 %a, i64 %b, ptr %dest) {
236 ; CHECK: rnsbg %r2, %r0, 48, 62, 1
238 %ashrb = ashr i64 %b, 49
239 store i64 %ashrb, ptr %dest
240 %shlb = shl i64 %ashrb, 1
241 %orb = or i64 %shlb, -65535
242 %and = and i64 %a, %orb
246 ; Test a case with a shift, OR, and rotate where the OR covers all shifted bits.
247 define i64 @f22(i64 %a, i64 %b) {
249 ; CHECK: rnsbg %r2, %r3, 60, 54, 9
251 %shlb = shl i64 %b, 5
252 %orb = or i64 %shlb, 31
253 %shlorb = shl i64 %orb, 4
254 %shrorb = lshr i64 %orb, 60
255 %rotlorb = or i64 %shlorb, %shrorb
256 %and = and i64 %a, %rotlorb
260 ; Check the handling of zext and AND, which isn't suitable for RNSBG.
261 define i64 @f23(i64 %a, i32 %b) {
266 %ext = zext i32 %add to i64
267 %and = and i64 %a, %ext