From 7e09f13fed6fa16e71f4a24c1531e825ede54d32 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Sun, 21 Aug 2016 16:28:22 +0000 Subject: [PATCH] [InstCombine] use m_APInt to allow icmp (shl X, Y), C folds for splat constant vectors, part 2 This is a partial enablement (move the ConstantInt guard down). llvm-svn: 279398 --- llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 12 ++++++------ llvm/test/Transforms/InstCombine/icmp.ll | 4 +--- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 220d783..73dc141 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -2024,16 +2024,16 @@ Instruction *InstCombiner::foldICmpShlConstant(ICmpInst &Cmp, Instruction *Shl, } } - // FIXME: This check restricts all folds under here to scalar types. - ConstantInt *RHS = dyn_cast(Cmp.getOperand(1)); - if (!RHS) - return nullptr; - // If this is a signed comparison to 0 and the shift is sign preserving, // use the shift LHS operand instead; isSignTest may change 'Pred', so only // do that if we're sure to not continue on in this function. if (cast(Shl)->hasNoSignedWrap() && isSignTest(Pred, *C)) - return new ICmpInst(Pred, X, Constant::getNullValue(RHS->getType())); + return new ICmpInst(Pred, X, Constant::getNullValue(X->getType())); + + // FIXME: This check restricts all folds under here to scalar types. + ConstantInt *RHS = dyn_cast(Cmp.getOperand(1)); + if (!RHS) + return nullptr; // Otherwise, if this is a comparison of the sign bit, simplify to and/test. bool TrueIfSigned = false; diff --git a/llvm/test/Transforms/InstCombine/icmp.ll b/llvm/test/Transforms/InstCombine/icmp.ll index e1b5839..f8f28d6 100644 --- a/llvm/test/Transforms/InstCombine/icmp.ll +++ b/llvm/test/Transforms/InstCombine/icmp.ll @@ -1160,11 +1160,9 @@ define i1 @icmp_shl_nsw_sge1(i32 %x) { ret i1 %cmp } -; FIXME: Vectors should fold the same way. define <2 x i1> @icmp_shl_nsw_sge1_vec(<2 x i32> %x) { ; CHECK-LABEL: @icmp_shl_nsw_sge1_vec( -; CHECK-NEXT: [[SHL:%.*]] = shl nsw <2 x i32> %x, -; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i32> [[SHL]], zeroinitializer +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i32> %x, zeroinitializer ; CHECK-NEXT: ret <2 x i1> [[CMP]] ; %shl = shl nsw <2 x i32> %x, -- 2.7.4