[llvm-commits] [llvm] r60182 - in /llvm/trunk: lib/Transforms/Scalar/InstructionCombining.cpp test/Transforms/InstCombine/2008-11-27-IDivVector.ll test/Transforms/InstCombine/2008-11-27-MultiplyIntVec.ll
Nick Lewycky
nicholas at mxc.ca
Thu Nov 27 12:21:10 PST 2008
Author: nicholas
Date: Thu Nov 27 14:21:08 2008
New Revision: 60182
URL: http://llvm.org/viewvc/llvm-project?rev=60182&view=rev
Log:
Add a couple of missed optimizations on integer vectors. Multiply and divide
by 1, as well as multiply by -1.
Added:
llvm/trunk/test/Transforms/InstCombine/2008-11-27-IDivVector.ll
llvm/trunk/test/Transforms/InstCombine/2008-11-27-MultiplyIntVec.ll
Modified:
llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=60182&r1=60181&r2=60182&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Thu Nov 27 14:21:08 2008
@@ -2576,12 +2576,21 @@
} 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 @@
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;
}
Added: llvm/trunk/test/Transforms/InstCombine/2008-11-27-IDivVector.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/2008-11-27-IDivVector.ll?rev=60182&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/2008-11-27-IDivVector.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/2008-11-27-IDivVector.ll Thu Nov 27 14:21:08 2008
@@ -0,0 +1,11 @@
+; RUN: llvm-as < %s | opt -instcombine | llvm-dis | not grep div
+
+define <2 x i8> @f(<2 x i8> %x) {
+ %A = udiv <2 x i8> %x, <i8 1, i8 1>
+ ret <2 x i8> %A
+}
+
+define <2 x i8> @g(<2 x i8> %x) {
+ %A = sdiv <2 x i8> %x, <i8 1, i8 1>
+ ret <2 x i8> %A
+}
Added: llvm/trunk/test/Transforms/InstCombine/2008-11-27-MultiplyIntVec.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/2008-11-27-MultiplyIntVec.ll?rev=60182&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/2008-11-27-MultiplyIntVec.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/2008-11-27-MultiplyIntVec.ll Thu Nov 27 14:21:08 2008
@@ -0,0 +1,11 @@
+; RUN: llvm-as < %s | opt -instcombine | llvm-dis | not grep mul
+
+define <2 x i8> @f(<2 x i8> %x) {
+ %A = mul <2 x i8> %x, <i8 1, i8 1>
+ ret <2 x i8> %A
+}
+
+define <2 x i8> @g(<2 x i8> %x) {
+ %A = mul <2 x i8> %x, <i8 -1, i8 -1>
+ ret <2 x i8> %A
+}
More information about the llvm-commits
mailing list