diff options
author | Chris Lattner <sabre@nondot.org> | 2002-09-10 23:04:09 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2002-09-10 23:04:09 +0000 |
commit | f283608f2ea7fd52fdd5d283a1f199b95efb931d (patch) | |
tree | 5ca98ee67d132173e5f737b14d11e694b9c167eb /lib | |
parent | dabb94adc15566aaf11b4befa18be55dbecfa9b0 (diff) | |
download | external_llvm-f283608f2ea7fd52fdd5d283a1f199b95efb931d.zip external_llvm-f283608f2ea7fd52fdd5d283a1f199b95efb931d.tar.gz external_llvm-f283608f2ea7fd52fdd5d283a1f199b95efb931d.tar.bz2 |
Add cannonicalization of shl X, 1 -> add X, X
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3671 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 785eb70..9c1076e 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -490,10 +490,18 @@ Instruction *InstCombiner::visitShiftInst(Instruction &I) { // a signed value. // if (ConstantUInt *CUI = dyn_cast<ConstantUInt>(Op1)) { - unsigned TypeBits = Op0->getType()->getPrimitiveSize()*8; - if (CUI->getValue() >= TypeBits && - !(Op0->getType()->isSigned() && I.getOpcode() == Instruction::Shr)) - return ReplaceInstUsesWith(I, Constant::getNullValue(Op0->getType())); + if (I.getOpcode() == Instruction::Shr) { + unsigned TypeBits = Op0->getType()->getPrimitiveSize()*8; + 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; } |