[InstCombine] fold (X >>u C) << C --> X & (-1 << C)

We already have this fold when the lshr has one use, but it doesn't need that
restriction. We may be able to remove some code from foldShiftedShift().

Also, move the similar:
(X << C) >>u C --> X & (-1 >>u C)
...directly into visitLShr to help clean up foldShiftByConstOfShiftByConst().

That whole function seems questionable since it is called by commonShiftTransforms(),
but there's really not much in common if we're checking the shift opcodes for every
fold.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293215 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Sanjay Patel
2017-01-26 22:08:10 +00:00
parent a28da41a4a
commit 4eb218a6fd
2 changed files with 21 additions and 22 deletions
+4 -4
View File
@@ -459,12 +459,12 @@ define <2 x i44> @shl_lshr_eq_amt_multi_use_splat_vec(<2 x i44> %A) {
ret <2 x i44> %D
}
; FIXME: Fold shl (lshr X, C), C -> and X, C' regardless of the number of uses of the lshr.
; Fold shl (lshr X, C), C -> and X, C' regardless of the number of uses of the lshr.
define i43 @lshr_shl_eq_amt_multi_use(i43 %A) {
; CHECK-LABEL: @lshr_shl_eq_amt_multi_use(
; CHECK-NEXT: [[B:%.*]] = lshr i43 %A, 23
; CHECK-NEXT: [[C:%.*]] = shl nuw i43 [[B]], 23
; CHECK-NEXT: [[C:%.*]] = and i43 %A, -8388608
; CHECK-NEXT: [[D:%.*]] = mul i43 [[B]], [[C]]
; CHECK-NEXT: ret i43 [[D]]
;
@@ -474,12 +474,12 @@ define i43 @lshr_shl_eq_amt_multi_use(i43 %A) {
ret i43 %D
}
; FIXME: Fold vector shl (lshr X, C), C -> and X, C' regardless of the number of uses of the lshr.
; Fold vector shl (lshr X, C), C -> and X, C' regardless of the number of uses of the lshr.
define <2 x i43> @lshr_shl_eq_amt_multi_use_splat_vec(<2 x i43> %A) {
; CHECK-LABEL: @lshr_shl_eq_amt_multi_use_splat_vec(
; CHECK-NEXT: [[B:%.*]] = lshr <2 x i43> %A, <i43 23, i43 23>
; CHECK-NEXT: [[C:%.*]] = shl nuw <2 x i43> [[B]], <i43 23, i43 23>
; CHECK-NEXT: [[C:%.*]] = and <2 x i43> %A, <i43 -8388608, i43 -8388608>
; CHECK-NEXT: [[D:%.*]] = mul <2 x i43> [[B]], [[C]]
; CHECK-NEXT: ret <2 x i43> [[D]]
;