[llvm] [SPIR-V] Fix block sorting with irreducible CFG (PR #116996)
Nathan Gauër via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 22 03:50:03 PST 2024
Keenuts wrote:
> I'm not sure if this works for irreducible regions because I am not sure what we are trying to accomplish.
For irreducible sub-graphs, what we want is just to comply with the requirement that a block must be placed the ones it dominates in the binary.
> In this case, you will get stuck with `toVisit = { B, C, D }`. Do we care if we choose `D` next, even if it is not part of the irreducible region?
In this case, no, we don't care. Maybe if we need a better fix, we could decide to isolate the irreducible region (here determine graph could be reducible if B-C were merged, hence pick should be between B and C).
> If this is the only restriction, then we can do a much simpler algorithm: any pre-order traversal of the dominator tree.
This would be fine for irreducible graph sorting. But the topological visitor used here is also used for structurizing.
What's important in such case is that loops belongs before the exit node.
Given this graph:
```
digraph {
Entry -> Header;
Header -> Continue;
Header -> Exit;
Continue -> Header;
}
```
The Dom-tree is as follows:
```
Entry -> Header
Header -> Exit
Header -> Continue
```
The header dominates both the exit and the continue block. But we MUST give C a lower rank than D so we can properly structurize the graph.
For this reason the algorithm is slightly tweaked to look for loops, and prioritize traversal of the loops.
(Algorithm is some kind of biased pre-order traversal of the D-tree)
https://github.com/llvm/llvm-project/pull/116996
More information about the llvm-commits
mailing list