[llvm-commits] CVS: llvm/lib/Transforms/Scalar/Reassociate.cpp
Chris Lattner
lattner at cs.uiuc.edu
Mon Mar 13 22:55:30 PST 2006
Changes in directory llvm/lib/Transforms/Scalar:
Reassociate.cpp updated: 1.57 -> 1.58
---
Log message:
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
---
Diffs of the changes: (+17 -13)
Reassociate.cpp | 30 +++++++++++++++++-------------
1 files changed, 17 insertions(+), 13 deletions(-)
Index: llvm/lib/Transforms/Scalar/Reassociate.cpp
diff -u llvm/lib/Transforms/Scalar/Reassociate.cpp:1.57 llvm/lib/Transforms/Scalar/Reassociate.cpp:1.58
--- llvm/lib/Transforms/Scalar/Reassociate.cpp:1.57 Sat Mar 4 03:31:13 2006
+++ llvm/lib/Transforms/Scalar/Reassociate.cpp Tue Mar 14 00:55:18 2006
@@ -410,19 +410,23 @@
/// 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
More information about the llvm-commits
mailing list