aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms/Scalar/InstructionCombining.cpp
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2008-11-27 20:21:08 +0000
committerNick Lewycky <nicholas@mxc.ca>2008-11-27 20:21:08 +0000
commit94418734beeaabe23124854367b2fcb6e415c33d (patch)
treed47c5b46a98115bb044c024808c25db2bb79e1ef /lib/Transforms/Scalar/InstructionCombining.cpp
parent3793c0ed2ecb8c74e28ed881e0586fe85e194bd9 (diff)
downloadexternal_llvm-94418734beeaabe23124854367b2fcb6e415c33d.zip
external_llvm-94418734beeaabe23124854367b2fcb6e415c33d.tar.gz
external_llvm-94418734beeaabe23124854367b2fcb6e415c33d.tar.bz2
Add a couple of missed optimizations on integer vectors. Multiply and divide
by 1, as well as multiply by -1. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60182 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/InstructionCombining.cpp')
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp28
1 files changed, 22 insertions, 6 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 5631bd0..661b047 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -2576,12 +2576,21 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) {
} else if (isa<VectorType>(Op1->getType())) {
if (isa<ConstantAggregateZero>(Op1))
return ReplaceInstUsesWith(I, Op1);
-
- // As above, vector X*splat(1.0) -> X in all defined cases.
- if (ConstantVector *Op1V = dyn_cast<ConstantVector>(Op1))
- if (ConstantFP *F = dyn_cast_or_null<ConstantFP>(Op1V->getSplatValue()))
- if (F->isExactlyValue(1.0))
- return ReplaceInstUsesWith(I, Op0);
+
+ if (ConstantVector *Op1V = dyn_cast<ConstantVector>(Op1)) {
+ if (Op1V->isAllOnesValue()) // X * -1 == 0 - X
+ return BinaryOperator::CreateNeg(Op0, I.getName());
+
+ // As above, vector X*splat(1.0) -> X in all defined cases.
+ if (Constant *Splat = Op1V->getSplatValue()) {
+ if (ConstantFP *F = dyn_cast<ConstantFP>(Splat))
+ if (F->isExactlyValue(1.0))
+ return ReplaceInstUsesWith(I, Op0);
+ if (ConstantInt *CI = dyn_cast<ConstantInt>(Splat))
+ if (CI->equalsInt(1))
+ return ReplaceInstUsesWith(I, Op0);
+ }
+ }
}
if (BinaryOperator *Op0I = dyn_cast<BinaryOperator>(Op0))
@@ -2856,6 +2865,13 @@ Instruction *InstCombiner::commonIDivTransforms(BinaryOperator &I) {
if (I.getType() == Type::Int1Ty)
return ReplaceInstUsesWith(I, Op0);
+ if (ConstantVector *Op1V = dyn_cast<ConstantVector>(Op1)) {
+ if (ConstantInt *X = cast_or_null<ConstantInt>(Op1V->getSplatValue()))
+ // div X, 1 == X
+ if (X->isOne())
+ return ReplaceInstUsesWith(I, Op0);
+ }
+
return 0;
}