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

Consider adding -Zcross-crate-inline-threshold=always #1512

Open
saethlin opened this issue Nov 25, 2023 · 3 comments
Open

Consider adding -Zcross-crate-inline-threshold=always #1512

saethlin opened this issue Nov 25, 2023 · 3 comments

Comments

@saethlin
Copy link

This project is already using -Zmir-opt-level=4 because it seems to decrease the size of compiled artifacts. In my own limited experimentation, -Zcross-crate-inline-threshold=always also seems to have that effect. You might find it worthwhile to enable this flag if your own testing indicates your binaries get smaller.

I implemented this flag so I know how it works but I can't really explain why it seems so effective. It basically automatically adds #[inline] to all functions which do not already have an inline attribute. The effect of that attribute is to actually lower the MIR for the function only in CGUs where it is actually referenced, and in all CGUs that reference it (CGUs in Rust tend to be crates, and thus lowering the function in all crates that reference it permits cross-crate-inlining). I think in some cases this results in dramatically improved dead code elimination, not just a more-optimized build.

@NobodyXu
Copy link
Member

This project is already using -Zmir-opt-level=4 because it seems to decrease the size of compiled artifacts.

I believe we have already disabled that due to mis-compilation and right now we use the stable toolchain for most of the release compilation, except for x86_64h-apple-darwin which needs -Zbuild-std

It basically automatically adds #[inline] to all functions which do not already have an inline attribute. The effect of that attribute is to actually lower the MIR for the function only in CGUs where it is actually referenced, and in all CGUs that reference it (CGUs in Rust tend to be crates, and thus lowering the function in all crates that reference it permits cross-crate-inlining).

Interesting, I was actually wondering if it makes sense to do MIR-level link-time-optimization, by generating MIR (or the new LIR proposed in zulip) when compiling crates, then link them together, optimize them before doing codegen.

It seems that it might be beneficial, though I don't have enough knowledge about compiler to do this.

@saethlin
Copy link
Author

due to mis-compilation

Was this reported? Any unsound MIR opt should be gated behind -Zunsound-mir-opts. If one has escaped that's a serious bug.

@NobodyXu
Copy link
Member

IIRC I have reported, but we rollback to stable because there were quite a few mis-compilation from time to time which is annoying, sometimes blocking PR merges and releases.

I do think it's actually a good thing to enable them, that will help with rustc a lot.

Maybe we can re-enable it if mis-compilation doesn't happen often?

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

No branches or pull requests

2 participants