[PATCH] D148806: [SLP]Fix the cost for the extractelements, used in several nodes.
Alexey Bataev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 21 09:07:16 PDT 2023
This revision was automatically updated to reflect the committed changes.
Closed by commit rG851a12138a76: [SLP]Fix the cost for the extractelements, used in several nodes. (authored by ABataev).
Changed prior to commit:
https://reviews.llvm.org/D148806?vs=515461&id=515760#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D148806/new/
https://reviews.llvm.org/D148806
Files:
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
llvm/test/Transforms/SLPVectorizer/X86/reused-extractelements.ll
Index: llvm/test/Transforms/SLPVectorizer/X86/reused-extractelements.ll
===================================================================
--- llvm/test/Transforms/SLPVectorizer/X86/reused-extractelements.ll
+++ llvm/test/Transforms/SLPVectorizer/X86/reused-extractelements.ll
@@ -8,7 +8,7 @@
; YAML-NEXT: Function: g
; YAML-NEXT: Args:
; YAML-NEXT: - String: 'SLP vectorized with cost '
-; YAML-NEXT: - Cost: '-2'
+; YAML-NEXT: - Cost: '-1'
; YAML-NEXT: - String: ' and with tree size '
; YAML-NEXT: - TreeSize: '4'
Index: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -2433,7 +2433,8 @@
/// \returns the cost of the vectorizable entry.
InstructionCost getEntryCost(const TreeEntry *E,
- ArrayRef<Value *> VectorizedVals);
+ ArrayRef<Value *> VectorizedVals,
+ SmallPtrSetImpl<Value *> &CheckedExtracts);
/// This is the recursive part of buildTree.
void buildTree_rec(ArrayRef<Value *> Roots, unsigned Depth,
@@ -6731,6 +6732,7 @@
InstructionCost Cost = 0;
ArrayRef<Value *> VectorizedVals;
BoUpSLP &R;
+ SmallPtrSetImpl<Value *> &CheckedExtracts;
constexpr static TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput;
InstructionCost getBuildVectorCost(ArrayRef<Value *> VL, Value *Root) {
@@ -6923,8 +6925,10 @@
public:
ShuffleCostEstimator(TargetTransformInfo &TTI,
- ArrayRef<Value *> VectorizedVals, BoUpSLP &R)
- : TTI(TTI), VectorizedVals(VectorizedVals), R(R) {}
+ ArrayRef<Value *> VectorizedVals, BoUpSLP &R,
+ SmallPtrSetImpl<Value *> &CheckedExtracts)
+ : TTI(TTI), VectorizedVals(VectorizedVals), R(R),
+ CheckedExtracts(CheckedExtracts) {}
Value *adjustExtracts(const TreeEntry *E, ArrayRef<int> Mask,
TTI::ShuffleKind ShuffleKind) {
if (Mask.empty())
@@ -6939,7 +6943,6 @@
return nullptr;
}
DenseMap<Value *, int> ExtractVectorsTys;
- SmallPtrSet<Value *, 4> CheckedExtracts;
for (auto [I, V] : enumerate(VL)) {
// Ignore non-extractelement scalars.
if (isa<UndefValue>(V) || (!Mask.empty() && Mask[I] == UndefMaskElem))
@@ -7070,8 +7073,9 @@
}
};
-InstructionCost BoUpSLP::getEntryCost(const TreeEntry *E,
- ArrayRef<Value *> VectorizedVals) {
+InstructionCost
+BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
+ SmallPtrSetImpl<Value *> &CheckedExtracts) {
ArrayRef<Value *> VL = E->Scalars;
Type *ScalarTy = VL[0]->getType();
@@ -7098,7 +7102,8 @@
return 0;
if (isa<InsertElementInst>(VL[0]))
return InstructionCost::getInvalid();
- ShuffleCostEstimator Estimator(*TTI, VectorizedVals, *this);
+ ShuffleCostEstimator Estimator(*TTI, VectorizedVals, *this,
+ CheckedExtracts);
unsigned VF = E->getVectorFactor();
SmallVector<int> ReuseShuffleIndicies(E->ReuseShuffleIndices.begin(),
E->ReuseShuffleIndices.end());
@@ -8224,6 +8229,7 @@
unsigned BundleWidth = VectorizableTree[0]->Scalars.size();
+ SmallPtrSet<Value *, 4> CheckedExtracts;
for (unsigned I = 0, E = VectorizableTree.size(); I < E; ++I) {
TreeEntry &TE = *VectorizableTree[I];
if (TE.State == TreeEntry::NeedToGather) {
@@ -8239,7 +8245,7 @@
}
}
- InstructionCost C = getEntryCost(&TE, VectorizedVals);
+ InstructionCost C = getEntryCost(&TE, VectorizedVals, CheckedExtracts);
Cost += C;
LLVM_DEBUG(dbgs() << "SLP: Adding cost " << C
<< " for bundle that starts with " << *TE.Scalars[0]
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148806.515760.patch
Type: text/x-patch
Size: 3992 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230421/c938dd34/attachment.bin>
More information about the llvm-commits
mailing list