Repository navigation
Speed up the dominance check in calc_loop_depths - #128
Conversation
The current setup requires walking the whole dominance tree from a node M to the root when checking if a node N dominates M. This process can actually be stopped as soon as a node with post-order index greater than that of N is reached. This can prevent accidentally quadratic behavior in situations where there are chains of sequential blocks.
|
@cfallin Would this PR also apply to regalloc2? |
|
@bjorn3 that's a good question, thanks for raising it; I just double-checked and it seems that the answer is "no" -- the CFG analysis in regalloc2 uses an O(n) algorithm that scans once over blocks and tracks in/out backedges, i.e., doesn't depend on the domtree. (This computes an "approximate loop depth" strictly speaking, but that matches the actual depth for any structured code with RPO-ordered blocks, which is what Cranelift produces.) |
cfallin
left a comment
There was a problem hiding this comment.
Thank you so much for tracking this down, @adamrk! The early-out condition seems correct to me but @julian-seward1 could you confirm?
|
By the way, the fact that the set is ordered is discussed on page 6 of the paper referenced in the code: https://www.cs.rice.edu/~keith/EMBED/dom.pdf |
|
I took another close look at this and I think I'm confident enough to merge it; I'll go ahead and do so then do a crates.io release so we can pull this into Cranelift. Thanks again! |
The current setup requires walking the whole dominance tree from a node
M to the root when checking if a node N dominates M. This process can
actually be stopped as soon as a node with post-order index greater than
that of N is reached. This can prevent accidentally quadratic behavior
as found here: bytecodealliance/wasmtime#3441