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

Const prop creates assignments from large constants #73203

Closed
oli-obk opened this issue Jun 10, 2020 · 2 comments
Closed

Const prop creates assignments from large constants #73203

oli-obk opened this issue Jun 10, 2020 · 2 comments
Labels
A-mir-opt Area: MIR optimizations C-enhancement Category: An issue proposing an enhancement or a PR with one. C-optimization Category: An issue highlighting optimization opportunities or PRs implementing such T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@oli-obk
Copy link
Contributor

oli-obk commented Jun 10, 2020

Background discussion: #71911 (comment)

If we have an assignment of Rvalue::Aggregate in const-prop, and we can figure out that all fields are Operand::Const, we end up replacing the Rvalue::Aggregate with an Rvalue::Use of a constant that contains the entire aggregate. This may end up creating large assignments that copy from constant memory to the stack at runtime. It may sometimes be cheaper to just build the constant at runtime. This is very true if the constant is actually a None where the Some part is a huge value. We'd have a very big constant with most bits undefined that we copy over, even if the runtime operation would just be "set the discriminant bits".

cc @rust-lang/wg-mir-opt

Should we have some heuristic here? Should we only do this optimization for Scalars and ScalarPairs? Other opinions?

@oli-obk oli-obk added the A-mir-opt Area: MIR optimizations label Jun 10, 2020
@oli-obk
Copy link
Contributor Author

oli-obk commented Jun 10, 2020

kinda related: #54360

@jonas-schievink jonas-schievink added C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 10, 2020
@workingjubilee workingjubilee added the C-optimization Category: An issue highlighting optimization opportunities or PRs implementing such label Oct 8, 2023
@cjgillot
Copy link
Contributor

cjgillot commented Jan 7, 2024

We now have a size limit on propagated constants.

@cjgillot cjgillot closed this as completed Jan 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-mir-opt Area: MIR optimizations C-enhancement Category: An issue proposing an enhancement or a PR with one. C-optimization Category: An issue highlighting optimization opportunities or PRs implementing such T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants