Skip to content

relooper: Avoid recomputing strict_reachable_from in simple case#1827

Open
randomPoison wants to merge 1 commit into
masterfrom
legare/relooper-fix-quadratic
Open

relooper: Avoid recomputing strict_reachable_from in simple case#1827
randomPoison wants to merge 1 commit into
masterfrom
legare/relooper-fix-quadratic

Conversation

@randomPoison

Copy link
Copy Markdown
Contributor

Fixes #1821 by avoiding computing strict_reachable_from in the case of linear control flow. The performance issue there was that we were recomputing strict_reachable_from in every call to relooper, which means we recompute it after processing each block in the CFG. For very long CFGs like the one in #1821 that results in a lot of redundant work, causing translation to take a very long time.

The fix for the specific case in #1821 is simple, but I suspect there are other edge cases that could cause similar quadratic behavior. I think we could be a bit smarter about when we recompute reachability info, since I think reachability only meaningfully changes when we strip back edges while processing a loop. I don't have time to experiment with that now, though, so I've added a TODO comment in there as a note to look into that in the future.

@fw-immunant fw-immunant left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One question and one comment suggestion inline.

Also, is it possible/feasible to add a test case here?

Comment on lines +254 to +257
let has_back_edge = local_successors
.values()
.any(|successors| successors.contains(entry));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

has_back_edge here seems to match the original condition here--"if the entry is in the transitive closure of any of its successors, there is a back edge". But the new condition doesn't search transitively. What justifies only looking at immediate successors? Is this connected to the comment on strict_reachable_from that says we only consider the local set of blocks? How does this relate to the comment that says "we don't want to consider back edges"--are we possibly "inside a loop" here?

Comment on lines +245 to +247
// TODO: If possible we should avoid recomputing this every time. I think the
// reachability information only meaningfully changes when we strip a back edge,
// so in theory we should only need to recompute this after processing a loop.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// TODO: If possible we should avoid recomputing this every time. I think the
// reachability information only meaningfully changes when we strip a back edge,
// so in theory we should only need to recompute this after processing a loop.
// TODO: If possible we should avoid recomputing this every time `relooper` recurses. I think the
// reachability information only meaningfully changes when we strip a back edge,
// so in theory we should only need to recompute this after processing a loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reworked relooper regressed on some large CFGs

2 participants