aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-04-29 22:24:47 +0000
committerChris Lattner <sabre@nondot.org>2002-04-29 22:24:47 +0000
commit6c1ce21ee61f5a50c7e49e5733be7e8af3958307 (patch)
tree3e6d5c6b57eac4c1e6420c3d08fdd6f4e5763673
parentefc01f62c6608e7bd5a4337df1c65b20d036eab3 (diff)
Add folding rules for mul X, 0 and mul X, 2
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2417 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 71c8723e42..2ad2356de3 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -2,7 +2,7 @@
//
// InstructionCombining - Combine instructions to form fewer, simple
// instructions. This pass does not modify the CFG, and has a tendancy to
-// make instructions dead, so a subsequent DCE pass is useful.
+// make instructions dead, so a subsequent DIE pass is useful.
//
// This pass combines things like:
// %Y = add int 1, %X
@@ -75,8 +75,7 @@ namespace {
//
static bool SimplifyBinOp(BinaryOperator *I) {
if (isa<Constant>(I->getOperand(0)) && !isa<Constant>(I->getOperand(1)))
- if (!I->swapOperands())
- return true;
+ return !I->swapOperands();
return false;
}
@@ -146,6 +145,17 @@ Instruction *InstCombiner::visitMul(BinaryOperator *I) {
AddUsesToWorkList(I); // Add all modified instrs to worklist
I->replaceAllUsesWith(Op1);
return I;
+
+ } else if (I->getType()->isIntegral() &&
+ cast<ConstantInt>(Op2)->equalsInt(2)) {
+ // Convert 'mul int %X, 2' to 'add int %X, %X'
+ return BinaryOperator::create(Instruction::Add, Op1, Op1, I->getName());
+
+ } else if (Op2->isNullValue()) {
+ // Eliminate 'mul int %X, 0'
+ AddUsesToWorkList(I); // Add all modified instrs to worklist
+ I->replaceAllUsesWith(Op2); // Set this value to zero directly
+ return I;
}
}