Repository navigation
Propagate copies into statements which overwrite them - #1481
Merged
Merged
Conversation
Constant and copy propagation kept what reaches a statement only when what goes out of it changed. A statement which drops everything that reaches it, such as p = f(p) with p known to be a copy of q, sends out the same nothing on every evaluation, so what reached it was never kept and its own read of p was never rewritten to q. The inliner makes this shape around natives with a nil guard once the local merger has given argument and result one variable. What reaches a statement is now kept on every evaluation; what goes out and the worklist are unchanged. luaInlinerInlinesFunctionsWithMultipleReturns and its sibling now see the argument folded into both inlined returns (v = 41 / v = 42).
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Constant and copy propagation kept the knowledge that reaches a statement only when the knowledge going out of it changed. A statement which drops everything that reaches it, for example
p = f(p)withpknown to be a copy ofq, sends out the same empty set on every evaluation, so what reached it was never stored and its own read ofpwas never rewritten toq. The copyp = qthen stays.The inliner produces this shape around natives with a nil guard (
p = q; if p == nil then p = nil else p = Native(p) end) once the local merger has given argument and result one variable.The fix stores what reaches a statement on every evaluation. What goes out of each statement, and when successors are re-queued, are unchanged; the rewrite now uses the knowledge from the statement's last evaluation, which is the fixpoint.
Tests
OptimizerTests.copyPropagationIntoAStatementWhichOverwritesTheCopy:var b = a; b = next(b)becomeslocal integer b = next(a). On master the optimised Jass keepslocal integer b = a/set b = next(b).LuaTranslationTests.luaInlinerInlinesFunctionsWithMultipleReturnsand its sibling encoded the old output (x + 1/x + 2left unfolded). The argument now reaches both inlined returns and folds, so they assertv = 41/v = 42assigned to the same local.OptimizerTests,LuaBackendAuditTests,LuaTranslationTests,LocalPlayerContextAnalyzerTests,ObservableEffectsTests,DeterministicChecksand the Lua backend classes, 691 tests.Effect on two large maps (optimised Lua, static luac 5.3 instructions)
Small, because most surviving copies in real maps are held back by a different rule: copy propagation refuses any value the local-player analysis marks as dependent. That is a separate change with its own PR.