-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the postorder traversal in the DominatorTree (#5821)
Fix the postorder traversal computed by the `DominatorTree`. It was recording nodes in the wrong order depending on the order child nodes were visited. Consider the following program: ``` function %foo2(i8) -> i8 { block0(v0: i8): brif v0, block1, block2 block1: return v0 block2: jump block1 } ``` The postorder produced by the previous implementation was: ``` block2 block1 block0 ``` Which is incorrect, as `block1` is branched to by `block2`. Changing the branch order in the function would also change the postorder result, yielding the expected order with `block1` emitted first. The problem was that when pushing successor nodes onto the stack, the old implementation would also mark them SEEN. This would then prevent them from being pushed on the stack again in the future, which is incorrect as they might be visited by other nodes that have not yet been pushed. This causes nodes to potentially show up later in the postorder traversal than they should. This PR reworks the implementation of `DominatorTree::compute` to produce an order where `block1` is always returned first, regardless of the branch order in the original program. Co-authored-by: Jamey Sharp <jsharp@fastly.com>
- Loading branch information
1 parent
4fc768d
commit a139ed6
Showing
1 changed file
with
49 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters