[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
Thu Apr 20 13:32:06 PDT 2023
ABataev updated this revision to Diff 515461.
ABataev added a comment.
Rebase
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,
@@ -6793,6 +6794,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) {
if (Mask.empty())
return nullptr;
@@ -6936,7 +6940,6 @@
if (VecNumParts == VecTy->getNumElements())
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))
@@ -7061,8 +7064,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();
@@ -7089,7 +7093,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());
@@ -8223,6 +8228,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) {
@@ -8238,7 +8244,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.515461.patch
Type: text/x-patch
Size: 4002 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230420/97f21e22/attachment.bin>
More information about the llvm-commits
mailing list