aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/Vectorize/VecUtils.cpp
diff options
context:
space:
mode:
authorNadav Rotem <nrotem@apple.com>2013-04-14 07:22:22 +0000
committerNadav Rotem <nrotem@apple.com>2013-04-14 07:22:22 +0000
commit077462993636e828c7f047fbc980c8e3fa4e87c4 (patch)
treea551158b60343f9ca322ce479af78549ffcbbb78 /lib/Transforms/Vectorize/VecUtils.cpp
parent420820056d42c93ea64cd86a95848bf4e0040670 (diff)
SLP: Document the scalarization cost method.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179479 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Vectorize/VecUtils.cpp')
-rw-r--r--lib/Transforms/Vectorize/VecUtils.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/Transforms/Vectorize/VecUtils.cpp b/lib/Transforms/Vectorize/VecUtils.cpp
index 584f3d9778..c85711532d 100644
--- a/lib/Transforms/Vectorize/VecUtils.cpp
+++ b/lib/Transforms/Vectorize/VecUtils.cpp
@@ -110,6 +110,7 @@ bool BoUpSLP::vectorizeStoreChain(ValueList &Chain, int CostThreshold) {
if (!isPowerOf2_32(Sz) || VF < 2) return false;
bool Changed = false;
+ // Look for profitable vectorizable trees at all offsets, starting at zero.
for (unsigned i = 0, e = Chain.size(); i < e; ++i) {
if (i + VF > e) return Changed;
DEBUG(dbgs()<<"SLP: Analyzing " << VF << " stores at offset "<< i << "\n");
@@ -166,7 +167,10 @@ bool BoUpSLP::vectorizeStores(StoreList &Stores, int costThreshold) {
}
bool Vectorized = vectorizeStoreChain(Operands, costThreshold);
- if (Vectorized) VectorizedStores.insert(Operands.begin(), Operands.end());
+
+ // Mark the vectorized stores so that we don't vectorize them again.
+ if (Vectorized)
+ VectorizedStores.insert(Operands.begin(), Operands.end());
Changed |= Vectorized;
}
@@ -174,12 +178,12 @@ bool BoUpSLP::vectorizeStores(StoreList &Stores, int costThreshold) {
}
int BoUpSLP::getScalarizationCost(ValueList &VL) {
+ // Find the type of the operands in 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());
+ // Find the cost of inserting/extracting values from the vector.
return getScalarizationCost(VecTy);
}
@@ -222,6 +226,9 @@ void BoUpSLP::vectorizeArith(ValueList &Operands) {
Value *Vec = vectorizeTree(Operands, Operands.size());
BasicBlock::iterator Loc = cast<Instruction>(Vec);
IRBuilder<> Builder(++Loc);
+ // After vectorizing the operands we need to generate extractelement
+ // instructions and replace all of the uses of the scalar values with
+ // the values that we extracted from the vectorized tree.
for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
Value *S = Builder.CreateExtractElement(Vec, Builder.getInt32(i));
Operands[i]->replaceAllUsesWith(S);