@@ -165,15 +165,6 @@ using namespace SCEVPatternMatch;
165165const char VerboseDebug[] = DEBUG_TYPE " -verbose" ;
166166#endif
167167
168- // / @{
169- // / Metadata attribute names
170- const char LLVMLoopVectorizeFollowupAll[] = " llvm.loop.vectorize.followup_all" ;
171- const char LLVMLoopVectorizeFollowupVectorized[] =
172- " llvm.loop.vectorize.followup_vectorized" ;
173- const char LLVMLoopVectorizeFollowupEpilogue[] =
174- " llvm.loop.vectorize.followup_epilogue" ;
175- // / @}
176-
177168STATISTIC (LoopsVectorized, " Number of loops vectorized" );
178169STATISTIC (LoopsAnalyzed, " Number of loops analyzed for vectorization" );
179170STATISTIC (LoopsEpilogueVectorized, " Number of epilogues vectorized" );
@@ -2569,24 +2560,6 @@ void InnerLoopVectorizer::fixVectorizedLoop(VPTransformState &State) {
25692560
25702561 // Remove redundant induction instructions.
25712562 cse (HeaderBB);
2572-
2573- // Set/update profile weights for the vector and remainder loops as original
2574- // loop iterations are now distributed among them. Note that original loop
2575- // becomes the scalar remainder loop after vectorization.
2576- //
2577- // For cases like foldTailByMasking() and requiresScalarEpiloque() we may
2578- // end up getting slightly roughened result but that should be OK since
2579- // profile is not inherently precise anyway. Note also possible bypass of
2580- // vector code caused by legality checks is ignored, assigning all the weight
2581- // to the vector loop, optimistically.
2582- //
2583- // For scalable vectorization we can't know at compile time how many
2584- // iterations of the loop are handled in one vector iteration, so instead
2585- // use the value of vscale used for tuning.
2586- Loop *VectorLoop = LI->getLoopFor (HeaderBB);
2587- unsigned EstimatedVFxUF =
2588- estimateElementCount (VF * UF, Cost->getVScaleForTuning ());
2589- setProfileInfoAfterUnrolling (OrigLoop, VectorLoop, OrigLoop, EstimatedVFxUF);
25902563}
25912564
25922565void InnerLoopVectorizer::fixNonInductionPHIs (VPTransformState &State) {
@@ -7098,40 +7071,6 @@ VectorizationFactor LoopVectorizationPlanner::computeBestVF() {
70987071 return BestFactor;
70997072}
71007073
7101- static void addRuntimeUnrollDisableMetaData (Loop *L) {
7102- SmallVector<Metadata *, 4 > MDs;
7103- // Reserve first location for self reference to the LoopID metadata node.
7104- MDs.push_back (nullptr );
7105- bool IsUnrollMetadata = false ;
7106- MDNode *LoopID = L->getLoopID ();
7107- if (LoopID) {
7108- // First find existing loop unrolling disable metadata.
7109- for (unsigned I = 1 , IE = LoopID->getNumOperands (); I < IE; ++I) {
7110- auto *MD = dyn_cast<MDNode>(LoopID->getOperand (I));
7111- if (MD) {
7112- const auto *S = dyn_cast<MDString>(MD->getOperand (0 ));
7113- IsUnrollMetadata =
7114- S && S->getString ().starts_with (" llvm.loop.unroll.disable" );
7115- }
7116- MDs.push_back (LoopID->getOperand (I));
7117- }
7118- }
7119-
7120- if (!IsUnrollMetadata) {
7121- // Add runtime unroll disable metadata.
7122- LLVMContext &Context = L->getHeader ()->getContext ();
7123- SmallVector<Metadata *, 1 > DisableOperands;
7124- DisableOperands.push_back (
7125- MDString::get (Context, " llvm.loop.unroll.runtime.disable" ));
7126- MDNode *DisableNode = MDNode::get (Context, DisableOperands);
7127- MDs.push_back (DisableNode);
7128- MDNode *NewLoopID = MDNode::get (Context, MDs);
7129- // Set operand 0 to refer to the loop id itself.
7130- NewLoopID->replaceOperandWith (0 , NewLoopID);
7131- L->setLoopID (NewLoopID);
7132- }
7133- }
7134-
71357074static Value *getStartValueFromReductionResult (VPInstruction *RdxResult) {
71367075 using namespace VPlanPatternMatch ;
71377076 assert (RdxResult->getOpcode () == VPInstruction::ComputeFindIVResult &&
@@ -7316,50 +7255,16 @@ DenseMap<const SCEV *, Value *> LoopVectorizationPlanner::executePlan(
73167255 // Keep all loop hints from the original loop on the vector loop (we'll
73177256 // replace the vectorizer-specific hints below).
73187257 VPBasicBlock *HeaderVPBB = vputils::getFirstLoopHeader (BestVPlan, State.VPDT );
7319- if (HeaderVPBB) {
7320- MDNode *OrigLoopID = OrigLoop->getLoopID ();
7321-
7322- std::optional<MDNode *> VectorizedLoopID =
7323- makeFollowupLoopID (OrigLoopID, {LLVMLoopVectorizeFollowupAll,
7324- LLVMLoopVectorizeFollowupVectorized});
7325-
7326- Loop *L = LI->getLoopFor (State.CFG .VPBB2IRBB [HeaderVPBB]);
7327- if (VectorizedLoopID) {
7328- L->setLoopID (*VectorizedLoopID);
7329- } else {
7330- // Keep all loop hints from the original loop on the vector loop (we'll
7331- // replace the vectorizer-specific hints below).
7332- if (MDNode *LID = OrigLoop->getLoopID ())
7333- L->setLoopID (LID);
7334-
7335- LoopVectorizeHints Hints (L, true , *ORE);
7336- Hints.setAlreadyVectorized ();
7337-
7338- // Check if it's EVL-vectorized and mark the corresponding metadata.
7339- bool IsEVLVectorized =
7340- llvm::any_of (*HeaderVPBB, [](const VPRecipeBase &Recipe) {
7341- // Looking for the ExplictVectorLength VPInstruction.
7342- if (const auto *VI = dyn_cast<VPInstruction>(&Recipe))
7343- return VI->getOpcode () == VPInstruction::ExplicitVectorLength;
7344- return false ;
7345- });
7346- if (IsEVLVectorized) {
7347- LLVMContext &Context = L->getHeader ()->getContext ();
7348- MDNode *LoopID = L->getLoopID ();
7349- auto *IsEVLVectorizedMD = MDNode::get (
7350- Context,
7351- {MDString::get (Context, " llvm.loop.isvectorized.tailfoldingstyle" ),
7352- MDString::get (Context, " evl" )});
7353- MDNode *NewLoopID = makePostTransformationMetadata (Context, LoopID, {},
7354- {IsEVLVectorizedMD});
7355- L->setLoopID (NewLoopID);
7356- }
7357- }
7358- TargetTransformInfo::UnrollingPreferences UP;
7359- TTI.getUnrollingPreferences (L, *PSE.getSE (), UP, ORE);
7360- if (!UP.UnrollVectorizedLoop || VectorizingEpilogue)
7361- addRuntimeUnrollDisableMetaData (L);
7362- }
7258+ // Add metadata to disable runtime unrolling a scalar loop when there
7259+ // are no runtime checks about strides and memory. A scalar loop that is
7260+ // rarely used is not worth unrolling.
7261+ bool DisableRuntimeUnroll = !ILV.RTChecks .hasChecks () && !BestVF.isScalar ();
7262+ updateLoopMetadataAndProfileInfo (
7263+ HeaderVPBB ? LI->getLoopFor (State.CFG .VPBB2IRBB .lookup (HeaderVPBB))
7264+ : nullptr ,
7265+ HeaderVPBB, VectorizingEpilogue,
7266+ estimateElementCount (BestVF * BestUF, CM.getVScaleForTuning ()),
7267+ DisableRuntimeUnroll);
73637268
73647269 // 3. Fix the vectorized code: take care of header phi's, live-outs,
73657270 // predication, updating analyses.
@@ -9377,8 +9282,6 @@ static bool processLoopInVPlanNativePath(
93779282
93789283 reportVectorization (ORE, L, VF, 1 );
93799284
9380- // Mark the loop as already vectorized to avoid vectorizing again.
9381- Hints.setAlreadyVectorized ();
93829285 assert (!verifyFunction (*L->getHeader ()->getParent (), &dbgs ()));
93839286 return true ;
93849287}
@@ -10191,9 +10094,6 @@ bool LoopVectorizePass::processLoop(Loop *L) {
1019110094 LLVM_DEBUG (dbgs () << " LV: Interleave Count is " << IC << ' \n ' );
1019210095 }
1019310096
10194- bool DisableRuntimeUnroll = false ;
10195- MDNode *OrigLoopID = L->getLoopID ();
10196-
1019710097 // Report the vectorization decision.
1019810098 if (VF.Width .isScalar ()) {
1019910099 using namespace ore ;
@@ -10249,9 +10149,6 @@ bool LoopVectorizePass::processLoop(Loop *L) {
1024910149 BestEpiPlan, LVL, ExpandedSCEVs,
1025010150 EPI.VectorTripCount );
1025110151 ++LoopsEpilogueVectorized;
10252-
10253- if (!Checks.hasChecks ())
10254- DisableRuntimeUnroll = true ;
1025510152 } else {
1025610153 InnerLoopVectorizer LB (L, PSE, LI, DT, TTI, AC, VF.Width , IC, &CM, BFI, PSI,
1025710154 Checks, BestPlan);
@@ -10265,31 +10162,12 @@ bool LoopVectorizePass::processLoop(Loop *L) {
1026510162
1026610163 LVP.executePlan (VF.Width , IC, BestPlan, LB, DT, false );
1026710164 ++LoopsVectorized;
10268-
10269- // Add metadata to disable runtime unrolling a scalar loop when there
10270- // are no runtime checks about strides and memory. A scalar loop that is
10271- // rarely used is not worth unrolling.
10272- if (!Checks.hasChecks () && !VF.Width .isScalar ())
10273- DisableRuntimeUnroll = true ;
1027410165 }
1027510166
1027610167 assert (DT->verify (DominatorTree::VerificationLevel::Fast) &&
1027710168 " DT not preserved correctly" );
10169+ assert (!verifyFunction (*F, &dbgs ()));
1027810170
10279- std::optional<MDNode *> RemainderLoopID =
10280- makeFollowupLoopID (OrigLoopID, {LLVMLoopVectorizeFollowupAll,
10281- LLVMLoopVectorizeFollowupEpilogue});
10282- if (RemainderLoopID) {
10283- L->setLoopID (*RemainderLoopID);
10284- } else {
10285- if (DisableRuntimeUnroll)
10286- addRuntimeUnrollDisableMetaData (L);
10287-
10288- // Mark the loop as already vectorized to avoid vectorizing again.
10289- Hints.setAlreadyVectorized ();
10290- }
10291-
10292- assert (!verifyFunction (*L->getHeader ()->getParent (), &dbgs ()));
1029310171 return true ;
1029410172}
1029510173
0 commit comments