From 348f665ee2d08f433b8cf92bc3f01597288600e2 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 6 Dec 2007 01:59:46 +0000 Subject: [PATCH] move some ashr-specific code out of commonShiftTransforms into visitAShr. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44650 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../Scalar/InstructionCombining.cpp | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 52c66a5d87c..b1317502836 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -5872,7 +5872,22 @@ Instruction *InstCombiner::visitLShr(BinaryOperator &I) { } Instruction *InstCombiner::visitAShr(BinaryOperator &I) { - return commonShiftTransforms(I); + if (Instruction *R = commonShiftTransforms(I)) + return R; + + Value *Op0 = I.getOperand(0); + + // ashr int -1, X = -1 (for any arithmetic shift rights of ~0) + if (ConstantInt *CSI = dyn_cast(Op0)) + if (CSI->isAllOnesValue()) + return ReplaceInstUsesWith(I, CSI); + + // See if we can turn a signed shr into an unsigned shr. + if (MaskedValueIsZero(Op0, + APInt::getSignBit(I.getType()->getPrimitiveSizeInBits()))) + return BinaryOperator::createLShr(Op0, I.getOperand(1)); + + return 0; } Instruction *InstCombiner::commonShiftTransforms(BinaryOperator &I) { @@ -5898,26 +5913,12 @@ Instruction *InstCombiner::commonShiftTransforms(BinaryOperator &I) { return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType())); } - // ashr int -1, X = -1 (for any arithmetic shift rights of ~0) - if (I.getOpcode() == Instruction::AShr) - if (ConstantInt *CSI = dyn_cast(Op0)) - if (CSI->isAllOnesValue()) - return ReplaceInstUsesWith(I, CSI); - // Try to fold constant and into select arguments. if (isa(Op0)) if (SelectInst *SI = dyn_cast(Op1)) if (Instruction *R = FoldOpIntoSelect(I, SI, this)) return R; - // See if we can turn a signed shr into an unsigned shr. - if (I.isArithmeticShift()) { - if (MaskedValueIsZero(Op0, - APInt::getSignBit(I.getType()->getPrimitiveSizeInBits()))) { - return BinaryOperator::createLShr(Op0, Op1, I.getName()); - } - } - if (ConstantInt *CUI = dyn_cast(Op1)) if (Instruction *Res = FoldShiftByConstant(Op0, CUI, I)) return Res;