diff options
author | Amjad Aboud <amjad.aboud@intel.com> | 2017-08-15 19:33:14 +0000 |
---|---|---|
committer | Amjad Aboud <amjad.aboud@intel.com> | 2017-08-15 19:33:14 +0000 |
commit | 0464c5d958065c571a605f5da3cfd4b729950be7 (patch) | |
tree | 2fb6cb0a5efa6ca1d9820012d6c9519e421f853b | |
parent | ab0400d5afae783d080883f4fc91f574f97ce917 (diff) | |
download | bcm5719-llvm-0464c5d958065c571a605f5da3cfd4b729950be7.tar.gz bcm5719-llvm-0464c5d958065c571a605f5da3cfd4b729950be7.zip |
[InstCombine] Added support for (X >>s C) << C --> X & (-1 << C)
Differential Revision: https://reviews.llvm.org/D36743
llvm-svn: 310949
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp | 4 | ||||
-rw-r--r-- | llvm/test/Transforms/InstCombine/shift.ll | 16 |
2 files changed, 18 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp index a19cdf7ef6d..45541c9adc0 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp @@ -559,8 +559,8 @@ Instruction *InstCombiner::visitShl(BinaryOperator &I) { return new ZExtInst(Builder.CreateShl(X, ShAmt), Ty); } - // (X >>u C) << C --> X & (-1 << C) - if (match(Op0, m_LShr(m_Value(X), m_Specific(Op1)))) { + // (X >> C) << C --> X & (-1 << C) + if (match(Op0, m_Shr(m_Value(X), m_Specific(Op1)))) { APInt Mask(APInt::getHighBitsSet(BitWidth, BitWidth - ShAmt)); return BinaryOperator::CreateAnd(X, ConstantInt::get(Ty, Mask)); } diff --git a/llvm/test/Transforms/InstCombine/shift.ll b/llvm/test/Transforms/InstCombine/shift.ll index 68bbf35d1e6..cbb3d614db2 100644 --- a/llvm/test/Transforms/InstCombine/shift.ll +++ b/llvm/test/Transforms/InstCombine/shift.ll @@ -221,6 +221,22 @@ define i32 @test12(i32 %A) { ret i32 %C } +;; ((A >>s 6) << 6 === (A & FFFFFFC0) +define i8 @shishi(i8 %x) { +; CHECK-LABEL: @shishi( +; CHECK-NEXT: [[A:%.*]] = ashr i8 [[X:%.*]], 6 +; CHECK-NEXT: [[B:%.*]] = and i8 [[X]], -64 +; CHECK-NEXT: [[EXTRA_USE_OF_A:%.*]] = mul nsw i8 [[A]], 5 +; CHECK-NEXT: [[R:%.*]] = sdiv i8 [[EXTRA_USE_OF_A]], [[B]] +; CHECK-NEXT: ret i8 [[R]] +; + %a = ashr i8 %x, 6 + %b = shl i8 %a, 6 + %extra_use_of_a = mul i8 %a, 5 + %r = sdiv i8 %extra_use_of_a, %b + ret i8 %r +} + ;; This transformation is deferred to DAGCombine: ;; (A >> 3) << 4 === (A & -8) * 2 ;; The shl may be valuable to scalar evolution. |