Skip to content

MIR move elimination [1.5/6]: Ensure ZSTs are always initialized - #163359

Open
Amanieu wants to merge 6 commits into
rust-lang:mainfrom
Amanieu:move-elimination/zst-initialization
Open

Amanieu wants to merge 6 commits into
rust-lang:mainfrom
Amanieu:move-elimination/zst-initialization

Conversation

@Amanieu

@Amanieu Amanieu commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

View all comments

Split off from #163335

The new MIR semantics from rust-lang/rfcs#3943 require that a local be initialized before it is used, since it only gains an allocation at that point. This means that ZSTs must be initialized before being read, even though the initialization is a no-op in codegen.

This PR addresses this in 2 ways:

  • Adds missing ZST initializations in MIR shims and MIR intrinsic lowering.
  • Restricts the RemoveZsts pass to only remove ZST assignments when the destination is indirect, since such places are required to already be allocated anyways. This is fine in practice since dead ZST assignments are later removed by DSE.

The last one also exposed a limitation in SimplifyMatch's handling of constant equality when checking if two match arms are equivalent: it was only checking for scalar constants and was not handling () unit constants, which resulted in a test regression. The pass has been fixed to handle any kind of ConstValue.

r? tmiasko

@rustbot

rustbot commented Sep 25, 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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 25, 2026
@tmiasko

tmiasko commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 25, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Sep 25, 2026
…r=<try>

MIR move elimination [1.5/6]: Ensure ZSTs are always initialized
@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
@rust-log-analyzer

This comment was marked as outdated.

@Amanieu
Amanieu force-pushed the move-elimination/zst-initialization branch from 104da00 to b25b42e Compare September 25, 2026 22:39
@rust-bors

rust-bors Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: ddd9a7e (ddd9a7ecfa5c69a3f9af801bd95c308d8b298a87)
Base parent: 5ceaf66 (5ceaf6608eb354c2f5bbb3b8d974caa367dac81c)

@rust-timer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (ddd9a7e): comparison URL.

Overall result: ❌✅ regressions and improvements - please read:

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

Next, please: If you can, justify the regressions found in this try perf run in writing along with @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

@bors rollup=never rustc-perf
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
1.0% [0.4%, 2.4%] 5
Regressions ❌
(secondary)
0.7% [0.2%, 2.2%] 9
Improvements ✅
(primary)
-0.6% [-1.7%, -0.2%] 31
Improvements ✅
(secondary)
-0.4% [-0.8%, -0.2%] 4
All ❌✅ (primary) -0.4% [-1.7%, 2.4%] 36

Max RSS (memory usage)

Results (primary -0.6%, secondary -0.3%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
1.9% [1.8%, 2.0%] 2
Regressions ❌
(secondary)
1.9% [1.3%, 2.3%] 3
Improvements ✅
(primary)
-5.7% [-5.7%, -5.7%] 1
Improvements ✅
(secondary)
-2.5% [-2.7%, -2.2%] 3
All ❌✅ (primary) -0.6% [-5.7%, 2.0%] 3

Cycles

Results (secondary 0.4%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.4% [0.4%, 0.4%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

Results (primary -0.9%, secondary 0.8%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.4% [0.5%, 12.6%] 7
Regressions ❌
(secondary)
6.6% [0.5%, 12.6%] 2
Improvements ✅
(primary)
-2.5% [-6.5%, -0.0%] 14
Improvements ✅
(secondary)
-3.0% [-5.2%, -1.6%] 3
All ❌✅ (primary) -0.9% [-6.5%, 12.6%] 21

Bootstrap: 488.629s -> 489.137s (0.10%)
Artifact size: 406.21 MiB -> 406.48 MiB (0.07%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Sep 26, 2026
@rust-log-analyzer

This comment has been minimized.

@Amanieu

Amanieu commented Sep 26, 2026

Copy link
Copy Markdown
Member Author

I investigated the perf results: they are entirely due to different CGU partitioning. Retaining ZST assignments affects function size estimates. The actual ZST assignments never make it to LLVM codegen.

@rust-log-analyzer

This comment has been minimized.

@Amanieu
Amanieu force-pushed the move-elimination/zst-initialization branch from 34e20b4 to 2f4b8da Compare September 26, 2026 04:50
@rustbot rustbot added the A-run-make Area: port run-make Makefiles to rmake.rs label Sep 26, 2026
Comment thread tests/codegen-llvm/lib-optimizations/append-elements.rs Outdated
@rust-bors

This comment has been minimized.

@Amanieu
Amanieu force-pushed the move-elimination/zst-initialization branch from 2f4b8da to c1901f7 Compare September 30, 2026 13:03
@rustbot

This comment has been minimized.

@dianqk dianqk self-assigned this Oct 7, 2026
@rust-bors

This comment has been minimized.

@Amanieu
Amanieu force-pushed the move-elimination/zst-initialization branch from c1901f7 to b60e110 Compare October 8, 2026 15:38
@rustbot

rustbot commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@dianqk

dianqk commented Oct 9, 2026

Copy link
Copy Markdown
Member

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 9, 2026
rust-bors Bot pushed a commit that referenced this pull request Oct 9, 2026
…r=<try>

MIR move elimination [1.5/6]: Ensure ZSTs are always initialized
@rust-bors

rust-bors Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 7210f43 (7210f43951c5829cfd312321f4c883497a0d0b64)
Base parent: 76c9095 (76c90957b7e422c4b9c45192b0197214d7de5a54)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (7210f43): comparison URL.

Overall result: ❌✅ regressions and improvements - please read:

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

Next, please: If you can, justify the regressions found in this try perf run in writing along with @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

@bors rollup=never rustc-perf
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
0.8% [0.2%, 2.4%] 6
Regressions ❌
(secondary)
0.9% [0.3%, 2.6%] 5
Improvements ✅
(primary)
-0.6% [-0.6%, -0.6%] 1
Improvements ✅
(secondary)
-0.6% [-0.6%, -0.6%] 1
All ❌✅ (primary) 0.6% [-0.6%, 2.4%] 7

Max RSS (memory usage)

Results (primary 3.7%, secondary 0.6%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
3.7% [0.7%, 8.0%] 3
Regressions ❌
(secondary)
3.5% [3.5%, 3.5%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.3% [-2.3%, -2.3%] 1
All ❌✅ (primary) 3.7% [0.7%, 8.0%] 3

Cycles

Results (primary 1.2%, secondary 3.7%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
3.2% [2.6%, 3.9%] 2
Regressions ❌
(secondary)
3.7% [3.4%, 3.9%] 2
Improvements ✅
(primary)
-2.7% [-2.7%, -2.7%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.2% [-2.7%, 3.9%] 3

Binary size

Results (primary 0.4%, secondary 0.7%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
1.2% [0.1%, 12.6%] 19
Regressions ❌
(secondary)
6.6% [0.5%, 12.6%] 2
Improvements ✅
(primary)
-0.1% [-0.5%, -0.0%] 27
Improvements ✅
(secondary)
-0.1% [-0.5%, -0.0%] 15
All ❌✅ (primary) 0.4% [-0.5%, 12.6%] 46

Bootstrap: 490.84s -> 494.467s (0.74%)
Artifact size: 406.48 MiB -> 406.50 MiB (0.00%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 9, 2026

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-run-make Area: port run-make Makefiles to rmake.rs llm-assisted An LLM-assisted PR as defined by the LLM policy. Requires ahead-of-time consent by assignee. perf-regression Performance regression. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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.

7 participants