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

rustc_mir: handle all aggregate kinds in, and always run, the deaggregator. #48052

Merged
merged 7 commits into from
Feb 23, 2018

Conversation

eddyb
Copy link
Member

@eddyb eddyb commented Feb 7, 2018

This helps with removingRvalue::Aggregate from the MIR, and with enabling more optimizations.
r? @nikomatsakis

@eddyb
Copy link
Member Author

eddyb commented Feb 7, 2018

This might be a bit slow to run, let's see:

@bors try

@bors
Copy link
Contributor

bors commented Feb 7, 2018

⌛ Trying commit fda2441f1b34fd6135e7af93aec859ad7e4434ad with merge 23ae5261b60c2cf53547176a3b625359c00f6a5f...

@kennytm kennytm added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 7, 2018
@eddyb
Copy link
Member Author

eddyb commented Feb 7, 2018

UI tests still broken on master, concealed test that needed to be updated.

@bors try

@bors
Copy link
Contributor

bors commented Feb 7, 2018

⌛ Trying commit 5cc4b94 with merge 7d831d0...

bors added a commit that referenced this pull request Feb 7, 2018
 rustc_mir: handle all aggregate kinds in, and always run, the deaggregator.

This helps with removing`Rvalue::Aggregate` from the MIR, and with enabling more optimizations.
r? @nikomatsakis
if tcx.sess.opts.debugging_opts.mir_opt_level <= 2 {
return;
}

// Don't run on constant MIR, because trans might not be able to
// evaluate the modified MIR.
// FIXME(eddyb) Remove check after miri is merged.
let id = tcx.hir.as_local_node_id(source.def_id).unwrap();
match (tcx.hir.body_owner_kind(id), source.promoted) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I find this match a bit hard to read. Maybe something like this?

let is_constant = source.promoted.is_some() || match tcx.hir.body_owner_kind(id) {
    hir::BodyOwnerKind::Const | hir::BodyOwnerKind::Static(_) => true,
    hir::BodyOwnerKind::Fn => tcx.is_const_fn(source.def_id),
};
if is_constant {
    return;
}

Copy link
Member Author

Choose a reason for hiding this comment

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

It's copied from elsewhere, this pattern is used in several passes - and this will hopefully go away ~soon anyway.

while let Some(i) = bb.statements[start..].iter().position(&can_deaggregate) {
let i = start + i;

// FIXME(eddyb) this is probably more expensive than it should be.
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems fine, you could also drain() and accumulate into a fresh vector or something...

let mut new_statements = vec![]; 
for statement in bb.statements.drain(..) {
    if !can_deaggregate(statement) {
        new_statements.push(statement);
    }
    ...
}

though probably you would want to test first that there is at least one match.

lhs.clone().elem(ProjectionElem::ConstantIndex {
offset,
// FIXME(eddyb) `min_length` doesn't appear to be used.
min_length: offset + 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

It was intended to be used for slice patterns by borrow check, I believe (and perhaps to handle from_end).

Copy link
Contributor

Choose a reason for hiding this comment

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

This is still a WIP =)

@nikomatsakis
Copy link
Contributor

r=me modulo that one nit about the match

@eddyb
Copy link
Member Author

eddyb commented Feb 7, 2018

@nikomatsakis I don't want to merge with the last commit (which turns this on by default) without perf results - if this is too slow we'd have to optimize it first or wait until we can remove Aggregate.

// Lowering generator control-flow and variables
// has to happen before we do anything else to them.
generator::StateTransform,

Copy link
Contributor

Choose a reason for hiding this comment

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

We want to lower generator as late as possible, in particular we want to run at least SimplifyLocals before the StateTransform. Did you move this up because you triggered the sanity checks in StateTransform?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, those sanity checks don't survive past optimizations.

@bors
Copy link
Contributor

bors commented Feb 7, 2018

☀️ Test successful - status-travis
State: approved= try=True

@eddyb
Copy link
Member Author

eddyb commented Feb 7, 2018

@Mark-Simulacrum Can I get a perf run of this?

@eddyb
Copy link
Member Author

eddyb commented Feb 7, 2018

I can reproduce the Travis failure (which didn't trigger on the @bors run) locally - and if I change

$(RUSTC) foo.rs --emit=llvm-ir -C codegen-units=3 \

from 3 to 4 it passes. With only 3 CGUs, some may get merged (based on MIR complexity?)

//! - There are two codegen units for every source-level module:

According to this comment, the test is wrong and it should use 6 to ensure one CGU per module.
I'll push a fix for the test.

@eddyb
Copy link
Member Author

eddyb commented Feb 8, 2018

The perf results don't look great for deep-vector - if you open it, you'll see why: it has a very large vec![...], which internally uses box [...] and now every single of those fields gets deaggregated.

#48052 (comment) seems irrelevant, it's really just slowed down by dealing with individual element destinations. @nikomatsakis Do we defer on array deaggregation, or take the hit?

@nikomatsakis
Copy link
Contributor

nikomatsakis commented Feb 8, 2018

@eddyb maybe we should set a threshold? (e.g., deaggregate up to length 8 or 16 or something?)

@eddyb
Copy link
Member Author

eddyb commented Feb 8, 2018

@nikomatsakis That's not as useful because my eventual plan is to just kill off Rvalue::Aggregate.

@pietroalbini pietroalbini added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 12, 2018
@nikomatsakis
Copy link
Contributor

So @eddyb and I discussed the deep-vector slowdown over IRC. They are hoping that they can remove it by altering the structure of MIR in various ways to make it more efficient -- e.g., to simplify places, and hence flatten statements so that they don't require allocation.

My current feeling is that we should insert a threshold check for now so that deep-vector doesn't regress, and then re-evaluate as we make those changes. If we have to swallow a compilation time hit on this use case, so be it, but I'd rather wait until later.

Also, I'd like to see some perf benchmarks covering big constants that are not vec![] (e.g., &[...], include!, etc). Not sure if we have those.

cc @rust-lang/compiler -- thoughts?

@eddyb
Copy link
Member Author

eddyb commented Feb 13, 2018

My position is that we should just not do arrays for now if that regresses too much.

@nikomatsakis
Copy link
Contributor

@eddyb that seems fine too, let's just open a FIXME

@nikomatsakis
Copy link
Contributor

r=me with that done

@eddyb
Copy link
Member Author

eddyb commented Feb 14, 2018

@bors try

@bors
Copy link
Contributor

bors commented Feb 14, 2018

⌛ Trying commit b91a7e5 with merge 4b24c56...

bors added a commit that referenced this pull request Feb 14, 2018
 rustc_mir: handle all aggregate kinds in, and always run, the deaggregator.

This helps with removing`Rvalue::Aggregate` from the MIR, and with enabling more optimizations.
r? @nikomatsakis
@bors bors added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 21, 2018
@eddyb
Copy link
Member Author

eddyb commented Feb 21, 2018

@bors retry

  • update failed

@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 Feb 21, 2018
@bors
Copy link
Contributor

bors commented Feb 22, 2018

⌛ Testing commit c9fcede with merge a63e5c3a0377366521072aa3c6bfc5f9484efb52...

@bors
Copy link
Contributor

bors commented Feb 22, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: nikomatsakis
Pushing a63e5c3a0377366521072aa3c6bfc5f9484efb52 to master...

@eddyb
Copy link
Member Author

eddyb commented Feb 22, 2018

Do I need to rebase or something?...

@kennytm
Copy link
Member

kennytm commented Feb 22, 2018

@bors retry

It seems we had accidentally revoked bors's push permission, thus the failure to merge.

@bors
Copy link
Contributor

bors commented Feb 22, 2018

⌛ Testing commit c9fcede with merge 625d01a26b2254ee9cd54bf206b7b3c6e74ffbbb...

@bors
Copy link
Contributor

bors commented Feb 22, 2018

💔 Test failed - status-appveyor

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 22, 2018
@kennytm
Copy link
Member

kennytm commented Feb 22, 2018

@bors retry #46903

@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 Feb 22, 2018
@bors
Copy link
Contributor

bors commented Feb 22, 2018

⌛ Testing commit c9fcede with merge a9099f59b5a5d7f9ffb8b5b96f8c4757601c9e9c...

@bors
Copy link
Contributor

bors commented Feb 22, 2018

💔 Test failed - status-appveyor

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 22, 2018
@kennytm
Copy link
Member

kennytm commented Feb 22, 2018

@bors retry #46903

@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 Feb 22, 2018
@bors
Copy link
Contributor

bors commented Feb 23, 2018

⌛ Testing commit c9fcede with merge 9284353...

bors added a commit that referenced this pull request Feb 23, 2018
 rustc_mir: handle all aggregate kinds in, and always run, the deaggregator.

This helps with removing`Rvalue::Aggregate` from the MIR, and with enabling more optimizations.
r? @nikomatsakis
@bors
Copy link
Contributor

bors commented Feb 23, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: nikomatsakis
Pushing 9284353 to master...

@bors bors merged commit c9fcede into rust-lang:master Feb 23, 2018
@eddyb eddyb deleted the deggregate branch February 23, 2018 15:18
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.

8 participants