Skip to content

Propagate copies into statements which overwrite them - #1481

Merged
Frotty merged 1 commit into
masterfrom
ccp-keep-incoming-knowledge
Oct 17, 2026
Merged

Frotty merged 1 commit into
masterfrom
ccp-keep-incoming-knowledge

Conversation

@Frotty

@Frotty Frotty commented Oct 17, 2026

Copy link
Copy Markdown
Member

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) with p known to be a copy of q, sends out the same empty set on every evaluation, so what reached it was never stored and its own read of p was never rewritten to q. The copy p = q then 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) becomes local integer b = next(a). On master the optimised Jass keeps local integer b = a / set b = next(b).
  • LuaTranslationTests.luaInlinerInlinesFunctionsWithMultipleReturns and its sibling encoded the old output (x + 1 / x + 2 left unfolded). The argument now reaches both inlined returns and folds, so they assert v = 41 / v = 42 assigned to the same local.
  • Run locally (Windows): OptimizerTests, LuaBackendAuditTests, LuaTranslationTests, LocalPlayerContextAnalyzerTests, ObservableEffectsTests, DeterministicChecks and the Lua backend classes, 691 tests.

Effect on two large maps (optimised Lua, static luac 5.3 instructions)

before after
map A 497,819 497,512 (-0.06%)
map B 318,761 318,654 (-0.03%)

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.

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).
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-17T13:00:11.276500Z cd28dac PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Frotty
Frotty merged commit 551d428 into master Oct 17, 2026
2 checks passed
@Frotty
Frotty deleted the ccp-keep-incoming-knowledge branch November 25, 2026 08:53
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.

1 participant