Save liveness results for DestinationPropagation#115291
Merged
bors merged 4 commits intorust-lang:masterfrom Jan 18, 2024
Merged
Save liveness results for DestinationPropagation#115291bors merged 4 commits intorust-lang:masterfrom
bors merged 4 commits intorust-lang:masterfrom
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DestinationPropagationneeds to verify that merge candidates do not conflict with each other. This is done by verifying that a local is not live when its counterpart is written to.To get the liveness information, the pass runs
MaybeLiveLocalsdataflow analysis repeatedly, once for each propagation round. This is quite costly, and the main driver for the perf impact onucdanddiesel. (See #115105 (comment))In order to mitigate this cost, this PR proposes to save the result of the analysis into a
SparseIntervalMatrix, and mirror merges of locals into that matrix:liveness(destination) := liveness(destination) union liveness(source).Proof
We denote by$\varphi$ be a mapping of locals, which maps $out'(statement)$ , and the proposed liveness set is $\varphi(out(statement))$ .
'all the quantities of the transformed program. Letsourcetodestination, and is identity otherwise. The exact liveness set after a statement isConsider a statement. Suppose that the output state verifies$out' \subset phi(out)$ . We want to prove that $in' \subset \varphi(in)$ where $in = (out - kill) \cup gen$ , and conclude by induction.
We have 2 cases: either that statement is kept with locals renumbered by$\varphi$ , or it is a tautological assignment and it removed.
If the statement is kept: the gen-set and the kill-set of$statement' = \varphi(statement)$ are $gen' = \varphi(gen)$ and $kill' = \varphi(kill)$ exactly.$\varphi(in)$ is disjoint from $\varphi(kill)$ .$\varphi(out - kill)$ is disjoint from $\varphi(kill)$ , and so $\varphi(out - kill) = \varphi(out) - \varphi(kill)$ . Then $\varphi(in) = (\varphi(out) - \varphi(kill)) \cup \varphi(gen) = (\varphi(out) - kill') \cup gen'$ .$out' \subset \varphi(out) \implies in' \subset \varphi(in)$ .
From soundness requirement 3,
This implies that
We can conclude that
If the statement is removed. As$\varphi(statement)$ is a tautological assignment, we know that $\varphi(gen) = \varphi(kill) = \{ destination \}$ , while $gen' = kill' = \emptyset$ . So $\varphi(in) = \varphi(out) \cup \{ destination \}$ . Then $in' = out' \subset out \subset \varphi(in)$ .
By recursion, we can conclude by that$in' \subset \varphi(in)$ everywhere.
This approximate liveness results is only suboptimal if there are locals that fully disappear from the CFG due to an assignment cycle. These cases are quite unlikely, so we do not bother with them.
This change allows to reduce the perf impact of DestinationPropagation by half on diesel and ucd (#115105 (comment)).
cc @JakobDegen