Skip to content

Rustup #2668

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

Merged
merged 7 commits into from
Nov 16, 2022
Merged

Rustup #2668

merged 7 commits into from
Nov 16, 2022

Conversation

RalfJung
Copy link
Member

No description provided.

RalfJung and others added 7 commits November 6, 2022 14:17
Add new MIR constant propagation based on dataflow analysis

The current constant propagation in `rustc_mir_transform/src/const_prop.rs` fails to handle many cases that would be expected from a constant propagation optimization. For example:
```rust
let x = if true { 0 } else { 0 };
```
This pull request adds a new constant propagation MIR optimization pass based on the existing dataflow analysis framework. Since most of the analysis is not unique to constant propagation, a generic framework has been extracted. It works on top of the existing framework and could be reused for other optimzations.

Closes #80038. Closes #81605.

## Todo
### Essential
- [x] [Writes to inactive enum variants](rust-lang/rust#101168 (review)). Resolved by rejecting the registration of places with downcast projections for now. Could be improved by flooding other variants if mutable access to a variant is observed.
- [X] Handle [`StatementKind::CopyNonOverlapping`](rust-lang/rust#101168 (comment)). Resolved by flooding the destination.
- [x] Handle `UnsafeCell` / `!Freeze` correctly.
- [X] Overflow propagation of `CheckedBinaryOp`: Decided to not propagate if overflow flag is `true` (`false` will still be propagated)
- [x] More documentation in general.
- [x] Arguments for correctness, documentation of necessary assumptions.
- [x] Better performance, or alternatively, require `-Zmir-opt-level=3` for now.

### Extra
- [x]  Add explicit unreachability, i.e. upgrading the lattice from $\mathbb{P} \to \mathbb{V}$ to $\set{\bot} \cup (\mathbb{P} \to \mathbb{V})$.
- [x] Use storage statements to improve precision.
- [ ] Consider opening issue for duplicate diagnostics: rust-lang/rust#101168 (comment)
- [ ] Flood moved-from places with $\bot$ (requires some changes for places with tracked projections).
- [ ] Add downcast projections back in.
- [ ] [Algebraic simplifications](rust-lang/rust#101168 (comment)) (possibly with a shared API; done by old const prop).
- [ ] Propagation through slices / arrays.
- [ ] Find other optimizations that are done by old `const_prop.rs`, but not by this one.
interpret: support for per-byte provenance

Also factors the provenance map into its own module.

The third commit does the same for the init mask. I can move it in a separate PR if you prefer.

Fixes rust-lang#2181

r? `@oli-obk`
Perform simple scalar replacement of aggregates (SROA) MIR opt

This is a re-open of rust-lang/rust#85796

I copied the debuginfo implementation (first commit) from `@eddyb's` own SROA PR.

This pass replaces plain field accesses by simple locals when possible.
To be eligible, the replaced locals:
- must not be enums or unions;
- must not be used whole;
- must not have their address taken.

The storage and deinit statements are duplicated on each created local.

cc `@tmiasko` who reviewed the former version of this PR.
@RalfJung
Copy link
Member Author

@bors r+

@bors
Copy link
Contributor

bors commented Nov 16, 2022

📌 Commit e48ec37 has been approved by RalfJung

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Nov 16, 2022

⌛ Testing commit e48ec37 with merge 8a84ebb...

@bors
Copy link
Contributor

bors commented Nov 16, 2022

☀️ Test successful - checks-actions
Approved by: RalfJung
Pushing 8a84ebb to master...

1 similar comment
@bors
Copy link
Contributor

bors commented Nov 16, 2022

☀️ Test successful - checks-actions
Approved by: RalfJung
Pushing 8a84ebb to master...

@bors bors merged commit 8a84ebb into rust-lang:master Nov 16, 2022
@RalfJung RalfJung deleted the rustup branch November 16, 2022 09:08
RalfJung pushed a commit to RalfJung/miri that referenced this pull request Nov 17, 2022
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

Successfully merging this pull request may close these issues.

2 participants