[llvm] [Uniformity] Fixed control-div early stop (PR #139667)

Sameer Sahasrabuddhe via llvm-commits llvm-commits at lists.llvm.org
Wed May 21 04:59:16 PDT 2025


================
@@ -626,14 +623,36 @@ template <typename ContextT> class DivergencePropagator {
         LLVM_DEBUG(dbgs() << "\tImmediate divergent cycle exit: "
                           << Context.print(SuccBlock) << "\n");
       }
-      auto SuccIdx = CyclePOT.getIndex(SuccBlock);
       visitEdge(*SuccBlock, *SuccBlock);
-      FloorIdx = std::min<int>(FloorIdx, SuccIdx);
     }
 
+    // Return true if B is inside an irreducible cycle
+    auto IsInIrreducibleCycle = [this](const BlockT *B) {
+      for (const auto *Cycle = CI.getCycle(B); Cycle;
+           Cycle = Cycle->getParentCycle()) {
+        if (!Cycle->isReducible())
+          return true;
----------------
ssahasra wrote:

```suggestion
        // If everything is inside a reducible cycle, then look no further
        if (Cycle->isReducible()) && Cycle->contains(DivTermBlock))
          return false;
        if (!Cycle->isReducible())
          return true;
```
I have not tested this thoroughly yet, but I believe we can stop early if we reach a reducible cycle that contains both the `DivTermBlock` and the current block. This ensures that we don't end up unnecessarily traversing a large cycle like in this situation:

```
C1 (irreducible) contains:
  C2 (reducible) contains:
     Divergent branch B and all possible join points
```
In this case, we should not continue traversing all of `C1` when only one fresh label is being reported. It needs to be proven, but intuitively, C2 is the cycle that contains both the branch and its IPD.

I am still thinking whether we should traverse `C1` or not if `C2` is irreducible.

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


More information about the llvm-commits mailing list