1 ; Test 32-bit arithmetic shifts right.
3 ; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
5 ; Check the low end of the SRAG range.
6 define i64 @f1(i64 %a) {
8 ; CHECK: srag %r2, %r2, 1
10 %shift = ashr i64 %a, 1
14 ; Check the high end of the defined SRAG range.
15 define i64 @f2(i64 %a) {
17 ; CHECK: srag %r2, %r2, 63
19 %shift = ashr i64 %a, 63
23 ; We don't generate shifts by out-of-range values.
24 define i64 @f3(i64 %a) {
28 %shift = ashr i64 %a, 64
32 ; Check variable shifts.
33 define i64 @f4(i64 %a, i64 %amt) {
35 ; CHECK: srag %r2, %r2, 0(%r3)
37 %shift = ashr i64 %a, %amt
41 ; Check shift amounts that have a constant term.
42 define i64 @f5(i64 %a, i64 %amt) {
44 ; CHECK: srag %r2, %r2, 10(%r3)
46 %add = add i64 %amt, 10
47 %shift = ashr i64 %a, %add
51 ; ...and again with a sign-extended 32-bit shift amount.
52 define i64 @f6(i64 %a, i32 %amt) {
54 ; CHECK: srag %r2, %r2, 10(%r3)
56 %add = add i32 %amt, 10
57 %addext = sext i32 %add to i64
58 %shift = ashr i64 %a, %addext
62 ; ...and now with a zero-extended 32-bit shift amount.
63 define i64 @f7(i64 %a, i32 %amt) {
65 ; CHECK: srag %r2, %r2, 10(%r3)
67 %add = add i32 %amt, 10
68 %addext = zext i32 %add to i64
69 %shift = ashr i64 %a, %addext
73 ; Check shift amounts that have the largest in-range constant term. We could
74 ; mask the amount instead.
75 define i64 @f8(i64 %a, i64 %amt) {
77 ; CHECK: srag %r2, %r2, 524287(%r3)
79 %add = add i64 %amt, 524287
80 %shift = ashr i64 %a, %add
84 ; Check the next value up, which without masking must use a separate
86 define i64 @f9(i64 %a, i64 %amt) {
88 ; CHECK: a{{g?}}fi %r3, 524288
89 ; CHECK: srag %r2, %r2, 0(%r3)
91 %add = add i64 %amt, 524288
92 %shift = ashr i64 %a, %add
96 ; Check cases where 1 is subtracted from the shift amount.
97 define i64 @f10(i64 %a, i64 %amt) {
99 ; CHECK: srag %r2, %r2, -1(%r3)
101 %sub = sub i64 %amt, 1
102 %shift = ashr i64 %a, %sub
106 ; Check the lowest value that can be subtracted from the shift amount.
107 ; Again, we could mask the shift amount instead.
108 define i64 @f11(i64 %a, i64 %amt) {
110 ; CHECK: srag %r2, %r2, -524288(%r3)
112 %sub = sub i64 %amt, 524288
113 %shift = ashr i64 %a, %sub
117 ; Check the next value down, which without masking must use a separate
119 define i64 @f12(i64 %a, i64 %amt) {
121 ; CHECK: a{{g?}}fi %r3, -524289
122 ; CHECK: srag %r2, %r2, 0(%r3)
124 %sub = sub i64 %amt, 524289
125 %shift = ashr i64 %a, %sub
129 ; Check that we don't try to generate "indexed" shifts.
130 define i64 @f13(i64 %a, i64 %b, i64 %c) {
132 ; CHECK: a{{g?}}r {{%r3, %r4|%r4, %r3}}
133 ; CHECK: srag %r2, %r2, 0({{%r[34]}})
135 %add = add i64 %b, %c
136 %shift = ashr i64 %a, %add
140 ; Check that the shift amount uses an address register. It cannot be in %r0.
141 define i64 @f14(i64 %a, i64 *%ptr) {
143 ; CHECK: l %r1, 4(%r3)
144 ; CHECK: srag %r2, %r2, 0(%r1)
146 %amt = load i64, i64 *%ptr
147 %shift = ashr i64 %a, %amt