diff options
author | Chris Lattner <sabre@nondot.org> | 2006-03-14 06:55:18 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2006-03-14 06:55:18 +0000 |
commit | 22a66c41f3ab42c15437033851395b0b8288681b (patch) | |
tree | 5dbdb71ae80b1f4b1d9f7338fb46692b358a40d8 /lib/Transforms | |
parent | 000c7c4c7b9481fb596fb2a2db9d163b800a8a09 (diff) | |
download | external_llvm-22a66c41f3ab42c15437033851395b0b8288681b.zip external_llvm-22a66c41f3ab42c15437033851395b0b8288681b.tar.gz external_llvm-22a66c41f3ab42c15437033851395b0b8288681b.tar.bz2 |
Promote shifts by a constant to multiplies so that we can reassociate
(x<<1)+(y<<1) -> (X+Y)<<1. This implements
Transforms/Reassociate/shift-factor.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26753 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/Scalar/Reassociate.cpp | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/lib/Transforms/Scalar/Reassociate.cpp b/lib/Transforms/Scalar/Reassociate.cpp index 61c5c49..4a484c3 100644 --- a/lib/Transforms/Scalar/Reassociate.cpp +++ b/lib/Transforms/Scalar/Reassociate.cpp @@ -410,19 +410,23 @@ static Instruction *BreakUpSubtract(Instruction *Sub) { /// by one, change this into a multiply by a constant to assist with further /// reassociation. static Instruction *ConvertShiftToMul(Instruction *Shl) { - if (!isReassociableOp(Shl->getOperand(0), Instruction::Mul) && - !(Shl->hasOneUse() && isReassociableOp(Shl->use_back(),Instruction::Mul))) - return 0; - - Constant *MulCst = ConstantInt::get(Shl->getType(), 1); - MulCst = ConstantExpr::getShl(MulCst, cast<Constant>(Shl->getOperand(1))); - - std::string Name = Shl->getName(); Shl->setName(""); - Instruction *Mul = BinaryOperator::createMul(Shl->getOperand(0), MulCst, - Name, Shl); - Shl->replaceAllUsesWith(Mul); - Shl->eraseFromParent(); - return Mul; + // If an operand of this shift is a reassociable multiply, or if the shift + // is used by a reassociable multiply or add, turn into a multiply. + if (isReassociableOp(Shl->getOperand(0), Instruction::Mul) || + (Shl->hasOneUse() && + (isReassociableOp(Shl->use_back(), Instruction::Mul) || + isReassociableOp(Shl->use_back(), Instruction::Add)))) { + Constant *MulCst = ConstantInt::get(Shl->getType(), 1); + MulCst = ConstantExpr::getShl(MulCst, cast<Constant>(Shl->getOperand(1))); + + std::string Name = Shl->getName(); Shl->setName(""); + Instruction *Mul = BinaryOperator::createMul(Shl->getOperand(0), MulCst, + Name, Shl); + Shl->replaceAllUsesWith(Mul); + Shl->eraseFromParent(); + return Mul; + } + return 0; } // Scan backwards and forwards among values with the same rank as element i to |