1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; Test removal of AND operations that don't affect last 6 bits of shift amount
5 ; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z14 | FileCheck %s
7 ; Test that AND is not removed when some lower 6 bits are not set.
8 define i32 @f1(i32 %a, i32 %sh) {
11 ; CHECK-NEXT: nill %r3, 31
12 ; CHECK-NEXT: sll %r2, 0(%r3)
14 %and = and i32 %sh, 31
15 %shift = shl i32 %a, %and
19 ; Test removal of AND mask with only bottom 6 bits set.
20 define i32 @f2(i32 %a, i32 %sh) {
23 ; CHECK-NEXT: sll %r2, 0(%r3)
25 %and = and i32 %sh, 63
26 %shift = shl i32 %a, %and
30 ; Test removal of AND mask including but not limited to bottom 6 bits.
31 define i32 @f3(i32 %a, i32 %sh) {
34 ; CHECK-NEXT: sll %r2, 0(%r3)
36 %and = and i32 %sh, 255
37 %shift = shl i32 %a, %and
41 ; Test removal of AND mask from SRA.
42 define i32 @f4(i32 %a, i32 %sh) {
45 ; CHECK-NEXT: sra %r2, 0(%r3)
47 %and = and i32 %sh, 63
48 %shift = ashr i32 %a, %and
52 ; Test removal of AND mask from SRL.
53 define i32 @f5(i32 %a, i32 %sh) {
56 ; CHECK-NEXT: srl %r2, 0(%r3)
58 %and = and i32 %sh, 63
59 %shift = lshr i32 %a, %and
63 ; Test removal of AND mask from SLLG.
64 define i64 @f6(i64 %a, i64 %sh) {
67 ; CHECK-NEXT: sllg %r2, %r2, 0(%r3)
69 %and = and i64 %sh, 63
70 %shift = shl i64 %a, %and
74 ; Test removal of AND mask from SRAG.
75 define i64 @f7(i64 %a, i64 %sh) {
78 ; CHECK-NEXT: srag %r2, %r2, 0(%r3)
80 %and = and i64 %sh, 63
81 %shift = ashr i64 %a, %and
85 ; Test removal of AND mask from SRLG.
86 define i64 @f8(i64 %a, i64 %sh) {
89 ; CHECK-NEXT: srlg %r2, %r2, 0(%r3)
91 %and = and i64 %sh, 63
92 %shift = lshr i64 %a, %and
96 ; Test that AND with two register operands is not affected.
97 define i32 @f9(i32 %a, i32 %b, i32 %sh) {
100 ; CHECK-NEXT: nr %r3, %r4
101 ; CHECK-NEXT: sll %r2, 0(%r3)
102 ; CHECK-NEXT: br %r14
103 %and = and i32 %sh, %b
104 %shift = shl i32 %a, %and
108 ; Test that AND is not entirely removed if the result is reused.
109 define i32 @f10(i32 %a, i32 %sh) {
112 ; CHECK-NEXT: sll %r2, 0(%r3)
113 ; CHECK-NEXT: nilf %r3, 63
114 ; CHECK-NEXT: ar %r2, %r3
115 ; CHECK-NEXT: br %r14
116 %and = and i32 %sh, 63
117 %shift = shl i32 %a, %and
118 %reuse = add i32 %and, %shift
122 define i128 @f11(i128 %a, i32 %sh) {
125 ; CHECK-NEXT: vlvgp %v1, %r4, %r4
126 ; CHECK-NEXT: vl %v0, 0(%r3), 3
127 ; CHECK-NEXT: vrepb %v1, %v1, 15
128 ; CHECK-NEXT: vslb %v0, %v0, %v1
129 ; CHECK-NEXT: vsl %v0, %v0, %v1
130 ; CHECK-NEXT: vst %v0, 0(%r2), 3
131 ; CHECK-NEXT: br %r14
132 %and = and i32 %sh, 127
133 %ext = zext i32 %and to i128
134 %shift = shl i128 %a, %ext
138 define i128 @f12(i128 %a, i32 %sh) {
141 ; CHECK-NEXT: vlvgp %v1, %r4, %r4
142 ; CHECK-NEXT: vl %v0, 0(%r3), 3
143 ; CHECK-NEXT: vrepb %v1, %v1, 15
144 ; CHECK-NEXT: vsrlb %v0, %v0, %v1
145 ; CHECK-NEXT: vsrl %v0, %v0, %v1
146 ; CHECK-NEXT: vst %v0, 0(%r2), 3
147 ; CHECK-NEXT: br %r14
148 %and = and i32 %sh, 127
149 %ext = zext i32 %and to i128
150 %shift = lshr i128 %a, %ext
154 define i128 @f13(i128 %a, i32 %sh) {
157 ; CHECK-NEXT: vlvgp %v1, %r4, %r4
158 ; CHECK-NEXT: vl %v0, 0(%r3), 3
159 ; CHECK-NEXT: vrepb %v1, %v1, 15
160 ; CHECK-NEXT: vsrab %v0, %v0, %v1
161 ; CHECK-NEXT: vsra %v0, %v0, %v1
162 ; CHECK-NEXT: vst %v0, 0(%r2), 3
163 ; CHECK-NEXT: br %r14
164 %and = and i32 %sh, 127
165 %ext = zext i32 %and to i128
166 %shift = ashr i128 %a, %ext