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

Never inline C variadics, cold functions, functions with incompatible attributes ... #78966

Merged
merged 6 commits into from
Nov 15, 2020

Conversation

tmiasko
Copy link
Contributor

@tmiasko tmiasko commented Nov 12, 2020

... and fix generator inlining.

Closes #67863.
Closes #78859.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 12, 2020
@jyn514 jyn514 added A-mir-opt-inlining Area: MIR inlining T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 12, 2020
@oli-obk
Copy link
Contributor

oli-obk commented Nov 12, 2020

@bors r+

very excited about the generator inlining. With this we'll be able to craft some MIR optimizations for async code

@bors
Copy link
Contributor

bors commented Nov 12, 2020

📌 Commit f91a0ef has been approved by oli-obk

@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 Nov 12, 2020
m-ou-se added a commit to m-ou-se/rust that referenced this pull request Nov 12, 2020
Never inline C variadics, cold functions, functions with incompatible attributes ...

... and fix generator inlining.

Closes rust-lang#67863.
Closes rust-lang#78859.
@m-ou-se
Copy link
Member

m-ou-se commented Nov 12, 2020

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 12, 2020
The inliner looks if a sanitizer is enabled before considering
`no_sanitize` attribute as possible source of incompatibility.

The MIR inlining could happen in a crate with sanitizer disabled, but
code generation in a crate with sanitizer enabled, thus the attribute
would be incorrectly ignored.

To avoid the issue never inline functions with different `no_sanitize`
attributes.
The information about cold attribute is lost during inlining,
Avoid the issue by never inlining cold functions.
The callee body is already transformed; the condition is always false.
@tmiasko
Copy link
Contributor Author

tmiasko commented Nov 12, 2020

Ignored new generator test on wasm.

@oli-obk
Copy link
Contributor

oli-obk commented Nov 13, 2020

@bors r+

@bors
Copy link
Contributor

bors commented Nov 13, 2020

📌 Commit 2a010dd has been approved by oli-obk

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 13, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Nov 13, 2020
Never inline C variadics, cold functions, functions with incompatible attributes ...

... and fix generator inlining.

Closes rust-lang#67863.
Closes rust-lang#78859.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Nov 13, 2020
Never inline C variadics, cold functions, functions with incompatible attributes ...

... and fix generator inlining.

Closes rust-lang#67863.
Closes rust-lang#78859.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Nov 14, 2020
Never inline C variadics, cold functions, functions with incompatible attributes ...

... and fix generator inlining.

Closes rust-lang#67863.
Closes rust-lang#78859.
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 15, 2020
Rollup of 15 pull requests

Successful merges:

 - rust-lang#78352 (Do not call `unwrap` with `signatures` option enabled)
 - rust-lang#78590 (refactor: removing alloc::collections::vec_deque ignore-tidy-filelength)
 - rust-lang#78848 (Bump minimal supported LLVM version to 9)
 - rust-lang#78856 (Explicitly checking for or-pattern before test)
 - rust-lang#78948 (test: add `()=()=()=...` to weird-exprs.rs)
 - rust-lang#78962 (Add a test for r# identifiers)
 - rust-lang#78963 (Added some unit tests as requested)
 - rust-lang#78966 (Never inline C variadics, cold functions, functions with incompatible attributes ...)
 - rust-lang#78968 (Include llvm-as in llvm-tools-preview component)
 - rust-lang#78969 (Normalize function type during validation)
 - rust-lang#78980 (Fix rustc_ast_pretty print_qpath resulting in invalid macro input)
 - rust-lang#78986 (Avoid installing external LLVM dylibs)
 - rust-lang#78988 (Fix an intrinsic invocation on threaded wasm)
 - rust-lang#78993 (rustc_target: Fix dash vs underscore mismatches in option names)
 - rust-lang#79013 (Clean up outdated `use_once_payload` pretty printer comment)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 6be44ed into rust-lang:master Nov 15, 2020
@rustbot rustbot added this to the 1.50.0 milestone Nov 15, 2020
@tmiasko tmiasko deleted the inline-never branch November 15, 2020 10:22
@novacrazy
Copy link

Does this PR have the potential to break this workaround in hashbrown? rust-lang/hashbrown#209

@tmiasko
Copy link
Contributor Author

tmiasko commented Nov 20, 2020

@novacrazy Thanks, that is a great example of a pattern that patch here tries to enable.

Currently in MIR the cold attribute can be only attached to a function. If a call to a cold function were to be inlined in MIR, the fact that this is a cold path is lost to the LLVM. The changes here disable inlining of cold functions at MIR level precisely to preserve this information.

That being said, the MIR inlining is disabled by default. So unless -Zmir-opt-level >= 2 is used, there will be no impact anyway.

@thomcc
Copy link
Member

thomcc commented Nov 20, 2020

Currently in MIR the cold attribute can be only attached to a function. If a call to a cold function were to be inlined in MIR, the fact that this is a cold path is lost to the LLVM.

Anecdotally, this happens when LLVM inlines cold functions too (which it does if you only have one call to it unless it's #[inline(never)] 😞).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-mir-opt-inlining Area: MIR inlining S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Calls to C variadic functions are inlined by MIR inliner MIR inlining checks for impossible condition
9 participants