Skip to content

MIR move elimination [5/6]: Storage reconstruction - #163339

Open
Amanieu wants to merge 2 commits into
rust-lang:mainfrom
Amanieu:move-elimination/storage-reconstruction
Open

Amanieu wants to merge 2 commits into
rust-lang:mainfrom
Amanieu:move-elimination/storage-reconstruction

Conversation

@Amanieu

@Amanieu Amanieu commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Depends on #163338

This PR extends the MoveElimination pass from rust-lang/rfcs#3943 to reconstruct StorageLive/StorageDead statements for all locals by using the liveness information collected by PreciseLiveness.

r? tmiasko

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Sep 25, 2026
@Amanieu

Amanieu commented Sep 25, 2026 •

Copy link
Copy Markdown
Member Author

LLM disclosure: LLMs were used to generate the boilerplate for the MIR tests, but each test was manually reviewed and adjusted before committing. LLMs were also used to audit this pass against the rest of the compiler MIR transforms and Miri semantics.

@Amanieu Amanieu added the llm-assisted An LLM-assisted PR as defined by the LLM policy. Requires ahead-of-time consent by assignee. label Sep 25, 2026
@Amanieu
Amanieu force-pushed the move-elimination/storage-reconstruction branch from 6745385 to 96e6975 Compare September 26, 2026 01:05
@Amanieu
Amanieu force-pushed the move-elimination/storage-reconstruction branch from 96e6975 to 7736978 Compare September 30, 2026 12:49
@rust-log-analyzer

This comment has been minimized.

@Amanieu
Amanieu force-pushed the move-elimination/storage-reconstruction branch from 7736978 to eab2d36 Compare September 30, 2026 13:03
@Amanieu
Amanieu force-pushed the move-elimination/storage-reconstruction branch from eab2d36 to 53be078 Compare October 8, 2026 23:26
@rust-log-analyzer

This comment has been minimized.

@Amanieu
Amanieu force-pushed the move-elimination/storage-reconstruction branch from 53be078 to 579316a Compare October 9, 2026 11:11
@rustbot rustbot added the A-attributes Area: Attributes (`#[…]`, `#![…]`) label Oct 9, 2026
@Amanieu
Amanieu force-pushed the move-elimination/storage-reconstruction branch from 579316a to 6256aaa Compare October 10, 2026 17:58
Comment thread compiler/rustc_mir_transform/src/move_elimination.rs
@Amanieu
Amanieu force-pushed the move-elimination/storage-reconstruction branch from 4d906d5 to 07bdf02 Compare October 19, 2026 20:54
@rust-log-analyzer

This comment has been minimized.

@Amanieu
Amanieu force-pushed the move-elimination/storage-reconstruction branch from 07bdf02 to 74b0f10 Compare October 20, 2026 07:53
@Amanieu
Amanieu force-pushed the move-elimination/storage-reconstruction branch from 74b0f10 to 3f8e6da Compare October 21, 2026 15:32
@Amanieu
Amanieu marked this pull request as ready for review October 21, 2026 15:32
@rustbot

rustbot commented Oct 21, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 21, 2026
@dianqk

dianqk commented Oct 22, 2026

Copy link
Copy Markdown
Member

I think this is a bit similar to #142531. I don't actually see any mir-opt pass that uses storage's UB in the real world. Should we have a dedicated StorageReconstruction pass placed later in the pipeline?
When using a local at a new location, we just remove the storage marks. StorageReconstruction will bring them back.
I think this should benefit other passes, such as Inline.

@tmiasko

tmiasko commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Removing storage statements and reconstructing them later, would lose information about ends of storage ranges. Consider a local which is borrowed and never moved. The best we could do, is to end its storage when function returns.

Ideally we would make decisions based on an actual measurements. We could extend perf benchmarks, e.g., by including a sum of stack adjustments from function prologues as an approximation of stack usage.

@Amanieu

Amanieu commented Oct 22, 2026

Copy link
Copy Markdown
Member Author

Essentially what @tmiasko said. The main issue is that place unification has deleted all storage statements for merged locals, so at that point the only record of where local lifetimes end is in the post-unification liveness matrix. This matrix must be used as the source for storage reconstruction within the pass.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) llm-assisted An LLM-assisted PR as defined by the LLM policy. Requires ahead-of-time consent by assignee. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants