[llvm-commits] [llvm] r51472 - in /llvm/trunk: lib/Transforms/Scalar/InstructionCombining.cpp test/Transforms/InstCombine/2008-05-22-FoldAddIVec.ll
Nick Lewycky
nicholas at mxc.ca
Thu May 22 21:14:51 PDT 2008
Author: nicholas
Date: Thu May 22 23:14:51 2008
New Revision: 51472
URL: http://llvm.org/viewvc/llvm-project?rev=51472&view=rev
Log:
Implement X + X for vectors.
Added:
llvm/trunk/test/Transforms/InstCombine/2008-05-22-FoldAddIVec.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=51472&r1=51471&r2=51472&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Thu May 22 23:14:51 2008
@@ -2292,14 +2292,22 @@
namespace {
-// AddRHS - Implements: X + X --> X << 1
+// AddRHS - Implements: X + X --> X << 1 and X + X --> X * 2 for vectors
struct AddRHS {
Value *RHS;
AddRHS(Value *rhs) : RHS(rhs) {}
bool shouldApply(Value *LHS) const { return LHS == RHS; }
Instruction *apply(BinaryOperator &Add) const {
- return BinaryOperator::CreateShl(Add.getOperand(0),
- ConstantInt::get(Add.getType(), 1));
+ if (Add.getType()->getTypeID() == Type::VectorTyID) {
+ const VectorType *VTy = cast<VectorType>(Add.getType());
+ ConstantInt *CI = ConstantInt::get(VTy->getElementType(), 2);
+ std::vector<Constant*> Elts(VTy->getNumElements(), CI);
+ return BinaryOperator::CreateMul(Add.getOperand(0),
+ ConstantVector::get(Elts));
+ } else {
+ return BinaryOperator::CreateShl(Add.getOperand(0),
+ ConstantInt::get(Add.getType(), 1));
+ }
}
};
@@ -2627,8 +2635,8 @@
}
}
- // X + X --> X << 1
- if (I.getType()->isInteger() && I.getType() != Type::Int1Ty) {
+ // X + X --> X << 1 and X + X --> X * 2 for vectors
+ if (I.getType()->isIntOrIntVector() && I.getType() != Type::Int1Ty) {
if (Instruction *Result = AssociativeOpt(I, AddRHS(RHS))) return Result;
if (Instruction *RHSI = dyn_cast<Instruction>(RHS)) {
Added: llvm/trunk/test/Transforms/InstCombine/2008-05-22-FoldAddIVec.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/2008-05-22-FoldAddIVec.ll?rev=51472&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/2008-05-22-FoldAddIVec.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/2008-05-22-FoldAddIVec.ll Thu May 22 23:14:51 2008
@@ -0,0 +1,6 @@
+; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep mul
+
+define <3 x i8> @f(<3 x i8> %i) {
+ %A = add <3 x i8> %i, %i
+ ret <3 x i8> %A
+}
More information about the llvm-commits
mailing list