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: stmg %r14, %r15, 112(%r15)
126 ; CHECK-NEXT: .cfi_offset %r14, -48
127 ; CHECK-NEXT: .cfi_offset %r15, -40
128 ; CHECK-NEXT: lg %r0, 8(%r3)
129 ; CHECK-NEXT: lg %r1, 0(%r3)
130 ; CHECK-NEXT: risblg %r3, %r4, 25, 159, 0
131 ; CHECK-NEXT: lcr %r14, %r3
132 ; CHECK-NEXT: sllg %r5, %r1, 0(%r4)
133 ; CHECK-NEXT: srlg %r14, %r0, 0(%r14)
134 ; CHECK-NEXT: ogr %r5, %r14
135 ; CHECK-NEXT: sllg %r3, %r0, -64(%r3)
136 ; CHECK-NEXT: tmll %r4, 127
137 ; CHECK-NEXT: locgrle %r3, %r5
138 ; CHECK-NEXT: sllg %r0, %r0, 0(%r4)
139 ; CHECK-NEXT: locgre %r3, %r1
140 ; CHECK-NEXT: locghinle %r0, 0
141 ; CHECK-NEXT: stg %r0, 8(%r2)
142 ; CHECK-NEXT: stg %r3, 0(%r2)
143 ; CHECK-NEXT: lmg %r14, %r15, 112(%r15)
144 ; CHECK-NEXT: br %r14
145 %and = and i32 %sh, 127
146 %ext = zext i32 %and to i128
147 %shift = shl i128 %a, %ext
151 define i128 @f12(i128 %a, i32 %sh) {
154 ; CHECK-NEXT: stmg %r14, %r15, 112(%r15)
155 ; CHECK-NEXT: .cfi_offset %r14, -48
156 ; CHECK-NEXT: .cfi_offset %r15, -40
157 ; CHECK-NEXT: lg %r0, 0(%r3)
158 ; CHECK-NEXT: lg %r1, 8(%r3)
159 ; CHECK-NEXT: risblg %r3, %r4, 25, 159, 0
160 ; CHECK-NEXT: lcr %r14, %r3
161 ; CHECK-NEXT: srlg %r5, %r1, 0(%r4)
162 ; CHECK-NEXT: sllg %r14, %r0, 0(%r14)
163 ; CHECK-NEXT: ogr %r5, %r14
164 ; CHECK-NEXT: srlg %r3, %r0, -64(%r3)
165 ; CHECK-NEXT: tmll %r4, 127
166 ; CHECK-NEXT: locgrle %r3, %r5
167 ; CHECK-NEXT: srlg %r0, %r0, 0(%r4)
168 ; CHECK-NEXT: locgre %r3, %r1
169 ; CHECK-NEXT: locghinle %r0, 0
170 ; CHECK-NEXT: stg %r0, 0(%r2)
171 ; CHECK-NEXT: stg %r3, 8(%r2)
172 ; CHECK-NEXT: lmg %r14, %r15, 112(%r15)
173 ; CHECK-NEXT: br %r14
174 %and = and i32 %sh, 127
175 %ext = zext i32 %and to i128
176 %shift = lshr i128 %a, %ext
180 define i128 @f13(i128 %a, i32 %sh) {
183 ; CHECK-NEXT: stmg %r14, %r15, 112(%r15)
184 ; CHECK-NEXT: .cfi_offset %r14, -48
185 ; CHECK-NEXT: .cfi_offset %r15, -40
186 ; CHECK-NEXT: lg %r0, 0(%r3)
187 ; CHECK-NEXT: lg %r1, 8(%r3)
188 ; CHECK-NEXT: risblg %r3, %r4, 25, 159, 0
189 ; CHECK-NEXT: lcr %r14, %r3
190 ; CHECK-NEXT: srlg %r5, %r1, 0(%r4)
191 ; CHECK-NEXT: sllg %r14, %r0, 0(%r14)
192 ; CHECK-NEXT: ogr %r5, %r14
193 ; CHECK-NEXT: srag %r14, %r0, 0(%r4)
194 ; CHECK-NEXT: srag %r3, %r0, -64(%r3)
195 ; CHECK-NEXT: srag %r0, %r0, 63
196 ; CHECK-NEXT: tmll %r4, 127
197 ; CHECK-NEXT: locgrle %r3, %r5
198 ; CHECK-NEXT: locgre %r3, %r1
199 ; CHECK-NEXT: locgrle %r0, %r14
200 ; CHECK-NEXT: stg %r0, 0(%r2)
201 ; CHECK-NEXT: stg %r3, 8(%r2)
202 ; CHECK-NEXT: lmg %r14, %r15, 112(%r15)
203 ; CHECK-NEXT: br %r14
204 %and = and i32 %sh, 127
205 %ext = zext i32 %and to i128
206 %shift = ashr i128 %a, %ext