1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-20 19:42:54 +02:00

Add cannonicalization of shl X, 1 -> add X, X

llvm-svn: 3671
This commit is contained in:
Chris Lattner 2002-09-10 23:04:09 +00:00
parent 9b5ccd195a
commit 5143d4a3b3

View File

@ -490,11 +490,19 @@ Instruction *InstCombiner::visitShiftInst(Instruction &I) {
// a signed value.
//
if (ConstantUInt *CUI = dyn_cast<ConstantUInt>(Op1)) {
if (I.getOpcode() == Instruction::Shr) {
unsigned TypeBits = Op0->getType()->getPrimitiveSize()*8;
if (CUI->getValue() >= TypeBits &&
!(Op0->getType()->isSigned() && I.getOpcode() == Instruction::Shr))
if (CUI->getValue() >= TypeBits && !(Op0->getType()->isSigned()))
return ReplaceInstUsesWith(I, Constant::getNullValue(Op0->getType()));
}
// Check to see if we are shifting left by 1. If so, turn it into an add
// instruction.
if (I.getOpcode() == Instruction::Shl && CUI->equalsInt(1))
// Convert 'shl int %X, 2' to 'add int %X, %X'
return BinaryOperator::create(Instruction::Add, Op0, Op0, I.getName());
}
return 0;
}