diff options
| author | Chris Lattner <sabre@nondot.org> | 2006-03-04 06:04:02 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2006-03-04 06:04:02 +0000 |
| commit | 32c01df299047e16d4d24140f58e78ef559128cf (patch) | |
| tree | 31dcf669cd57d685f219ab65c30fa1f97955bfba /llvm/lib/Transforms | |
| parent | ba66f8e1ad950402b552ff7564b28ee1ba50d650 (diff) | |
| download | bcm5719-llvm-32c01df299047e16d4d24140f58e78ef559128cf.tar.gz bcm5719-llvm-32c01df299047e16d4d24140f58e78ef559128cf.zip | |
Canonicalize (X+C1)*C2 -> X*C2+C1*C2
This implements Transforms/InstCombine/add.ll:test31
llvm-svn: 26519
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 6d006b1815d..c409e91ef00 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -1622,6 +1622,19 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) { if (Op1F->getValue() == 1.0) return ReplaceInstUsesWith(I, Op0); // Eliminate 'mul double %X, 1.0' } + + if (BinaryOperator *Op0I = dyn_cast<BinaryOperator>(Op0)) + if (Op0I->getOpcode() == Instruction::Add && Op0I->hasOneUse() && + isa<ConstantInt>(Op0I->getOperand(1))) { + // Canonicalize (X+C1)*C2 -> X*C2+C1*C2. + Instruction *Add = BinaryOperator::createMul(Op0I->getOperand(0), + Op1, "tmp"); + InsertNewInstBefore(Add, I); + Value *C1C2 = ConstantExpr::getMul(Op1, + cast<Constant>(Op0I->getOperand(1))); + return BinaryOperator::createAdd(Add, C1C2); + + } // Try to fold constant mul into select arguments. if (SelectInst *SI = dyn_cast<SelectInst>(Op0)) |

