Skip to content
This repository was archived by the owner on Oct 4, 2022. It is now read-only.

Speed up the dominance check in calc_loop_depths - #128

Merged
cfallin merged 1 commit into
bytecodealliance:mainfrom
adamrk:speed-up-dominance-check
Oct 20, 2021
Merged

cfallin merged 1 commit into
bytecodealliance:mainfrom
adamrk:speed-up-dominance-check

Conversation

@adamrk

@adamrk adamrk commented Oct 19, 2021

Copy link
Copy Markdown
Member

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

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.
@bjorn3

bjorn3 commented Oct 19, 2021

Copy link
Copy Markdown
Contributor

@cfallin Would this PR also apply to regalloc2?

@cfallin

cfallin commented Oct 19, 2021

Copy link
Copy Markdown
Member

@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 cfallin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for tracking this down, @adamrk! The early-out condition seems correct to me but @julian-seward1 could you confirm?

@adamrk

adamrk commented Oct 20, 2021

Copy link
Copy Markdown
Member Author

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

@cfallin

cfallin commented Oct 20, 2021

Copy link
Copy Markdown
Member

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!

@cfallin
cfallin merged commit 2e6d1e3 into bytecodealliance:main Oct 20, 2021
@cfallin cfallin mentioned this pull request Oct 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants