Skip to content

Implement a global value numbering MIR optimization#109597

Merged
bors merged 10 commits intorust-lang:masterfrom
cjgillot:gvn
Sep 27, 2023
Merged

Implement a global value numbering MIR optimization#109597
bors merged 10 commits intorust-lang:masterfrom
cjgillot:gvn

Conversation

@cjgillot
Copy link
Contributor

@cjgillot cjgillot commented Mar 25, 2023

The aim of this pass is to avoid repeated computations by reusing past assignments. It is based on an analysis of SSA locals, in order to perform a restricted form of common subexpression elimination.

By opportunity, this pass allows for some simplifications by combining assignments. For instance, this pass could be able to see through projections of aggregates to directly reuse the aggregate field (not in this PR).

We handle references by assigning a different "provenance" index to each Ref/AddressOf rvalue. This ensure that we do not spuriously merge borrows that should not be merged. Meanwhile, we consider all the derefs of an immutable reference to a freeze type to give the same value:

_a = *_b // _b is &Freeze
_c = *_b // replaced by _c = _a

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 merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.