[llvm] [AMDGPU] Teach SIPreEmitPeephole pass to preserve MachineLoopInfo (PR #178868)

via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 15 22:27:40 PST 2026


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/Target/AMDGPU/SIPreEmitPeephole.cpp --diff_from_common_commit
``````````

: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/Target/AMDGPU/SIPreEmitPeephole.cpp b/llvm/lib/Target/AMDGPU/SIPreEmitPeephole.cpp
index 815f55918..84f5a052a 100644
--- a/llvm/lib/Target/AMDGPU/SIPreEmitPeephole.cpp
+++ b/llvm/lib/Target/AMDGPU/SIPreEmitPeephole.cpp
@@ -141,21 +141,21 @@ void SIPreEmitPeephole::updateMLIBeforeRemovingEdge(
       MLI->changeLoopFor(BB, ParentLoop);
   }
 
-    // Reparent all child loops.
-    while (!Loop->isInnermost()) {
-      MachineLoop *Child = Loop->removeChildLoop(std::prev(Loop->end()));
-      if (ParentLoop)
-        ParentLoop->addChildLoop(Child);
-      else
-        MLI->addTopLevelLoop(Child);
-    }
-
+  // Reparent all child loops.
+  while (!Loop->isInnermost()) {
+    MachineLoop *Child = Loop->removeChildLoop(std::prev(Loop->end()));
     if (ParentLoop)
-      ParentLoop->removeChildLoop(Loop);
+      ParentLoop->addChildLoop(Child);
     else
-      MLI->removeLoop(llvm::find(*MLI, Loop));
+      MLI->addTopLevelLoop(Child);
+  }
+
+  if (ParentLoop)
+    ParentLoop->removeChildLoop(Loop);
+  else
+    MLI->removeLoop(llvm::find(*MLI, Loop));
 
-    MLI->destroy(Loop);
+  MLI->destroy(Loop);
 }
 
 bool SIPreEmitPeephole::optimizeVccBranch(MachineInstr &MI) const {

``````````

</details>


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


More information about the llvm-commits mailing list