-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[VPlan] Add getSCEVExprForVPValue util, use to get trip count SCEV (NFC) #94464
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
Changes from 5 commits
fcd4148
c777a3a
d7d389e
4d0f112
9bc1413
dbe22b4
8449f8f
ca98f41
3f72966
cc75e4a
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 | ||
---|---|---|---|---|
|
@@ -67,6 +67,7 @@ class VPTypeAnalysis { | |||
// Collect a VPlan's ephemeral recipes (those used only by an assume). | ||||
void collectEphemeralRecipesForVPlan(VPlan &Plan, | ||||
DenseSet<VPRecipeBase *> &EphRecipes); | ||||
|
||||
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.
Suggested change
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. Removed, thanks! |
||||
} // end namespace llvm | ||||
|
||||
#endif // LLVM_TRANSFORMS_VECTORIZE_VPLANANALYSIS_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -689,10 +689,9 @@ void VPlanTransforms::optimizeForVFAndUF(VPlan &Plan, ElementCount BestVF, | |
m_BranchOnCond(m_Not(m_ActiveLaneMask(m_VPValue(), m_VPValue()))))) | ||
return; | ||
|
||
Type *IdxTy = | ||
Plan.getCanonicalIV()->getStartValue()->getLiveInIRValue()->getType(); | ||
const SCEV *TripCount = createTripCountSCEV(IdxTy, PSE); | ||
ScalarEvolution &SE = *PSE.getSE(); | ||
const SCEV *TripCount = | ||
vputils::getSCEVExprForVPValue(Plan.getTripCount(), SE); | ||
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. BTW, independently - BOC below would better use an unconditional branch than BranchOnCond with 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. Yes, will also entail to remove the region and header phis. 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. Worth asserting that the SCEV returned could be computed? 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. Thanks, added assert. |
||
ElementCount NumElements = BestVF.multiplyCoefficientBy(BestUF); | ||
const SCEV *C = SE.getElementCount(TripCount->getType(), NumElements); | ||
if (TripCount->isZero() || | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
|
||
#include "VPlanUtils.h" | ||
#include "VPlanPatternMatch.h" | ||
#include "llvm/ADT/TypeSwitch.h" | ||
#include "llvm/Analysis/ScalarEvolutionExpressions.h" | ||
|
||
using namespace llvm; | ||
|
@@ -60,3 +61,14 @@ bool vputils::isHeaderMask(const VPValue *V, VPlan &Plan) { | |
return match(V, m_Binary<Instruction::ICmp>(m_VPValue(A), m_VPValue(B))) && | ||
IsWideCanonicalIV(A) && B == Plan.getOrCreateBackedgeTakenCount(); | ||
} | ||
|
||
const SCEV *vputils::getSCEVExprForVPValue(VPValue *V, ScalarEvolution &SE) { | ||
if (V->isLiveIn()) | ||
return SE.getSCEV(V->getLiveInIRValue()); | ||
|
||
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. This seems to work well for Values at VPlan's boundary: can complement live-ins with live-out/VPIRInstructions which could also simply retrieve SE.getSCEV() of the instruction they wrap; as follow-up, along with concrete use. 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. Yep |
||
// TODO: Support constructing SCEVs for more recipes as needed. | ||
return TypeSwitch<const VPRecipeBase *, const SCEV *>(V->getDefiningRecipe()) | ||
.Case<VPExpandSCEVRecipe>( | ||
[](const VPExpandSCEVRecipe *R) { return R->getSCEV(); }) | ||
.Default([&SE](const VPRecipeBase *) { return SE.getCouldNotCompute(); }); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,11 @@ | |
|
||
#include "VPlan.h" | ||
|
||
namespace llvm { | ||
class ScalarEvolution; | ||
class SCEV; | ||
} // namespace llvm | ||
|
||
namespace llvm::vputils { | ||
/// Returns true if only the first lane of \p Def is used. | ||
bool onlyFirstLaneUsed(const VPValue *Def); | ||
|
@@ -45,6 +50,11 @@ inline bool isUniformAfterVectorization(const VPValue *VPV) { | |
|
||
/// Return true if \p V is a header mask in \p Plan. | ||
bool isHeaderMask(const VPValue *V, VPlan &Plan); | ||
|
||
/// Return the SCEV expression for \p V. Returns SCEVCouldNotCompute if no | ||
/// SCEV expression could be constructed. | ||
const SCEV *getSCEVExprForVPValue(VPValue *V, ScalarEvolution &SE); | ||
|
||
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. This complements 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. Moved, thanks! |
||
} // end namespace llvm::vputils | ||
|
||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly here or as follow-up:
The call to createTripCountSCEV() in LVP::selectEpilogueVectorizationFactor() has available VPlans from which to retrieve a TripCount VPValue and call the new API instead of continuing to call createTripCountSCEV().
The other two calls to createTripCountSCEV() are inside calls to VPlan::createInitialVPlan(), setting its first parameter; should they be inlined into createInitialVPlan() itself instead?
Thereby retiring createTripCountSCEV altogether, leaving only vputils::getSCEVExprForVPValue(Plan.getTripCount(), SE) as the way to obtain the SCEV of a loop's trip count.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, updated the PR to also inline
createTripCountSCEV
.