Skip to content
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

[RFC][LV] VPlan-based cost model #67647

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions llvm/lib/Transforms/Vectorize/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ add_llvm_component_library(LLVMVectorize
Vectorize.cpp
VectorCombine.cpp
VPlan.cpp
VPlanCostModel.cpp
VPlanHCFGBuilder.cpp
VPlanRecipes.cpp
VPlanSLP.cpp
Expand Down
37 changes: 37 additions & 0 deletions llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ class LoopVectorizationPlanner {

SmallVector<VPlanPtr, 4> VPlans;

/// Candidate VectorizationFactors for VPlans.
DenseMap<VPlan *, SmallVector<VectorizationFactor>> VFCandidates;

/// A builder used to construct the current plan.
VPBuilder Builder;

Expand Down Expand Up @@ -336,6 +339,21 @@ class LoopVectorizationPlanner {
/// Check if the number of runtime checks exceeds the threshold.
bool requiresTooManyRuntimeChecks() const;

/// \return The most profitable vectorization factor and the cost of that VF.
/// This method checks every VF in every plan in VPlans.
VectorizationFactor selectVectorizationFactor();

/// \return The most profitable vectorization factor and the cost of that VF
/// for vectorizing the epilogue. Returns VectorizationFactor::Disabled if
/// epilogue vectorization is not supported for the loop.
VectorizationFactor
selectEpilogueVectorizationFactor(const ElementCount MaxVF);

/// Convenience function that returns the value of vscale_range iff
/// vscale_range.min == vscale_range.max or otherwise returns the value
/// returned by the corresponding TLI method.
std::optional<unsigned> getVScaleForTuning() const;

protected:
/// Build VPlans for power-of-2 VF's between \p MinVF and \p MaxVF inclusive,
/// according to the information gathered by Legal when it checked if it is
Expand Down Expand Up @@ -370,6 +388,25 @@ class LoopVectorizationPlanner {
void adjustRecipesForReductions(VPBasicBlock *LatchVPBB, VPlanPtr &Plan,
VPRecipeBuilder &RecipeBuilder,
ElementCount MinVF);

/// Returns true when Factor A is more profitable than Factor B.
bool isMoreProfitable(const VectorizationFactor &A,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd have guessed this is part of the cost model, not the planner.

const VectorizationFactor &B) const;

/// Determines if we have the infrastructure to vectorize loop \p L and its
/// epilogue, assuming the main loop is vectorized by \p VF.
bool isCandidateForEpilogueVectorization(const ElementCount VF) const;

/// Returns true if epilogue vectorization is considered profitable, and
/// false otherwise.
/// \p VF is the vectorization factor chosen for the original loop.
bool isEpilogueVectorizationProfitable(const ElementCount VF) const;

ArrayRef<VectorizationFactor> getVFCandidatesFor(VPlan &Plan) const {
auto I = VFCandidates.find(&Plan);
assert(I != VFCandidates.end());
return I->second;
}
};

} // namespace llvm
Expand Down
Loading
Loading