aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms/Vectorize
diff options
context:
space:
mode:
authorNadav Rotem <nrotem@apple.com>2013-04-14 05:15:53 +0000
committerNadav Rotem <nrotem@apple.com>2013-04-14 05:15:53 +0000
commitab105ae95fc473c19d9f0b019fc7c7a16d17b1a5 (patch)
tree27247e73ffdef91c52268c935d65afd7c066c1c0 /lib/Transforms/Vectorize
parent618eda7a60bafff7741a988e27b98bf81d27cb89 (diff)
downloadexternal_llvm-ab105ae95fc473c19d9f0b019fc7c7a16d17b1a5.zip
external_llvm-ab105ae95fc473c19d9f0b019fc7c7a16d17b1a5.tar.gz
external_llvm-ab105ae95fc473c19d9f0b019fc7c7a16d17b1a5.tar.bz2
SLPVectorizer: Add support for trees that don't start at binary operators, and add the cost of extracting values from the roots of the tree.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179475 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Vectorize')
-rw-r--r--lib/Transforms/Vectorize/SLPVectorizer.cpp15
-rw-r--r--lib/Transforms/Vectorize/VecUtils.cpp10
-rw-r--r--lib/Transforms/Vectorize/VecUtils.h7
3 files changed, 25 insertions, 7 deletions
diff --git a/lib/Transforms/Vectorize/SLPVectorizer.cpp b/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 2f55a00..d94b2b2 100644
--- a/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -85,14 +85,16 @@ struct SLPVectorizer : public BasicBlockPass {
return true;
}
- bool tryToVectorizePair(BinaryOperator *A, BinaryOperator *B, BoUpSLP &R) {
+ bool tryToVectorizePair(Value *A, Value *B, BoUpSLP &R) {
if (!A || !B) return false;
BoUpSLP::ValueList VL;
VL.push_back(A);
VL.push_back(B);
int Cost = R.getTreeCost(VL);
- DEBUG(dbgs()<<"SLP: Cost of pair:" << Cost << ".\n");
- if (Cost >= -SLPCostThreshold) return false;
+ int ExtrCost = R.getScalarizationCost(VL);
+ DEBUG(dbgs()<<"SLP: Cost of pair:" << Cost <<
+ " Cost of extract:" << ExtrCost << ".\n");
+ if ((Cost+ExtrCost) >= -SLPCostThreshold) return false;
DEBUG(dbgs()<<"SLP: Vectorizing pair.\n");
R.vectorizeArith(VL);
return true;
@@ -100,11 +102,12 @@ struct SLPVectorizer : public BasicBlockPass {
bool tryToVectorizeCandidate(BinaryOperator *V, BoUpSLP &R) {
if (!V) return false;
- BinaryOperator *A = dyn_cast<BinaryOperator>(V->getOperand(0));
- BinaryOperator *B = dyn_cast<BinaryOperator>(V->getOperand(1));
// Try to vectorize V.
- if (tryToVectorizePair(A, B, R)) return true;
+ if (tryToVectorizePair(V->getOperand(0), V->getOperand(1), R))
+ return true;
+ BinaryOperator *A = dyn_cast<BinaryOperator>(V->getOperand(0));
+ BinaryOperator *B = dyn_cast<BinaryOperator>(V->getOperand(1));
// Try to skip B.
if (B && B->hasOneUse()) {
BinaryOperator *B0 = dyn_cast<BinaryOperator>(B->getOperand(0));
diff --git a/lib/Transforms/Vectorize/VecUtils.cpp b/lib/Transforms/Vectorize/VecUtils.cpp
index 4d075c5..584f3d9 100644
--- a/lib/Transforms/Vectorize/VecUtils.cpp
+++ b/lib/Transforms/Vectorize/VecUtils.cpp
@@ -173,6 +173,16 @@ bool BoUpSLP::vectorizeStores(StoreList &Stores, int costThreshold) {
return Changed;
}
+int BoUpSLP::getScalarizationCost(ValueList &VL) {
+ Type *ScalarTy = VL[0]->getType();
+
+ if (StoreInst *SI = dyn_cast<StoreInst>(VL[0]))
+ ScalarTy = SI->getValueOperand()->getType();
+
+ VectorType *VecTy = VectorType::get(ScalarTy, VL.size());
+ return getScalarizationCost(VecTy);
+}
+
int BoUpSLP::getScalarizationCost(Type *Ty) {
int Cost = 0;
for (unsigned i = 0, e = cast<VectorType>(Ty)->getNumElements(); i < e; ++i)
diff --git a/lib/Transforms/Vectorize/VecUtils.h b/lib/Transforms/Vectorize/VecUtils.h
index f865236..edebcb3 100644
--- a/lib/Transforms/Vectorize/VecUtils.h
+++ b/lib/Transforms/Vectorize/VecUtils.h
@@ -61,6 +61,11 @@ struct BoUpSLP {
/// A negative number means that this is profitable.
int getTreeCost(ValueList &VL);
+ /// \returns the scalarization cost for this ValueList. Assuming that this
+ /// subtree gets vectorized, we may need to extract the values from the
+ /// roots. This method calculates the cost of extracting the values.
+ int getScalarizationCost(ValueList &VL);
+
/// \brief Attempts to order and vectorize a sequence of stores. This
/// function does a quadratic scan of the given stores.
/// \returns true if the basic block was modified.
@@ -118,7 +123,7 @@ private:
/// by multiple lanes, or by users outside the tree.
/// NOTICE: The vectorization methods also use this set.
ValueSet MustScalarize;
-
+
// Contains a list of values that are used outside the current tree. This
// set must be reset between runs.
ValueSet MultiUserVals;