Repository navigation
Conversation
|
Some changes occurred to constck cc @fee1-dead
cc @bjorn3 This PR changes MIR cc @oli-obk, @RalfJung, @JakobDegen, @vakaras
cc @rust-lang/clippy Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt Some changes occurred to the CTFE machinery This PR changes rustc_public cc @oli-obk, @celinval, @ouz-a, @makai410 Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri |
|
LLM disclosure: this PR is in large part the result of an LLM-assisted audit of all existing MIR transformations against the new MIR semantics as implemented in Miri in #163340. LLMs were also used to generate the boilerplate for the MIR tests, but each test was manually reviewed and adjusted before committing. |
|
We started with a single pull request with 65 files changed, and now ended up with multiple "smaller" pull requests, where the first one has 115 files changed. This is not exactly what I expected. Could you move some parts to smaller pull requests still. For example parts of "Fix missing ZST initialization in MIR passes" which don't depend on |
|
I'm currently working to make none of the changes in this PR depend on The main concern is that this means restricting I will then move all of the ZST-related changes to a separate PR since they no longer depend on the flag. |
a4912a3 to
43c741c
Compare
|
I've moved the ZST-related changes to #163359.
Most of the difference come from this preparation work which adjusts the rest of the compiler to work with the new semantics, which ends up touching a lot of tests. The actual compiler code changes are not that big. |
This comment has been minimized.
This comment has been minimized.
43c741c to
7d28b47
Compare
|
I moved the MIR validity changes to the Miri PR. |
| pub(crate) fn remove_unused_storage_annotations<'tcx>(&self, body: &mut Body<'tcx>) { | ||
| for data in body.basic_blocks.as_mut_preserves_cfg() { | ||
| // Remove unnecessary StorageLive and StorageDead annotations. | ||
| // Remove storage statements for unused locals. | ||
| for statement in data.statements.iter_mut() { | ||
| let keep_statement = match &statement.kind { | ||
| StatementKind::StorageLive(local) | StatementKind::StorageDead(local) => { | ||
| self.locals.contains(*local) | ||
| } | ||
| StatementKind::StorageLive(local) | ||
| | StatementKind::StorageDead(local) | ||
| | StatementKind::StorageAlloc(local) => self.locals.contains(*local), |
There was a problem hiding this comment.
Please add a test case.
There was a problem hiding this comment.
Which test exercises this? I would expect changes in tests/mir-opt/simplify_locals*
|
I addressed all the review comments, as well as #163388. I also noticed that the handling of the destination place in inlining was incorrect: the destination place must become allocated-but-uninitialized if the call unwinds. This means we always need to use |
This comment has been minimized.
This comment has been minimized.
|
Given that the semantics have been overhauled, we should probably ensure t-opsem had a chance to look at the new semantics. In particular this PR seems to already alter MIR semantics by adding a new statement (StorageAlloc)?
|
This comment has been minimized.
This comment has been minimized.
b366400 to
d39204c
Compare
dc6558c to
8fcfe1f
Compare
|
@rustbot ready |
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…try> MIR move elimination [1/6]: MIR preparation
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (d54f68c): 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 @bors rollup=never rustc-perf Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 2.4%, secondary 0.4%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 3.4%, secondary -1.3%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 0.2%, secondary 0.7%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 458.8s -> 459.974s (0.26%) |
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…try> MIR move elimination [1/6]: MIR preparation
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (e6dcdf1): 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 @bors rollup=never rustc-perf Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 1.3%, secondary 1.9%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary -1.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary -0.3%, secondary 0.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 458.8s -> 460.504s (0.37%) |
|
These regressions seem insignificant. |
| // CHECK-NEXT: _0 = const (); | ||
| // CHECK-NEXT: return; | ||
| // CHECK-NOT: -> | ||
| // CHECK: return; |
There was a problem hiding this comment.
It should be possible to revert those changes after DSE was taught about StorageAlloc.
| // StorageAlloc requires the local to be live. | ||
| if !context.is_use() && context != PlaceContext::NonUse(NonUseContext::StorageAlloc) { |
There was a problem hiding this comment.
Whatever strategy we end up in copy propagation (see other comments), GVN probably needs an analogous adjustments.
| } | ||
| } | ||
|
|
||
| // Allocating a field of the destination must also allocate its uninitialized sibling. |
There was a problem hiding this comment.
| // Allocating a field of the destination must also allocate its uninitialized sibling. | |
| // Initializing a field of the destination allocates the destination local. |
| unsafe fn slice_in_place(ptr: *mut [char]) { | ||
| // CHECK-LABEL: fn slice_in_place(_1: *mut [char]) | ||
| // CHECK: bb0: { | ||
| // CHECK-NEXT: _0 = const (); | ||
| // CHECK-NEXT: return; | ||
| // CHECK-NOT: -> | ||
| // CHECK: return; | ||
| // CHECK-NEXT: } | ||
| std::ptr::drop_in_place(ptr) |
There was a problem hiding this comment.
Is the idea that there are no edges, and so call must have been inlined?
I would prefer to add checks for extra StorageAllocs.
|
|
||
| use std::intrinsics::mir::*; | ||
|
|
||
| // Ensure the copy source's storage lifetime covers the redirected StorageAlloc. |
There was a problem hiding this comment.
What about a strategy that removes StorageAllocs instead?
I would expect that SSA form (along with changes that replace moves with copies) ensures that all StorageAllocs are redundant.
View all comments
This PR contains preparatory work for supporting the new MIR semantics from rust-lang/rfcs#3943.
-Zmir-move-eliminationwhich both opts-in to the new semantics and enables the new optimization pass.StorageAllocMIR statement. This is used by the MIR inliner when it needs to borrow a destination place that hasn't been initialized.r? tmiasko