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

Added MIR constant propagation of Scalars into function call arguments #71697

Merged
merged 1 commit into from
May 4, 2020
Merged

Added MIR constant propagation of Scalars into function call arguments #71697

merged 1 commit into from
May 4, 2020

Conversation

felix91gr
Copy link
Contributor

Now for the function call arguments!

Caveats:

  1. It's only being enabled at mir-opt-2 or higher, because currently codegen gives performance regressions with this optimization.
  2. Only propagates Scalars. Tuples and references (references are Indirect, right??) are not being propagated into as of this PR.
  3. Maybe more tests would be nice?
  4. I need (shamefully) to ask @wesleywiser to write in his words (or explain to me, and then I can write it down) why we want to ignore propagation into ScalarPairs and Indirect arguments.

r? @wesleywiser

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 29, 2020
@felix91gr
Copy link
Contributor Author

This is a continuation of #71522

@felix91gr
Copy link
Contributor Author

CC @oli-obk <3

@felix91gr
Copy link
Contributor Author

felix91gr commented Apr 30, 2020

The mingw check failed, seemingly because of some network issue? Welp, we'll see what do the Azure checks say. Everything should be allright.

Edit: Azure CI passed, so it was indeed just some network issue on the servers. Did a forced push to restart the CI testing.

@felix91gr
Copy link
Contributor Author

@wesleywiser does Github ping you when I re-request a review? (I ask so that I know to tag you or not for the next PRs in which you review me)

Anyway... I think this is done! I have written down the full rationale. Lemme know what you think :)

@felix91gr
Copy link
Contributor Author

omg I'm an idiot. Brb. Formatting (this always happens to me whenever I write documentation 😅 )

- Documented rationale of current solution
- Polished documentation
@felix91gr
Copy link
Contributor Author

Fixed!

The following code would appear to be incomplete, because
the function `Operand::place()` returns `None` if the
`Operand` is of the variant `Operand::Constant`. In this
context however, that variant will never appear. This is why:
Copy link
Contributor

Choose a reason for hiding this comment

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

The 42 is a const in the MIR's function call arguments in

fn main() {
    foo(42);
}

fn foo(i: i32) {}

But that's already "propagated" so it's fine and we don't need to care about it.

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 took me a while to realize what you meant. But indeed! Those are already "propagated": https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=9bfca57ccf6c252f7e601ed58beb7895

Should I add something to the comment?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yea, I think the comment should be adjusted. It's not that an Operand::Constant doesn't appear, it's that when it does, it's already constant and we don't need to propagate anything.

@wesleywiser
Copy link
Member

Yeah, I get pinged I was just afk today.

This looks good to me but I'll do one last review tomorrow!

@felix91gr
Copy link
Contributor Author

Okay, that's good to know :3
Have a good time today/tonight, Wesley 😊

@wesleywiser
Copy link
Member

Looking great!

@bors r+ rollup

(functional changes are gated under mir-opt-level=2 so there will be no performance impact)

@bors
Copy link
Contributor

bors commented May 4, 2020

📌 Commit d0dea9f has been approved by wesleywiser

@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 May 4, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request May 4, 2020
…wesleywiser

Added MIR constant propagation of Scalars into function call arguments

Now for the function call arguments!

Caveats:
1. It's only being enabled at `mir-opt-2` or higher, because currently codegen gives performance regressions with this optimization.
2. Only propagates Scalars. Tuples and references (references are `Indirect`, right??) are not being propagated into as of this PR.
3. Maybe more tests would be nice?
4. I need (shamefully) to ask @wesleywiser to write in his words (or explain to me, and then I can write it down) why we want to ignore propagation into `ScalarPairs` and `Indirect` arguments.

r? @wesleywiser
bors added a commit to rust-lang-ci/rust that referenced this pull request May 4, 2020
Rollup of 5 pull requests

Successful merges:

 - rust-lang#71038 (forbid `dyn Trait` in patterns)
 - rust-lang#71697 (Added MIR constant propagation of Scalars into function call arguments)
 - rust-lang#71773 (doc: misc rustdoc things)
 - rust-lang#71810 (Do not try to find binop method on RHS `TyErr`)
 - rust-lang#71877 (Use f64 in f64 examples)

Failed merges:

r? @ghost
@bors bors merged commit d47ec16 into rust-lang:master May 4, 2020
@felix91gr felix91gr deleted the new_prop_into_fn_call branch May 4, 2020 21:40
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.

5 participants