@@ -182,3 +182,58 @@ define <3 x i36> @fshl_v3i36_constant_nonsplat_undef0(<3 x i36> %x, <3 x i36> %y
182
182
%r = or <3 x i36 > %shl , %shr
183
183
ret <3 x i36 > %r
184
184
}
185
+
186
+ ; Fold or(shl(x,a),lshr(y,bw-a)) -> fshl(x,y,a) iff a < bw
187
+
188
+ define i64 @fshl_sub_mask (i64 %x , i64 %y , i64 %a ) {
189
+ ; CHECK-LABEL: @fshl_sub_mask(
190
+ ; CHECK-NEXT: [[MASK:%.*]] = and i64 [[A:%.*]], 63
191
+ ; CHECK-NEXT: [[SHL:%.*]] = shl i64 [[X:%.*]], [[MASK]]
192
+ ; CHECK-NEXT: [[SUB:%.*]] = sub nuw nsw i64 64, [[MASK]]
193
+ ; CHECK-NEXT: [[SHR:%.*]] = lshr i64 [[Y:%.*]], [[SUB]]
194
+ ; CHECK-NEXT: [[R:%.*]] = or i64 [[SHL]], [[SHR]]
195
+ ; CHECK-NEXT: ret i64 [[R]]
196
+ ;
197
+ %mask = and i64 %a , 63
198
+ %shl = shl i64 %x , %mask
199
+ %sub = sub nuw nsw i64 64 , %mask
200
+ %shr = lshr i64 %y , %sub
201
+ %r = or i64 %shl , %shr
202
+ ret i64 %r
203
+ }
204
+
205
+ ; Fold or(lshr(v,a),shl(v,bw-a)) -> fshr(y,x,a) iff a < bw
206
+
207
+ define i64 @fshr_sub_mask (i64 %x , i64 %y , i64 %a ) {
208
+ ; CHECK-LABEL: @fshr_sub_mask(
209
+ ; CHECK-NEXT: [[MASK:%.*]] = and i64 [[A:%.*]], 63
210
+ ; CHECK-NEXT: [[SHR:%.*]] = lshr i64 [[X:%.*]], [[MASK]]
211
+ ; CHECK-NEXT: [[SUB:%.*]] = sub nuw nsw i64 64, [[MASK]]
212
+ ; CHECK-NEXT: [[SHL:%.*]] = shl i64 [[Y:%.*]], [[SUB]]
213
+ ; CHECK-NEXT: [[R:%.*]] = or i64 [[SHL]], [[SHR]]
214
+ ; CHECK-NEXT: ret i64 [[R]]
215
+ ;
216
+ %mask = and i64 %a , 63
217
+ %shr = lshr i64 %x , %mask
218
+ %sub = sub nuw nsw i64 64 , %mask
219
+ %shl = shl i64 %y , %sub
220
+ %r = or i64 %shl , %shr
221
+ ret i64 %r
222
+ }
223
+
224
+ define <2 x i64 > @fshr_sub_mask_vector (<2 x i64 > %x , <2 x i64 > %y , <2 x i64 > %a ) {
225
+ ; CHECK-LABEL: @fshr_sub_mask_vector(
226
+ ; CHECK-NEXT: [[MASK:%.*]] = and <2 x i64> [[A:%.*]], <i64 63, i64 63>
227
+ ; CHECK-NEXT: [[SHR:%.*]] = lshr <2 x i64> [[X:%.*]], [[MASK]]
228
+ ; CHECK-NEXT: [[SUB:%.*]] = sub nuw nsw <2 x i64> <i64 64, i64 64>, [[MASK]]
229
+ ; CHECK-NEXT: [[SHL:%.*]] = shl <2 x i64> [[Y:%.*]], [[SUB]]
230
+ ; CHECK-NEXT: [[R:%.*]] = or <2 x i64> [[SHL]], [[SHR]]
231
+ ; CHECK-NEXT: ret <2 x i64> [[R]]
232
+ ;
233
+ %mask = and <2 x i64 > %a , <i64 63 , i64 63 >
234
+ %shr = lshr <2 x i64 > %x , %mask
235
+ %sub = sub nuw nsw <2 x i64 > <i64 64 , i64 64 >, %mask
236
+ %shl = shl <2 x i64 > %y , %sub
237
+ %r = or <2 x i64 > %shl , %shr
238
+ ret <2 x i64 > %r
239
+ }
0 commit comments