[llvm] r310949 - [InstCombine] Added support for (X >>s C) << C --> X & (-1 << C)
Amjad Aboud via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 15 12:33:14 PDT 2017
Author: aaboud
Date: Tue Aug 15 12:33:14 2017
New Revision: 310949
URL: http://llvm.org/viewvc/llvm-project?rev=310949&view=rev
Log:
[InstCombine] Added support for (X >>s C) << C --> X & (-1 << C)
Differential Revision: https://reviews.llvm.org/D36743
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineShifts.cpp
llvm/trunk/test/Transforms/InstCombine/shift.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineShifts.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineShifts.cpp?rev=310949&r1=310948&r2=310949&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineShifts.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineShifts.cpp Tue Aug 15 12:33:14 2017
@@ -559,8 +559,8 @@ Instruction *InstCombiner::visitShl(Bina
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));
}
Modified: llvm/trunk/test/Transforms/InstCombine/shift.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/shift.ll?rev=310949&r1=310948&r2=310949&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/shift.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/shift.ll Tue Aug 15 12:33:14 2017
@@ -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.
More information about the llvm-commits
mailing list