[llvm] [WebAssembly] Incorporate SCCs into WebAssemblyFixIrreducibleControlFlow (PR #181755)
Demetrius Kanios via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 20 11:50:39 PST 2026
================
@@ -18,14 +18,16 @@
/// The big picture: We recursively process each "region", defined as a group
/// of blocks with a single entry and no branches back to that entry. A region
/// may be the entire function body, or the inner part of a loop, i.e., the
-/// loop's body without branches back to the loop entry. In each region we fix
-/// up multi-entry loops by adding a new block that can dispatch to each of the
-/// loop entries, based on the value of a label "helper" variable, and we
-/// replace direct branches to the entries with assignments to the label
-/// variable and a branch to the dispatch block. Then the dispatch block is the
-/// single entry in the loop containing the previous multiple entries. After
-/// ensuring all the loops in a region are reducible, we recurse into them. The
-/// total time complexity of this pass is:
+/// loop's body without branches back to the loop entry. In each region we
+/// identify all the strongly-connected components (SCCs). We fix up multi-entry
+/// loops (SCCs) by adding a new block that can dispatch to each of the loop
+/// entries, based on the value of a label "helper" variable, and we replace
+/// direct branches to the entries with assignments to the label variable and a
+/// branch to the dispatch block. Then the dispatch block is the single entry in
+/// the loop containing the previous multiple entries. Each time we fix some
+/// irreducibility, we recalculate the SCCs. After ensuring all the SCCs in a
+/// region are reducible, we recurse into them. The total time complexity of
+/// this pass is:
///
/// O(NumBlocks * NumNestedLoops * NumIrreducibleLoops +
/// NumLoops * NumLoops)
----------------
QuantumSegfault wrote:
I'm actually not sure what the big-O time complexity ends up being then.
We calculate SCCs (which itself is `O(N+E)`) in each region at the start, then each time we encounter an irreducible SCC we fix it, then recalculate the SCCs (which will now have 1 - 3(?) additional blocks to process). We fix each irreducible loop found then recurse into the natural loops we find.
https://github.com/llvm/llvm-project/pull/181755
More information about the llvm-commits
mailing list