diff options
author | Haicheng Wu <haicheng@codeaurora.org> | 2018-04-16 18:09:49 +0000 |
---|---|---|
committer | Haicheng Wu <haicheng@codeaurora.org> | 2018-04-16 18:09:49 +0000 |
commit | f7466f316429a4bdd1672f5bb61eae5c4ce8beb3 (patch) | |
tree | 4ee78ce51f22f8099939acfb61951297bc4ab0f8 /llvm/lib/Transforms | |
parent | 67feadb2c757d7ff7cbaacdbcdecdf7d077a7c6d (diff) | |
download | bcm5719-llvm-f7466f316429a4bdd1672f5bb61eae5c4ce8beb3.tar.gz bcm5719-llvm-f7466f316429a4bdd1672f5bb61eae5c4ce8beb3.zip |
[SLP] Use getExtractWithExtendCost() to compute the scalar cost of extractelement/ext pair
We use getExtractWithExtendCost to calculate the cost of extractelement and
s|zext together when computing the extract cost after vectorization, but we
calculate the cost of extractelement and s|zext separately when computing the
scalar cost which is larger than it should be.
Differential Revision: https://reviews.llvm.org/D45469
llvm-svn: 330143
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 321fb1db04f..e3637ccf5d7 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -2192,10 +2192,26 @@ int BoUpSLP::getEntryCost(TreeEntry *E) { // If all users are going to be vectorized, instruction can be // considered as dead. // The same, if have only one user, it will be vectorized for sure. - if (areAllUsersVectorized(E)) + if (areAllUsersVectorized(E)) { // Take credit for instruction that will become dead. + if (E->hasOneUse()) { + Instruction *Ext = E->user_back(); + if ((isa<SExtInst>(Ext) || isa<ZExtInst>(Ext)) && + all_of(Ext->users(), + [](User *U) { return isa<GetElementPtrInst>(U); })) { + // Use getExtractWithExtendCost() to calculate the cost of + // extractelement/ext pair. + DeadCost -= TTI->getExtractWithExtendCost( + Ext->getOpcode(), Ext->getType(), VecTy, i); + // Add back the cost of s|zext which is subtracted seperately. + DeadCost += TTI->getCastInstrCost( + Ext->getOpcode(), Ext->getType(), E->getType(), Ext); + continue; + } + } DeadCost -= TTI->getVectorInstrCost(Instruction::ExtractElement, VecTy, i); + } } return DeadCost; } |