@@ -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)
17671777void LoopVectorizationPlanner::printPlans (raw_ostream &O) {
17681778 if (VPlans.empty ()) {
0 commit comments