summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Vectorize
diff options
context:
space:
mode:
authorAlexey Bataev <a.bataev@hotmail.com>2018-01-19 14:40:13 +0000
committerAlexey Bataev <a.bataev@hotmail.com>2018-01-19 14:40:13 +0000
commitfa80c47c6a6741ad8536ef81034d901c70e934f5 (patch)
tree8c15691136c6ffa29e45928a74554b473b6483ed /llvm/lib/Transforms/Vectorize
parent545a20d90b8e5b89ad97e8da274bc05bf17920eb (diff)
downloadbcm5719-llvm-fa80c47c6a6741ad8536ef81034d901c70e934f5.tar.gz
bcm5719-llvm-fa80c47c6a6741ad8536ef81034d901c70e934f5.zip
[SLP] Fix vectorization for tree with trunc to minimum required bit width.
Summary: If the vectorized tree has truncate to minimum required bit width and the vector type of the cast operation after the truncation is the same as the vector type of the cast operands, count cost of the vector cast operation as 0, because this cast will be later removed. Also, if the vectorization tree root operations are integer cast operations, do not consider them as candidates for truncation. It will just create extra number of the same vector/scalar operations, which will be removed by instcombiner. Reviewers: RKSimon, spatel, mkuper, hfinkel, mssimpso Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D41948 llvm-svn: 322946
Diffstat (limited to 'llvm/lib/Transforms/Vectorize')
-rw-r--r--llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp22
1 files changed, 20 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 90f84e00b44..f748ba4b31b 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -2065,7 +2065,10 @@ int BoUpSLP::getEntryCost(TreeEntry *E) {
VL0->getType(), SrcTy, VL0);
VectorType *SrcVecTy = VectorType::get(SrcTy, VL.size());
- int VecCost = TTI->getCastInstrCost(VL0->getOpcode(), VecTy, SrcVecTy, VL0);
+ int VecCost = 0;
+ // Check if the values are candidates to demote.
+ if (!MinBWs.count(VL0) || VecTy != SrcVecTy)
+ VecCost = TTI->getCastInstrCost(VL0->getOpcode(), VecTy, SrcVecTy, VL0);
return VecCost - ScalarCost;
}
case Instruction::FCmp:
@@ -4014,9 +4017,24 @@ void BoUpSLP::computeMinimumValueSizes() {
// additional roots that require investigating in Roots.
SmallVector<Value *, 32> ToDemote;
SmallVector<Value *, 4> Roots;
- for (auto *Root : TreeRoot)
+ for (auto *Root : TreeRoot) {
+ // Do not include top zext/sext/trunc operations to those to be demoted, it
+ // produces noise cast<vect>, trunc <vect>, exctract <vect>, cast <extract>
+ // sequence.
+ if (isa<Constant>(Root))
+ continue;
+ auto *I = dyn_cast<Instruction>(Root);
+ if (!I || !I->hasOneUse() || !Expr.count(I))
+ return;
+ if (isa<ZExtInst>(I) || isa<SExtInst>(I))
+ continue;
+ if (auto *TI = dyn_cast<TruncInst>(I)) {
+ Roots.push_back(TI->getOperand(0));
+ continue;
+ }
if (!collectValuesToDemote(Root, Expr, ToDemote, Roots))
return;
+ }
// The maximum bit width required to represent all the values that can be
// demoted without loss of precision. It would be safe to truncate the roots
OpenPOWER on IntegriCloud