test: the lifted code's flags stay semantics-safe when its optimization level rises #1140

Open
Marcuss2 wants to merge 1 commit from Marcuss2/Longshot:test/split-exactness into main
Contributor

Type: test · Risk: low · Tested on: Linux (game-free checks) · Needs: none

Why

The build-time work makes it cheap to compile more of the lifted code at a higher optimization level (a hot-list build went from 7 min 13 s to 3 min 17 s from scratch once the giant hot functions were split). Nothing in the tree states, or checks, the rule that makes that safe: raising the level may change how fast the guest's C runs, never what it computes. Two flags carry that promise, and one wrong flag voids it silently:

  • -ffp-contract=off: an a*b+c must round twice as the guest does, not once as an FMA;
  • -fno-strict-aliasing: the lifted code puns pointers constantly.

And RX_HOT_OPT/the hot flags are derived by swapping -O1 for -O<n> in the chunk flags, so any -ffast-math shape that ever reached flags() or LIGHT_FLAGS would reach every hot piece with no one noticing.

What changed

A new game-free check, tests/test_lifted_flags_safe.py, locks the flag surface the lifted code is compiled with, so that raising a chunk's or the hot list's optimization level can only make the guest's C run faster, never compute something else. It needs no compiler, no dump and no game: it reads the flags the build itself uses.

  • tests/test_lifted_flags_safe.py: checks the flag surface the lift compiles with.

It calls nx2/build.py's own flags() and LIGHT_FLAGS (no compiler, no dump, no game): the chunk flags at -O1, -O2 and -O3 must carry both safe flags and none of fourteen fast-math/float-licence shapes; the hot pieces' derivation must differ from a chunk's flags by the optimization level alone; and LIGHT_FLAGS must be -mllvm -opt-disable=<names> over a reviewed allowlist of optimization passes, so a semantics option can never be smuggled in as a "pass".

Measurements

Verdict: nothing to measure — a test that locks the flag surface; the evidence is that it passes here and that it fails if any of the above changes. python -I -B tests/run_all.py on Linux: 587 passed, 17 failed, 74 skipped, the 17 also failing on main @ 71b1edd8 (the known environmental set).

Flags and settings

None: the check reads the flags the build already uses and adds no switch.

Testing

Tested: python -I -B tests/test_lifted_flags_safe.py and python -I -B tests/run_all.py on Linux. The check needs no compiler and no dump, so it runs everywhere, including CI-less checkouts.

Not tested: the compiled behaviour itself — that is tests/test_split_giants.py (the split mechanism) plus the new tests/test_opt_level_exactness.py (hot+split and -O1 vs -O2 on the same function), which are separate PRs from other workstreams.

Must be tested: None.

Risks

What could break: a deliberate addition of a pass to LIGHT_PASSES now fails until the allowlist in the test names it — that is the point (a pass list change should be reviewed for float semantics), and the failure message says so.

Turning it off: revert the commit; nothing is shipped to players.

Compatibility: Nothing changes for a player.

Checklist

Everyone

  • One topic.
  • The title is a Conventional Commit (type(scope): description) of the status line's type.
  • Why gives the reason plainly and links the issues that fit (no issue fits; the work comes from the build-time workstream).
  • Measurements has a verdict, or one line saying why there is nothing to measure.
  • Testing names what was tested, what wasn't, and what must still be tested, where and how.
  • Rebased on current main (71b1edd8).
  • python -I -B tests/run_all.py passes (the 17 that fail also fail on main).
  • No game files, dumps, build output or generated files.
  • third_party/ untouched (a new folder with a PROVENANCE.md instead).
  • The license is OK: GPL-3.0-or-later.

When it applies

  • AI assistance recorded with an Assisted-by: trailer.
  • A game-free test added for the rule.
  • Docs updated: none needed (the switches' docs already say the level; the test states the invariant).
**Type:** test · **Risk:** low · **Tested on:** Linux (game-free checks) · **Needs:** none ## Why The build-time work makes it cheap to compile more of the lifted code at a higher optimization level (a hot-list build went from 7 min 13 s to 3 min 17 s from scratch once the giant hot functions were split). Nothing in the tree states, or checks, the rule that makes that safe: **raising the level may change how fast the guest's C runs, never what it computes.** Two flags carry that promise, and one wrong flag voids it silently: - `-ffp-contract=off`: an `a*b+c` must round twice as the guest does, not once as an FMA; - `-fno-strict-aliasing`: the lifted code puns pointers constantly. And `RX_HOT_OPT`/the hot flags are derived by swapping `-O1` for `-O<n>` in the chunk flags, so any `-ffast-math` shape that ever reached `flags()` or `LIGHT_FLAGS` would reach every hot piece with no one noticing. ## What changed A new game-free check, `tests/test_lifted_flags_safe.py`, locks the flag surface the lifted code is compiled with, so that raising a chunk's or the hot list's optimization level can only make the guest's C run faster, never compute something else. It needs no compiler, no dump and no game: it reads the flags the build itself uses. - `tests/test_lifted_flags_safe.py`: checks the flag surface the lift compiles with. It calls `nx2/build.py`'s own `flags()` and `LIGHT_FLAGS` (no compiler, no dump, no game): the chunk flags at `-O1`, `-O2` and `-O3` must carry both safe flags and none of fourteen fast-math/float-licence shapes; the hot pieces' derivation must differ from a chunk's flags **by the optimization level alone**; and `LIGHT_FLAGS` must be `-mllvm -opt-disable=<names>` over a reviewed allowlist of optimization passes, so a semantics option can never be smuggled in as a "pass". ## Measurements **Verdict:** nothing to measure — a test that locks the flag surface; the evidence is that it passes here and that it fails if any of the above changes. `python -I -B tests/run_all.py` on Linux: 587 passed, 17 failed, 74 skipped, the 17 also failing on `main @ 71b1edd8` (the known environmental set). ### Flags and settings None: the check reads the flags the build already uses and adds no switch. ## Testing **Tested:** `python -I -B tests/test_lifted_flags_safe.py` and `python -I -B tests/run_all.py` on Linux. The check needs no compiler and no dump, so it runs everywhere, including CI-less checkouts. **Not tested:** the compiled behaviour itself — that is `tests/test_split_giants.py` (the split mechanism) plus the new `tests/test_opt_level_exactness.py` (hot+split and `-O1` vs `-O2` on the same function), which are separate PRs from other workstreams. **Must be tested:** None. ## Risks **What could break:** a deliberate addition of a pass to `LIGHT_PASSES` now fails until the allowlist in the test names it — that is the point (a pass list change should be reviewed for float semantics), and the failure message says so. **Turning it off:** revert the commit; nothing is shipped to players. **Compatibility:** Nothing changes for a player. ## Checklist ### Everyone - [x] One topic. - [x] The title is a Conventional Commit (`type(scope): description`) of the status line's type. - [x] Why gives the reason plainly and links the issues that fit (no issue fits; the work comes from the build-time workstream). - [x] Measurements has a verdict, or one line saying why there is nothing to measure. - [x] Testing names what was tested, what wasn't, and what must still be tested, where and how. - [x] Rebased on current `main` (71b1edd8). - [x] `python -I -B tests/run_all.py` passes (the 17 that fail also fail on `main`). - [x] No game files, dumps, build output or generated files. - [x] `third_party/` untouched (a new folder with a `PROVENANCE.md` instead). - [x] The license is OK: GPL-3.0-or-later. ### When it applies - [x] AI assistance recorded with an `Assisted-by:` trailer. - [x] A game-free test added for the rule. - [x] Docs updated: none needed (the switches' docs already say the level; the test states the invariant).
test: the lifted code's flags stay semantics-safe when its optimization level rises
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 4s
Website / Website on Cloudflare (pull_request_target) Has been skipped
e6424be83d
A hot-list build now costs what a no-list build does (the giant hot functions are split at compile time), which makes compiling more of the lift at -O2 affordable. What makes that safe is the flag surface: -ffp-contract=off (an a*b+c rounds twice, as the guest does), -fno-strict-aliasing (the lifted code puns pointers), and no -ffast-math shape anywhere, while the hot pieces' flags are derived by swapping -O1 for -O<n> in the chunk flags.

Tests/test_lifted_flags_safe.py checks nx2/build.py's flags() at -O1/-O2/-O3, the hot derivation (the level alone differs), and LIGHT_FLAGS (module passes disabled by name, over a reviewed allowlist). No compiler, no dump.

Assisted-by: DeepSeek Harness
Marcuss2 changed title from WIP: test: the lifted code's flags stay semantics-safe when its optimization level rises to test: the lifted code's flags stay semantics-safe when its optimization level rises 2026-11-16 14:51:43 +00:00
Collaborator

Possibly related, for context:

  • PR #756 WIP: perf(build): optimize shared A64 helpers independently of cold chunks — Open PR changes compile optimization flags for lifted helpers
  • PR #1002 perf(build): lifted chunks with small functions compile without -O1's module passes (LONGSHOT_LIGHT_PASSES, on by default) — Merged PR introduced light optimization-pass flags this test guards
  • PR #1124 perf(scripts): hotlist.py ranks a hot list by the FP helper calls it inlines — Open hot-list work uses higher optimization on lifted code
Possibly related, for context: - PR #756 WIP: perf(build): optimize shared A64 helpers independently of cold chunks — Open PR changes compile optimization flags for lifted helpers - PR #1002 perf(build): lifted chunks with small functions compile without -O1's module passes (LONGSHOT_LIGHT_PASSES, on by default) — Merged PR introduced light optimization-pass flags this test guards - PR #1124 perf(scripts): hotlist.py ranks a hot list by the FP helper calls it inlines — Open hot-list work uses higher optimization on lifted code
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 4s
Website / Website on Cloudflare (pull_request_target) Has been skipped
This pull request doesn't have enough approvals yet. 0 of 1 approvals granted.
Some workflows are waiting to be reviewed.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'test/split-exactness:Marcuss2-test/split-exactness'
git switch 'Marcuss2-test/split-exactness'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!1140
No description provided.