[llvm-commits] [llvm] r44650 - /llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
Chris Lattner
sabre at nondot.org
Wed Dec 5 17:59:47 PST 2007
Author: lattner
Date: Wed Dec 5 19:59:46 2007
New Revision: 44650
URL: http://llvm.org/viewvc/llvm-project?rev=44650&view=rev
Log:
move some ashr-specific code out of commonShiftTransforms into visitAShr.
Modified:
llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=44650&r1=44649&r2=44650&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Wed Dec 5 19:59:46 2007
@@ -5872,7 +5872,22 @@
}
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<ConstantInt>(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 @@
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<ConstantInt>(Op0))
- if (CSI->isAllOnesValue())
- return ReplaceInstUsesWith(I, CSI);
-
// Try to fold constant and into select arguments.
if (isa<Constant>(Op0))
if (SelectInst *SI = dyn_cast<SelectInst>(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<ConstantInt>(Op1))
if (Instruction *Res = FoldShiftByConstant(Op0, CUI, I))
return Res;
More information about the llvm-commits
mailing list