Skip to content

agx: keep the values a fused break leaves with live - #575

Closed
DjDeveloperr wants to merge 1 commit into
aurora-wipfrom
djdev/agx-fused-break-liveness
Closed

DjDeveloperr wants to merge 1 commit into
aurora-wipfrom
djdev/agx-fused-break-liveness

Conversation

@DjDeveloperr

Copy link
Copy Markdown

Problem

agx_opt_break_if turns if_cmp x, y { break } pop_exec into a break_if_*cmp at the start of the block after the if, but the CFG edge to the break target stays on the emptied then block. The post-RA liveness in agx_opt_register_cache follows CFG edges only, so at the fused break it does not see what the loop exit reads.

A value that the exit reads, and that the loop last reads in the break's own compare, therefore gets a last-use (discard) hint on that compare. On AGX3 a last-use hint releases the register (on G17P a wrong one is known to destroy the value; see the ballot fix in README-g17p-ballot-source-live.md). Every thread that takes the break can then read a released register at the loop exit:

loop {
   x = ...
   break_if (x == 9)      // x: last use here according to the old liveness
   ...                    // x not read again in the loop
}
use(x)                    // the exit reads x

Change

The break target's live-in is taken as live at the break instruction, in the analysis and where the hints are set. A fused break's block is not a predecessor of its target, so when a shader has fused breaks the worklist analysis repeats until nothing changes. The change only removes hints that were wrong. All chips.

Testing

  • New unit test RegisterCache.FusedBreakKeepsTheExitsValue (uniform loop, the fused break's compare operand read at the exit). On aurora-wip 82af196 without this change it fails (brk->src[0].discard is true); with it, it passes.
  • agx_tests: 1200 passed, 1 skipped (host aarch64 release build with drm-shim).
  • Found by an independent review of the G17P divergent last-use change (branch djdev/g17p-dynamic-caching, which carries this commit first). No hardware row yet: this fixes hints on code shapes CTS may not reach under load; the Neo CTS gate will run with the G17P series.

🤖 Generated with Claude Code

agx_opt_break_if moves a conditional break into the block after its if,
but the edge to the break target stays on the emptied then block. Post-RA
liveness therefore did not see what the loop exit reads at the break, and
a value read at the exit but last read in the loop by the break's own
compare got a last-use hint there. On AGX3 a last-use hint releases the
register, so every thread taking the break could then read a released
register at the loop exit.

Take the break target's live-in as live at the break itself. A break's
block is not a predecessor of its target, so with fused breaks the
analysis repeats until nothing changes. Only hints that were wrong go
away.

Found while reviewing the G17P last-use change that follows.

Signed-off-by: Diljit Singh <hey@djdev.me>
@DjDeveloperr

Copy link
Copy Markdown
Author

Local equivalent of the asahi CI job on f28285a (no CI run has started on this PR yet): host aarch64 clang release build with -Dtools=drm-shim -Dbuild-tests=true, meson test --suite asahi: 159 Ok, 0 Fail.

@RyanTheTide

Copy link
Copy Markdown

No blockers.

What I checked at f28285a. agx_opt_break_if runs before agx_opt_register_cache (agx_compile.c:13326, :13346), and of the opcodes that carry a TARGET (agx_opcodes.py:425-440, :673-679) only break_if_*cmp leaves its block without a CFG edge to the target. The other source-reading ones (if/else/while_*cmp) keep their edges, and jmp_exec_* has no sources, so restricting fused_break_target() to the two break_if opcodes is the right scope. The target's live-in is ORed in before postra_liveness_ins() in the analysis and before the source hints in the hint pass. A break_if has no destinations, so the order within the instruction doesn't matter. The extra outer iteration only runs when a fused break exists, and it terminates because the live sets only grow. Shaders without fused breaks get the same single worklist pass as before. The new test reproduces the uniform-loop shape where discard was set on the compare's source.

PR body: the last line is the "Generated with Claude Code" banner rather than Assisted-by: LLM (Claude:Opus 5.5). The commit itself is clean, with a human Signed-off-by and no trailers.

HW row: Neo (G17P), one other AGX3 Mac (J616s) and one M1 or M2 (the pass runs on AGX2 too) on aurora-wip with this commit: dEQP-VK.glsl.loops.*, dEQP-VK.spirv_assembly.instruction.compute.loop* and dEQP-GLES31.functional.shaders.*loop*, with the same pass/fail as the base (0 new failures, 0 GPU faults or recoveries in dmesg); plus a shader-db or fossil run showing the only instruction-level difference is fewer discard hints on break_if sources; 0 new kernel errors.

Assisted-by: LLM (Claude:Opus 5.5)

@DjDeveloperr

Copy link
Copy Markdown
Author

Superseded by #603 (merged into aurora-wip as ce4db96e9234, which carries this fused-break liveness fix as commit 1).

Assisted-by: LLM (Antigravity:Gemini 4 Neon)

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.

2 participants