Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace a recursive algorithm with an iterative one and a stack. #74983

Merged
merged 1 commit into from
Aug 1, 2020

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Jul 31, 2020

fixes #74931

@rust-highfive
Copy link
Collaborator

r? @ecstatic-morse

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 31, 2020
@Mark-Simulacrum
Copy link
Member

@bors try @rust-timer queue

Seems not unlikely to have some perf effects.

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Contributor

bors commented Jul 31, 2020

⌛ Trying commit ac5b2b0a2a6d526901b412f07651885be3c7f1f9 with merge 7ecf4177219d2b3082e0d5ee04edff8af3e1e80b...

@bors
Copy link
Contributor

bors commented Jul 31, 2020

☀️ Try build successful - checks-actions, checks-azure
Build commit: 7ecf4177219d2b3082e0d5ee04edff8af3e1e80b (7ecf4177219d2b3082e0d5ee04edff8af3e1e80b)

@rust-timer
Copy link
Collaborator

Queued 7ecf4177219d2b3082e0d5ee04edff8af3e1e80b with parent 62f9aa9, future comparison URL.

Copy link
Contributor

@ecstatic-morse ecstatic-morse left a comment

Choose a reason for hiding this comment

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

Thanks for doing this @oli-obk. I remember looking at this code early on and wondering if it was going to ruin someone's day 😄. This is a pretty straightforward translation of the recursive version, so I feel good about it even though I left some questions.

self.pred_count[*target] += 1;
self.pred_count[current] -= 1;
}
*changed |= current != *target;
Copy link
Contributor

Choose a reason for hiding this comment

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

Preexisting I know, but why do we only mark the MIR as changed if current != target? If current == target then we are inserting a self-loop, but it's possible for this to represent a change in the MIR if we had a cycle involving several Gotos.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have learned the hard way that tinkering with this code is not a good idea XD But I've also learned that you either break it completely or not at all, there's no middle ground, so I guess i can do more experimentation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh well, it worked :D

Copy link
Contributor

@ecstatic-morse ecstatic-morse Jul 31, 2020

Choose a reason for hiding this comment

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

If you don't wanna lump it into this PR, that's fine too. It just didn't make sense to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's already in this PR ;)

self.pred_count[*start] -= 1;
// Collapse a goto chain starting from `start`
fn collapse_goto_chain(&mut self, start: &mut BasicBlock, changed: &mut bool) {
let mut terminators: SmallVec<[_; 1]> = Default::default();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the SmallVec here? In the common case, start will not refer to a Goto with no statements, so terminators will be empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

anecdotal evidence showed me many single-step goto chains (I had logging on during libcore builds). But we can also just go ahead and benchmark Vec vs SmallVec<[_; 1]> and maybe some other default sizes.

Copy link
Contributor

@ecstatic-morse ecstatic-morse Jul 31, 2020

Choose a reason for hiding this comment

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

I'm satisfied with that. It shouldn't matter much either way, maybe leave a comment?

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (7ecf4177219d2b3082e0d5ee04edff8af3e1e80b): comparison url.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying rollup- to bors.

Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up.

@bors rollup=never

@ecstatic-morse
Copy link
Contributor

@bors rollup

@oli-obk r=me when you're happy

@oli-obk oli-obk force-pushed the mir_opt_goto_chain branch from 49d0c9a to aba0251 Compare August 1, 2020 05:20
@oli-obk
Copy link
Contributor Author

oli-obk commented Aug 1, 2020

@bors r=ecstatic-morse

@bors
Copy link
Contributor

bors commented Aug 1, 2020

📌 Commit aba0251 has been approved by ecstatic-morse

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 1, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 1, 2020
…arth

Rollup of 6 pull requests

Successful merges:

 - rust-lang#74977 (Clean up E0741 error explanation)
 - rust-lang#74981 (Some fixes for `plugin.md` in unstable-book)
 - rust-lang#74983 (Replace a recursive algorithm with an iterative one and a stack.)
 - rust-lang#74995 (Update the WASI libc build to LLVM 10.)
 - rust-lang#74996 (submodules: update cargo from 974eb438d to 2d5c2381e)
 - rust-lang#75007 (Clean up E0743 explanation)

Failed merges:

r? @ghost
@bors bors merged commit 6951581 into rust-lang:master Aug 1, 2020
@oli-obk oli-obk deleted the mir_opt_goto_chain branch August 2, 2020 06:18
@cuviper cuviper added this to the 1.47.0 milestone May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"thread 'rustc' has overflowed its stack" introduced in 1.45.0
7 participants