Skip to content

Commit 7bcbbe6

Browse files
committed
!fixu update on top of main
1 parent 3b47e50 commit 7bcbbe6

12 files changed

+239
-235
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -571,15 +571,11 @@ class LoopVectorizationPlanner {
571571
/// Update loop metadata and profile info for both the scalar remainder loop
572572
/// and \p VectorLoop, if it exists. Keeps all loop hints from the original
573573
/// loop on the vector loop and replaces vectorizer-specific metadata
574-
void updateLoopMetadata(Loop *VectorLoop, Loop *OrigLoop, ScalarEvolution &SE,
575-
OptimizationRemarkEmitter *ORE,
576-
VPBasicBlock *HeaderVPBB, VPlan &Plan,
577-
const TargetTransformInfo &TTI,
578-
bool VectorizingEpilogue, MDNode *LID,
579-
std::optional<unsigned> OrigAverageTripCount,
580-
unsigned OrigLoopInvocationWeight,
581-
ElementCount BestVF,
582-
unsigned EstimatedVFxUF , bool DisableRuntimeUnroll);
574+
void updateLoopMetadata(Loop *VectorLoop, VPBasicBlock *HeaderVPBB,
575+
VPlan &Plan, bool VectorizingEpilogue, MDNode *LID,
576+
std::optional<unsigned> OrigAverageTripCount,
577+
unsigned OrigLoopInvocationWeight,
578+
unsigned EstimatedVFxUF, bool DisableRuntimeUnroll);
583579

584580
protected:
585581
/// Build VPlans for power-of-2 VF's between \p MinVF and \p MaxVF inclusive,

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7283,9 +7283,11 @@ DenseMap<const SCEV *, Value *> LoopVectorizationPlanner::executePlan(
72837283
updateLoopMetadata(
72847284
HeaderVPBB ? LI->getLoopFor(State.CFG.VPBB2IRBB.lookup(HeaderVPBB))
72857285
: nullptr,
7286-
OrigLoop, *PSE.getSE(), ORE, HeaderVPBB, BestVPlan, TTI,
7287-
VectorizingEpilogue, LID, OrigAverageTripCount,
7288-
OrigLoopInvocationWeight, BestVF, estimateElementCount(BestVF * BestUF, CM.getVScaleForTuning()), DisableRuntimeUnroll);
7286+
HeaderVPBB, BestVPlan, VectorizingEpilogue, LID, OrigAverageTripCount,
7287+
OrigLoopInvocationWeight,
7288+
estimateElementCount(BestVF * BestUF, CM.getVScaleForTuning()),
7289+
DisableRuntimeUnroll);
7290+
72897291
// 3. Fix the vectorized code: take care of header phi's, live-outs,
72907292
// predication, updating analyses.
72917293
ILV.fixVectorizedLoop(State);

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,19 +1677,16 @@ static void addRuntimeUnrollDisableMetaData(Loop *L) {
16771677
}
16781678
}
16791679

1680-
void LoopVectorizationPlanner::updateLoopMetadata(Loop *VectorLoop, Loop *OrigLoop, ScalarEvolution &SE,
1681-
OptimizationRemarkEmitter *ORE,
1682-
VPBasicBlock *HeaderVPBB, VPlan &Plan,
1683-
const TargetTransformInfo &TTI,
1684-
bool VectorizingEpilogue, MDNode *LID,
1685-
std::optional<unsigned> OrigAverageTripCount,
1686-
unsigned OrigLoopInvocationWeight,
1687-
ElementCount BestVF,
1688-
unsigned EstimatedVFxUF, bool DisableRuntimeUnroll) {
1689-
MDNode *LID = OrigLoop->getLoopID();
1680+
void LoopVectorizationPlanner::updateLoopMetadata(
1681+
Loop *VectorLoop, VPBasicBlock *HeaderVPBB, VPlan &Plan,
1682+
bool VectorizingEpilogue, MDNode *LID,
1683+
std::optional<unsigned> OrigAverageTripCount,
1684+
unsigned OrigLoopInvocationWeight, unsigned EstimatedVFxUF,
1685+
bool DisableRuntimeUnroll) {
16901686
// Update the metadata of the scalar loop. Skip the update when vectorizing
1691-
// the epilogue loop, to ensure it is only updated once.
1692-
if (!VectorizingEpilogue) {
1687+
// the epilogue loop, to ensure it is only updated once, or when the became
1688+
// unreachable.
1689+
if (Plan.getScalarPreheader()->hasPredecessors() && !VectorizingEpilogue) {
16931690
std::optional<MDNode *> RemainderLoopID = makeFollowupLoopID(
16941691
LID, {LLVMLoopVectorizeFollowupAll, LLVMLoopVectorizeFollowupEpilogue});
16951692
if (RemainderLoopID) {
@@ -1759,10 +1756,23 @@ void LoopVectorizationPlanner::updateLoopMetadata(Loop *VectorLoop, Loop *OrigLo
17591756
// For scalable vectorization we can't know at compile time how many
17601757
// iterations of the loop are handled in one vector iteration, so instead
17611758
// use the value of vscale used for tuning.
1762-
setProfileInfoAfterUnrolling(OrigLoop, VectorLoop, OrigLoop, EstimatedVFxUF);
1759+
if (OrigAverageTripCount) {
1760+
// Calculate number of iterations in unrolled loop.
1761+
unsigned AverageVectorTripCount = *OrigAverageTripCount / EstimatedVFxUF;
1762+
// Calculate number of iterations for remainder loop.
1763+
unsigned RemainderAverageTripCount = *OrigAverageTripCount % EstimatedVFxUF;
1764+
1765+
if (HeaderVPBB) {
1766+
setLoopEstimatedTripCount(VectorLoop, AverageVectorTripCount,
1767+
OrigLoopInvocationWeight);
1768+
}
1769+
if (Plan.getScalarPreheader()->hasPredecessors()) {
1770+
setLoopEstimatedTripCount(OrigLoop, RemainderAverageTripCount,
1771+
OrigLoopInvocationWeight);
1772+
}
1773+
}
17631774
}
17641775

1765-
>>>>>>> main
17661776
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
17671777
void LoopVectorizationPlanner::printPlans(raw_ostream &O) {
17681778
if (VPlans.empty()) {

0 commit comments

Comments
 (0)