[llvm] [AMDGPU][FixIrreducible][UnifyLoopExits] Support callbr with inline-asm (PR #149308)

Robert Imschweiler via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 18 06:46:52 PDT 2025


================
@@ -186,11 +218,17 @@ static bool unifyLoopExits(DominatorTree &DT, LoopInfo &LI, Loop *L) {
   L->verifyLoop();
 
   // The guard blocks were created outside the loop, so they need to become
-  // members of the parent loop.
+  // members of the parent loop. Same goes for the callbr target blocks if they
+  // have not already been added to the respective parent loop by adding them to
+  // the original callbr target's loop.
   if (auto ParentLoop = L->getParentLoop()) {
     for (auto *G : GuardBlocks) {
       ParentLoop->addBasicBlockToLoop(G, LI);
     }
+    for (auto *C : CallBrTargetBlocks) {
+      if (!ParentLoop->contains(C))
+        ParentLoop->addBasicBlockToLoop(C, LI);
----------------
ro-i wrote:

I think that I could alternatively do something like:
```
for (auto *C : CallBrTargetBlocks) {
  if (LI-getLoopFor(C->getSingleSuccessor()) != ParentLoop)
    ParentLoop->addBasicBlockToLoop(C, LI);
}
```
However, I'm not sure whether that would be 100% correct. What if `ParentLoop` is a parent loop of `LI-getLoopFor(C->getSingleSuccessor())` --- we would have to check for that as well.

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


More information about the llvm-commits mailing list