[llvm] r279399 - [InstCombine] use m_APInt to allow icmp (shl X, Y), C folds for splat constant vectors, part 3
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 21 09:35:34 PDT 2016
Author: spatel
Date: Sun Aug 21 11:35:34 2016
New Revision: 279399
URL: http://llvm.org/viewvc/llvm-project?rev=279399&view=rev
Log:
[InstCombine] use m_APInt to allow icmp (shl X, Y), C folds for splat constant vectors, part 3
This is a partial enablement (move the ConstantInt guard down).
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/trunk/test/Transforms/InstCombine/shift.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=279399&r1=279398&r2=279399&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Sun Aug 21 11:35:34 2016
@@ -2030,15 +2030,10 @@ Instruction *InstCombiner::foldICmpShlCo
if (cast<BinaryOperator>(Shl)->hasNoSignedWrap() && isSignTest(Pred, *C))
return new ICmpInst(Pred, X, Constant::getNullValue(X->getType()));
- // FIXME: This check restricts all folds under here to scalar types.
- ConstantInt *RHS = dyn_cast<ConstantInt>(Cmp.getOperand(1));
- if (!RHS)
- return nullptr;
-
// Otherwise, if this is a comparison of the sign bit, simplify to and/test.
bool TrueIfSigned = false;
if (Shl->hasOneUse() && isSignBitCheck(Pred, *C, TrueIfSigned)) {
- // (X << 31) <s 0 --> (X&1) != 0
+ // (X << 31) <s 0 --> (X & 1) != 0
Constant *Mask = ConstantInt::get(
X->getType(),
APInt::getOneBitSet(TypeBits, TypeBits - ShiftAmt->getZExtValue() - 1));
@@ -2047,6 +2042,11 @@ Instruction *InstCombiner::foldICmpShlCo
And, Constant::getNullValue(And->getType()));
}
+ // FIXME: This check restricts all folds under here to scalar types.
+ ConstantInt *RHS = dyn_cast<ConstantInt>(Cmp.getOperand(1));
+ if (!RHS)
+ return nullptr;
+
// Transform (icmp pred iM (shl iM %v, N), CI)
// -> (icmp pred i(M-N) (trunc %v iM to i(M-N)), (trunc (CI>>N))
// Transform the shl to a trunc if (trunc (CI>>N)) has no loss and M-N.
Modified: llvm/trunk/test/Transforms/InstCombine/shift.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/shift.ll?rev=279399&r1=279398&r2=279399&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/shift.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/shift.ll Sun Aug 21 11:35:34 2016
@@ -608,8 +608,8 @@ define i1 @test33(i32 %X) {
; FIXME: Vectors should fold the same way.
define <2 x i1> @test33vec(<2 x i32> %X) {
; CHECK-LABEL: @test33vec(
-; CHECK-NEXT: [[TMP1:%.*]] = shl <2 x i32> %X, <i32 7, i32 7>
-; CHECK-NEXT: [[TMP2:%.*]] = icmp slt <2 x i32> [[TMP1]], zeroinitializer
+; CHECK-NEXT: [[TMP1_MASK:%.*]] = and <2 x i32> %X, <i32 16777216, i32 16777216>
+; CHECK-NEXT: [[TMP2:%.*]] = icmp ne <2 x i32> [[TMP1_MASK]], zeroinitializer
; CHECK-NEXT: ret <2 x i1> [[TMP2]]
;
%tmp1 = shl <2 x i32> %X, <i32 7, i32 7>
More information about the llvm-commits
mailing list