Skip to content

Reimplement ConstProp using DataflowConstProp#110719

Closed
cjgillot wants to merge 4 commits intorust-lang:masterfrom
cjgillot:single-const-prop
Closed

Reimplement ConstProp using DataflowConstProp#110719
cjgillot wants to merge 4 commits intorust-lang:masterfrom
cjgillot:single-const-prop

Conversation

@cjgillot
Copy link
Contributor

@cjgillot cjgillot commented Apr 23, 2023

This PR attempts to remove the current ConstProp optimization, and replace it by an implementation based on DataflowConstProp.

The current ConstProp twists the MIR interpreter to do things it is not designed to do, including manipulating generic types. Meanwhile, @jachris has implemented a new DataflowConstProp pass that only uses a few chosen methods for arithmetic.

The main change concerns how propagatable places and operations are tracked. In the current ConstProp, all places are tracked and all operations executed, and we removed wrong or non-propagatable results. This new implementation does the opposite : place tracking is opt-in, and we only propagate supported operations. I believe this approach to be less risky from a soundness point of view.

As a consequence, this new implementation is more restricted. The main limitation is that we stop propagating inside a basic block, and only propagate SSA locals. This makes the implementation simpler, and is more consistent with this "opt-in" logic.

Some operations are added inside this PR (transmutes, algebraic simplifications, Len operations). The handling of statics and non-scalar consts are left to a follow-up PR.

This PR does not remove the const-prop lints (arithmetic overflow and unconditional panic), as I need to design a way to pass more span information around.

There has been quite a few perf runs below. Marking as ready for review, since I removed the massive regressions on diesel/keccak/serde. Kept as waiting-on-author until I bless CI.

Regressed optimizations:

  • array indexing;
  • non-scalar constants;
  • assignment of immutable statics;
  • creating rvalues with non-scalar types;
  • integer-to-pointer transmutes.

Based on #110728, #110732, #110820

Loading
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 perf-regression Performance regression. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.