From 8ca30ab0c5daf44bc6e86c257ecb5da01345fc28 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Sun, 27 Nov 2016 21:07:28 +0000 Subject: [PATCH] [InstSimplify] allow integer vector types to use computeKnownBits Note that the non-splat lshr+lshr test folded, but that does not work in general. Something is missing or wrong in computeKnownBits as the non-splat shl+shl test still shows. llvm-svn: 288005 --- llvm/lib/Analysis/InstructionSimplify.cpp | 4 ++-- llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp | 10 +++++----- llvm/test/Analysis/ValueTracking/knownzero-shift.ll | 18 +++--------------- 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index 398ac52..0969e7a 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -4380,13 +4380,13 @@ Value *llvm::SimplifyInstruction(Instruction *I, const DataLayout &DL, // In general, it is possible for computeKnownBits to determine all bits in a // value even when the operands are not all constants. - if (!Result && I->getType()->isIntegerTy()) { + if (!Result && I->getType()->isIntOrIntVectorTy()) { unsigned BitWidth = I->getType()->getScalarSizeInBits(); APInt KnownZero(BitWidth, 0); APInt KnownOne(BitWidth, 0); computeKnownBits(I, KnownZero, KnownOne, DL, /*Depth*/0, AC, I, DT); if ((KnownZero | KnownOne).isAllOnesValue()) - Result = ConstantInt::get(I->getContext(), KnownOne); + Result = ConstantInt::get(I->getType(), KnownOne); } /// If called on unreachable code, the above logic may report that the diff --git a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp index 5181d23..95f06f2 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp @@ -580,13 +580,13 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, Constant *Op1, // Check for (X << c1) << c2 and (X >> c1) >> c2 if (I.getOpcode() == ShiftOp->getOpcode()) { - uint32_t AmtSum = ShiftAmt1+ShiftAmt2; // Fold into one big shift. - // If this is oversized composite shift, then unsigned shifts get 0, ashr - // saturates. + uint32_t AmtSum = ShiftAmt1 + ShiftAmt2; // Fold into one big shift. + // If this is an oversized composite shift, then unsigned shifts become + // zero (handled in InstSimplify) and ashr saturates. if (AmtSum >= TypeBits) { if (I.getOpcode() != Instruction::AShr) - return replaceInstUsesWith(I, Constant::getNullValue(I.getType())); - AmtSum = TypeBits-1; // Saturate to 31 for i32 ashr. + return nullptr; + AmtSum = TypeBits - 1; // Saturate to 31 for i32 ashr. } return BinaryOperator::Create(I.getOpcode(), X, diff --git a/llvm/test/Analysis/ValueTracking/knownzero-shift.ll b/llvm/test/Analysis/ValueTracking/knownzero-shift.ll index cf5c0a0..4ceb822 100644 --- a/llvm/test/Analysis/ValueTracking/knownzero-shift.ll +++ b/llvm/test/Analysis/ValueTracking/knownzero-shift.ll @@ -24,13 +24,9 @@ define i32 @shl_shl(i32 %A) { ret i32 %C } -; FIXME - define <2 x i33> @shl_shl_splat_vec(<2 x i33> %A) { ; CHECK-LABEL: @shl_shl_splat_vec( -; CHECK-NEXT: [[B:%.*]] = shl <2 x i33> %A, -; CHECK-NEXT: [[C:%.*]] = shl <2 x i33> [[B]], -; CHECK-NEXT: ret <2 x i33> [[C]] +; CHECK-NEXT: ret <2 x i33> zeroinitializer ; %B = shl <2 x i33> %A, %C = shl <2 x i33> %B, @@ -59,26 +55,18 @@ define i232 @lshr_lshr(i232 %A) { ret i232 %C } -; FIXME - define <2 x i32> @lshr_lshr_splat_vec(<2 x i32> %A) { ; CHECK-LABEL: @lshr_lshr_splat_vec( -; CHECK-NEXT: [[B:%.*]] = lshr <2 x i32> %A, -; CHECK-NEXT: [[C:%.*]] = lshr <2 x i32> [[B]], -; CHECK-NEXT: ret <2 x i32> [[C]] +; CHECK-NEXT: ret <2 x i32> zeroinitializer ; %B = lshr <2 x i32> %A, %C = lshr <2 x i32> %B, ret <2 x i32> %C } -; FIXME - define <2 x i32> @lshr_lshr_vec(<2 x i32> %A) { ; CHECK-LABEL: @lshr_lshr_vec( -; CHECK-NEXT: [[B:%.*]] = lshr <2 x i32> %A, -; CHECK-NEXT: [[C:%.*]] = lshr <2 x i32> [[B]], -; CHECK-NEXT: ret <2 x i32> [[C]] +; CHECK-NEXT: ret <2 x i32> zeroinitializer ; %B = lshr <2 x i32> %A, %C = lshr <2 x i32> %B, -- 2.7.4