[llvm] [LoopRotate] Remove canRotateDeoptimizingLatchExit and multi-rotate (PR #162482)

via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 8 06:42:14 PDT 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp -- llvm/lib/Transforms/Utils/LoopRotationUtils.cpp
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/lib/Transforms/Utils/LoopRotationUtils.cpp b/llvm/lib/Transforms/Utils/LoopRotationUtils.cpp
index f0f7bbb64..0c8d6fa47 100644
--- a/llvm/lib/Transforms/Utils/LoopRotationUtils.cpp
+++ b/llvm/lib/Transforms/Utils/LoopRotationUtils.cpp
@@ -377,21 +377,21 @@ bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
     Metrics.analyzeBasicBlock(OrigHeader, *TTI, EphValues, PrepareForLTO);
     if (Metrics.notDuplicatable) {
       LLVM_DEBUG(
-                  dbgs() << "LoopRotation: NOT rotating - contains non-duplicatable"
-                  << " instructions: ";
-                  L->dump());
+          dbgs() << "LoopRotation: NOT rotating - contains non-duplicatable"
+                 << " instructions: ";
+          L->dump());
       return Rotated;
     }
     if (Metrics.Convergence != ConvergenceKind::None) {
       LLVM_DEBUG(dbgs() << "LoopRotation: NOT rotating - contains convergent "
-                  "instructions: ";
-                  L->dump());
+                           "instructions: ";
+                 L->dump());
       return Rotated;
     }
     if (!Metrics.NumInsts.isValid()) {
       LLVM_DEBUG(dbgs() << "LoopRotation: NOT rotating - contains instructions"
-                  " with invalid cost: ";
-                  L->dump());
+                           " with invalid cost: ";
+                 L->dump());
       return Rotated;
     }
     if (Metrics.NumInsts > MaxHeaderSize) {
@@ -399,7 +399,7 @@ bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
                         << Metrics.NumInsts
                         << " instructions, which is more than the threshold ("
                         << MaxHeaderSize << " instructions): ";
-                  L->dump());
+                 L->dump());
       ++NumNotRotatedDueToHeaderSize;
       return Rotated;
     }
@@ -446,12 +446,12 @@ bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
     std::swap(Exit, NewHeader);
   assert(NewHeader && "Unable to determine new loop header");
   assert(L->contains(NewHeader) && !L->contains(Exit) &&
-          "Unable to determine loop header and exit blocks");
+         "Unable to determine loop header and exit blocks");
 
   // This code assumes that the new header has exactly one predecessor.
   // Remove any single-entry PHI nodes in it.
   assert(NewHeader->getSinglePredecessor() &&
-          "New header doesn't have one pred!");
+         "New header doesn't have one pred!");
   FoldSingleEntryPHINodes(NewHeader);
 
   // Begin by walking OrigHeader and populating ValueMap with an entry for
@@ -483,7 +483,7 @@ bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
   // Build DbgVariableRecord hashes for DbgVariableRecords attached to the
   // terminator.
   for (const DbgVariableRecord &DVR :
-        filterDbgVars(OrigPreheader->getTerminator()->getDbgRecordRange()))
+       filterDbgVars(OrigPreheader->getTerminator()->getDbgRecordRange()))
     DbgRecords.insert(makeHash(&DVR));
 
   // Remember the local noalias scope declarations in the header. After the
@@ -549,7 +549,7 @@ bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
                             RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
         // Erase anything we've seen before.
         for (DbgVariableRecord &DVR :
-              make_early_inc_range(filterDbgVars(DbgValueRange)))
+             make_early_inc_range(filterDbgVars(DbgValueRange)))
           if (DbgRecords.count(makeHash(&DVR)))
             DVR.eraseFromParent();
       }
@@ -577,15 +577,14 @@ bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
                           RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
       NextDbgInsts = DbgMarker::getEmptyDbgRecordRange();
       // Erase anything we've seen before.
-      for (DbgVariableRecord &DVR :
-            make_early_inc_range(filterDbgVars(Range)))
+      for (DbgVariableRecord &DVR : make_early_inc_range(filterDbgVars(Range)))
         if (DbgRecords.count(makeHash(&DVR)))
           DVR.eraseFromParent();
     }
 
     // Eagerly remap the operands of the instruction.
     RemapInstruction(C, ValueMap,
-                      RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
+                     RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
 
     // With the operands remapped, see if the instruction constant folds or is
     // otherwise simplifyable.  This commonly occurs because the entry from PHI
@@ -658,7 +657,7 @@ bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
 
       LLVM_DEBUG(dbgs() << "  Updating OrigHeader scopes\n");
       cloneAndAdaptNoAliasScopes(NoAliasDeclScopes, {OrigHeader}, Context,
-                                  "h.rot");
+                                 "h.rot");
       LLVM_DEBUG(OrigHeader->dump());
 
       // Keep the compile time impact low by only adapting the inserted block
@@ -671,7 +670,7 @@ bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
           cast<Instruction>(ValueMap[*NoAliasDeclInstructions.begin()]);
       auto *LastInst = &OrigPreheader->back();
       cloneAndAdaptNoAliasScopes(NoAliasDeclScopes, FirstDecl, LastInst,
-                                  Context, "pre.rot");
+                                 Context, "pre.rot");
       LLVM_DEBUG(OrigPreheader->dump());
 
       LLVM_DEBUG(dbgs() << "  Updated NewHeader:\n");
@@ -684,7 +683,7 @@ bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
   // successors by duplicating their incoming values for OrigHeader.
   for (BasicBlock *SuccBB : successors(OrigHeader))
     for (BasicBlock::iterator BI = SuccBB->begin();
-          PHINode *PN = dyn_cast<PHINode>(BI); ++BI)
+         PHINode *PN = dyn_cast<PHINode>(BI); ++BI)
       PN->addIncoming(PN->getIncomingValueForBlock(OrigHeader), OrigPreheader);
 
   // Now that OrigPreHeader has a clone of OrigHeader's terminator, remove
@@ -701,7 +700,7 @@ bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
                                         ValueMapMSSA);
   }
 
-  SmallVector<PHINode*, 2> InsertedPHIs;
+  SmallVector<PHINode *, 2> InsertedPHIs;
   // If there were any uses of instructions in the duplicated block outside the
   // loop, update them, inserting PHI nodes as required
   RewriteUsesOfClonedInstructions(OrigHeader, OrigPreheader, ValueMap, SE,
@@ -759,8 +758,8 @@ bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
     // thus is not a preheader anymore.
     // Split the edge to form a real preheader.
     BasicBlock *NewPH = SplitCriticalEdge(
-                                          OrigPreheader, NewHeader,
-                                          CriticalEdgeSplittingOptions(DT, LI, MSSAU).setPreserveLCSSA());
+        OrigPreheader, NewHeader,
+        CriticalEdgeSplittingOptions(DT, LI, MSSAU).setPreserveLCSSA());
     NewPH->setName(NewHeader->getName() + ".lr.ph");
 
     // Preserve canonical loop form, which means that 'Exit' should have only
@@ -777,12 +776,12 @@ bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
         continue;
       SplitLatchEdge |= L->getLoopLatch() == ExitPred;
       BasicBlock *ExitSplit = SplitCriticalEdge(
-                                                ExitPred, Exit,
-                                                CriticalEdgeSplittingOptions(DT, LI, MSSAU).setPreserveLCSSA());
+          ExitPred, Exit,
+          CriticalEdgeSplittingOptions(DT, LI, MSSAU).setPreserveLCSSA());
       ExitSplit->moveBefore(Exit);
     }
     assert(SplitLatchEdge &&
-            "Despite splitting all preds, failed to split latch exit?");
+           "Despite splitting all preds, failed to split latch exit?");
     (void)SplitLatchEdge;
   } else {
     // We can fold the conditional branch in the preheader, this makes things
@@ -793,7 +792,8 @@ bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
     PHBI->eraseFromParent();
 
     // With our CFG finalized, update DomTree if it is available.
-    if (DT) DT->deleteEdge(OrigPreheader, Exit);
+    if (DT)
+      DT->deleteEdge(OrigPreheader, Exit);
 
     // Update MSSA too, if available.
     if (MSSAU)

``````````

</details>


https://github.com/llvm/llvm-project/pull/162482


More information about the llvm-commits mailing list