-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[SLP]: Introduce and use getDataFlowCost #112999
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9075,15 +9075,16 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals, | |
auto *FinalVecTy = FixedVectorType::get(ScalarTy, EntryVF); | ||
|
||
bool NeedToShuffleReuses = !E->ReuseShuffleIndices.empty(); | ||
InstructionCost CommonCost = 0; | ||
if (E->State == TreeEntry::NeedToGather) { | ||
if (allConstant(VL)) | ||
return 0; | ||
return CommonCost; | ||
if (isa<InsertElementInst>(VL[0])) | ||
return InstructionCost::getInvalid(); | ||
return processBuildVector<ShuffleCostEstimator, InstructionCost>( | ||
E, ScalarTy, *TTI, VectorizedVals, *this, CheckedExtracts); | ||
return CommonCost + | ||
processBuildVector<ShuffleCostEstimator, InstructionCost>( | ||
E, ScalarTy, *TTI, VectorizedVals, *this, CheckedExtracts); | ||
} | ||
InstructionCost CommonCost = 0; | ||
SmallVector<int> Mask; | ||
bool IsReverseOrder = isReverseOrder(E->ReorderIndices); | ||
if (!E->ReorderIndices.empty() && | ||
|
@@ -9222,6 +9223,18 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals, | |
OpTE->Scalars.size()); | ||
} | ||
|
||
// Calculate the cost difference of propagating a vector vs series of | ||
// scalars across blocks. This may be nonzero in the case of illegal | ||
// vectors. | ||
Comment on lines
+9227
to
+9228
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment talks about illegal vector types but the code affects only legal vector types |
||
Type *ScalarTy = VL0->getType()->getScalarType(); | ||
if (ScalarTy && isValidElementType(ScalarTy)) { | ||
jrbyrnes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ScalarCost += TTI->getDataFlowCost(ScalarTy, | ||
/*IsCallingConv=*/false) * | ||
Comment on lines
+9231
to
+9232
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it account register pressure or something else? |
||
EntryVF; | ||
CommonCost += TTI->getDataFlowCost( | ||
FixedVectorType::get(ScalarTy, EntryVF), /*IsCallingConv=*/false); | ||
jrbyrnes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
return CommonCost - ScalarCost; | ||
} | ||
case Instruction::ExtractValue: | ||
|
@@ -10241,6 +10254,27 @@ InstructionCost BoUpSLP::getTreeCost(ArrayRef<Value *> VectorizedVals) { | |
|
||
InstructionCost C = getEntryCost(&TE, VectorizedVals, CheckedExtracts); | ||
Cost += C; | ||
|
||
// Calculate the cost difference of propagating a vector vs series of scalars | ||
// across blocks. This may be nonzero in the case of illegal vectors. | ||
Instruction *VL0 = TE.getMainOp(); | ||
if (VL0 && ((I + 1) < VectorizableTree.size())) { | ||
Instruction *VL1 = VectorizableTree[I + 1]->getMainOp(); | ||
if (VL1 && (VL0->getParent() != VL1->getParent())) { | ||
Type *ScalarTy = VL0->getType()->getScalarType(); | ||
if (ScalarTy && isValidElementType(ScalarTy)) { | ||
InstructionCost ScalarDFlow = | ||
TTI->getDataFlowCost(ScalarTy, | ||
/*IsCallingConv=*/false) * | ||
TE.getVectorFactor(); | ||
InstructionCost VectorDFlow = TTI->getDataFlowCost( | ||
FixedVectorType::get(ScalarTy, TE.getVectorFactor()), | ||
/*IsCallingConv=*/false); | ||
Cost += (VectorDFlow - ScalarDFlow); | ||
} | ||
} | ||
} | ||
|
||
Comment on lines
+10257
to
+10277
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
LLVM_DEBUG(dbgs() << "SLP: Adding cost " << C << " for bundle " | ||
<< shortBundleName(TE.Scalars) << ".\n" | ||
<< "SLP: Current total cost = " << Cost << "\n"); | ||
|
@@ -10257,8 +10291,9 @@ InstructionCost BoUpSLP::getTreeCost(ArrayRef<Value *> VectorizedVals) { | |
for (ExternalUser &EU : ExternalUses) { | ||
// We only add extract cost once for the same scalar. | ||
if (!isa_and_nonnull<InsertElementInst>(EU.User) && | ||
!ExtractCostCalculated.insert(EU.Scalar).second) | ||
!ExtractCostCalculated.insert(EU.Scalar).second) { | ||
continue; | ||
} | ||
jrbyrnes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Uses by ephemeral values are free (because the ephemeral value will be | ||
// removed prior to code generation, and so the extraction will be | ||
|
@@ -10267,8 +10302,14 @@ InstructionCost BoUpSLP::getTreeCost(ArrayRef<Value *> VectorizedVals) { | |
continue; | ||
|
||
// No extract cost for vector "scalar" | ||
if (isa<FixedVectorType>(EU.Scalar->getType())) | ||
if (isa<FixedVectorType>(EU.Scalar->getType())) { | ||
// Account for any additional costs required by CallingConvention for the | ||
// type. | ||
if (isa_and_nonnull<ReturnInst>(EU.User)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Outgoing call arguments too. But this is just the type legality cost? |
||
Cost += | ||
TTI->getDataFlowCost(EU.Scalar->getType(), /*IsCallingConv=*/true); | ||
continue; | ||
} | ||
|
||
// If found user is an insertelement, do not calculate extract cost but try | ||
// to detect it as a final shuffled/identity match. | ||
|
Uh oh!
There was an error while loading. Please reload this page.