Skip to content

asahi/compiler: fold proven zext byte offsets and unroll compact guarded loops 8x - #1202

Merged
RyanTheTide merged 4 commits into
aurora-wipfrom
neo/agx3-loop-offset-unroll-20261126
Nov 27, 2026
Merged

RyanTheTide merged 4 commits into
aurora-wipfrom
neo/agx3-loop-offset-unroll-20261126

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 27, 2026 •

Copy link
Copy Markdown

What: Three general, chip-agnostic AGX3 compute loop optimizations: proven zero-extended constant byte-offset folding (u32_add_no_wrap()), compact-prefix 8x guarded loop unrolling with 8-wide guard coalescing and AGX3B register-file retry, and scalar branch-compare LICM.

Tested:

  • MacBook Neo (J700, G17P B1, AGX3B): exact-head ABBA+BAAB (n = 4 per arm) at ac5e53a157bb and 3ea292e40fc1 (#issuecomment-7216513527): Geekbench 6.7.1 Vulkan Particle Physics -20.66% (42.449 → 33.678 ms GPU busy, 0 validation errors across all runs), Feature Matching -0.60%, other 6 workloads neutral; 89,959 VK CTS cases (compute.*, glsl.loops.*, ssbo.layout.random.*, spirv_assembly.instruction.compute.*) 0 Fail; stock.sh PRE/POST=0, 0 GPU faults/AVCs.
  • M4 Mac mini (J773g, G16G B0, AGX3B): PASS at ac5e53a157bb (#issuecomment-7211111651) and exact-head 3ea292e40fc1 (0 Fail).
  • CI & unit tests: Fedora 44 Mesa Asahi CI clean + agx_tests (OptLicm.*, LowerAddressCheckedOffsets.*, GuardChains.*) PASS; Ryan confirmed 336/336 asahi + poly clean; Reviewer A confirmed 215/215 asahi + 5/5 poly on the #1204 merged tree.

Risk: two-way · M3, M4, Neo, M5 — Reverting cleanly disables all three compiler optimizations; checked_offsets remains strictly disabled and the existing half-factor AGX3B register-pressure retry prevents spill/occupancy regressions.

Not yet: J714s (M5 Pro, AGX3C) 89,959-case CTS passed (0 new fails) with GB6 Particle Physics ABBA finishing before comment post; quick J700 spot check on the #1204 merge commit pending.

Details and verification evidence

Summary

Three general, chip-agnostic AGX3 compute loop optimizations that compose cleanly without signed-index assumptions or shader allowlists:

  1. Zero-extended constant byte-offset folding (src/asahi/compiler/agx_nir_lower_address.c)

    • AGX3B natively encodes signed 16-bit byte offsets on device_load / device_store while supporting full 4 GiB storage buffers (UINT32_MAX), so zero-extended indices cannot blindly switch to sign extension.
    • Added u32_add_no_wrap() to prove (uint32_t)rest + c <= UINT32_MAX (when !checked_offsets) from no_unsigned_wrap, exact modular upper bounds (iand, ushr, usub_sat, bcsel guard bounds, narrow u2u32), constant left-shift low zero bits, and enclosing top-tested loop guards (unsigned and non-negative signed IVs), folding c into byte_off while keeping sign_extend = 0.
    • Avoids upstream nir_unsigned_upper_bound()'s unsound max / const * const rule on wrapping non-power-of-two imul, and keeps checked_offsets strictly disabled.
  2. Compact-prefix guarded loop 8x unrolling & 8-wide guard coalescing (src/asahi/compiler/agx_nir_unroll_runtime_loops.c, src/asahi/compiler/agx_nir_opt_guard_chains.c, src/asahi/compiler/agx_compile.c)

    • Count only unconditional top-level loads toward the >4x 16-dword in-flight read budget (loaded_dwords_in_loop), since loads inside nested if bodies are guarded and do not issue concurrently across iterations.
    • Allow guarded loops with a compact unconditional prefix (top_size * f <= max_instrs / 2, size * 4 <= max_instrs) to unroll 8x up to 2 * max_instrs total code size.
    • Raise guard-chain coalescing from 4 to 8 adjacent ifs (MAX_GROUP_IFS = 8, MAX_LIVE_HOISTED_DWORDS = 48) and unwrap fneg(fneg(x)) -> x in try_unwrap_zero_fadd_bias() (IEEE-754 bit-exact).
    • In agx_compile_shader_nir_unrolled(), retry factor 4 before factor 1 on AGX3B when 8x exceeds half the register file (> 96 halves), preventing Dynamic Caching / occupancy regressions.
  3. Scalar branch-compare LICM (src/asahi/compiler/agx_opt_licm.c)

    • Treat IF/ELSE/WHILE/BREAK_IF_{FCMP,ICMP} as plain register uses so loop-invariant uniform copies feeding branch compares hoist to the loop preheader and merge with identical ALU copies.

Hardware Verification — MacBook Neo (J700, Apple A18 Pro T8140, G17P B1, AGX3B)

Exact-commit same-boot ABBA+BAAB (n = 4 per arm: A1 B1 B2 A2 B3 A3 A4 B4) comparing clean aurora-wip (2cb5e1a5cbd9) vs ac5e53a157bb (0 diff lines, stock kernel 7.3.0-41.fc44.aurora.aarch64, stock.sh PRE=0 / POST=0, same boot 65f30b5a-68ce-499f-bf13-617842e616fd, 0 GPU faults / AVCs / recoveries).

Geekbench 6.7.1 Vulkan (0 validation errors, 0 warnings across all 9 runs)

Workload Base 2cb5e1a5cb median (range) Candidate ac5e53a157 median (range) Delta Notes
Particle Physics 42.449 ms (42.448–42.450) 33.678 ms (33.677–33.679) -20.66% (-8.771 ms) WG32 all 9 arms: 290i/69g/1luc -> 405i/87g/0luc (1024t, 0sp), hot loop 68 -> 54 dynamic instrs / 8 particles (-20.6%)
Feature Matching 18.537 ms (18.524–18.636) 18.425 ms (18.408–18.451) -0.60% fm-h 370i->368i, fm-v 554i->551i, 3ba0a508 187i->186i
Background Blur 9.666 ms (9.629–9.686) 9.683 ms (9.672–9.697) +0.18% Flat
Face Detection 11.727 ms (11.723–12.025) 11.712 ms (11.703–11.777) -0.14% Flat (gemm-aligned 320i->319i)
Horizon Detection 22.300 ms (22.280–22.323) 22.271 ms (22.238–22.285) -0.13% Flat
Edge Detection 16.721 ms (16.710–16.736) 16.712 ms (16.703–16.730) -0.06% Flat
Stereo Matching 3.226 ms (3.223–3.226) 3.223 ms (3.222–3.226) -0.08% Flat
Gaussian Blur 11.189 ms (min 11.149, mean 12.10) 12.863 ms (min 11.151, mean 12.28) bimodal 10/9 split Bit-identical shaders (b55b9b9d 503i/85g, ebb331db 465i/81g); diag2 measured 11.178 ms vs 11.213 ms and gpubench-vk gaussian is +0.07%

Diagnostic ablation on the same hardware (A1 -> VarA -> VarB -> A2):

  • Byte-offset folding + branch-compare LICM alone (VarA, 4x unroll, 290i/57g): 42.449 ms -> 39.963 ms (-5.86%).
  • Adding 8x guarded unrolling + 8-wide guard coalescing (VarB, 405i/87g/0luc): 42.449 ms -> 33.677 ms (-20.66%).

gpubench-vk Compute ABBA+BAAB (n = 4 per arm) & Bit-Exact CRCs

Test Depth Base (us) Cand (us) Delta CRC
compute.conv2d bilateral 1080p 1 / 4 2739.4 / 2888.8 2731.1 / 2881.7 -0.30% / -0.25% 6cdc0716 (exact)
compute.conv2d gaussian 1080p 1 / 4 1254.5 / 1401.5 1255.4 / 1402.6 +0.07% / +0.08% 2d55a14d (exact)
compute.edge harris 1080p 1 / 4 1418.1 / 1535.6 1424.0 / 1542.0 +0.42% / +0.42% 4cebadfc (exact)
compute.edge sobel 1080p 1 / 4 719.0 / 822.9 714.6 / 820.6 -0.61% / -0.28% 27c79e6d (exact)
compute.stereo disp=64 1 / 4 24992.2 / 24930.5 24996.3 / 24935.2 +0.02% / +0.02% c62aadf9 (exact)

Correctness & CI

  • Vulkan CTS compute suite on J700 (6,366 cases): 5,874 Passed, 0 Failed, 492 Not supported, 0 Warnings, 0 Waived.
  • ASAHI_MESA_DEBUG=verify: PASS on J700 (compute.edge sobel, CRC 27c79e6d) + 0 failures across offline G17P replay of all 82 GB6 .foz archives (0 spills, 1024 threads on all).
  • Unit tests & Fedora 44 Mesa Asahi CI (./rig/fedora-mesaci.sh ac5e53a157bb): 216/216 PASS (0 fail, 0 skipped, 0 new warnings in touched C files), including new positive and negative controls in test-lower-address-checked-offsets.cpp, test-opt-licm.cpp, and test-guard-chains.cpp.
  • Policy check: .github/aurora/agent-policy.sh pr HEAD -> PR is clean.

…ded loops 8x

Enable three general AGX3 compute loop optimizations that compose cleanly
across compute workloads without chip allowlists or signed-index assumptions:

1. Zero-extended constant byte-offset folding (agx_nir_lower_address):
   AGX3B supports native signed 16-bit byte offsets on device loads and
   stores while exposing full 4 GiB storage buffers (UINT32_MAX), so
   unrolled loop indices cannot blindly sign-extend. Prove that
   (uint32_t)idx + c cannot wrap modulo 2^32 from unsigned range bounds,
   constant left shifts, or enclosing top-tested loop guards (unsigned
   and non-negative signed IVs), and fold c into byte_off while keeping
   sign_extend = 0.

2. Compact-prefix guarded loop 8x unrolling & 8-wide guard coalescing
   (agx_nir_unroll_runtime_loops, agx_nir_opt_guard_chains, agx_compile):
   Count only unconditional top-level loads toward the >4x in-flight read
   budget, allow guarded loops with a compact unconditional prefix
   (top_size * f <= max_instrs / 2, size * 4 <= max_instrs) to unroll 8x
   up to 2x total size, raise guard-chain coalescing to 8 ifs (48 live
   dwords) and unwrap fneg(fneg(x)) -> x in try_unwrap_zero_fadd_bias,
   and retry factor 4 before factor 1 on AGX3B when 8x exceeds half the
   register file (96 halves).

3. Scalar branch-compare LICM (agx_opt_licm):
   Treat IF/ELSE/WHILE/BREAK_IF scalar compares as plain register uses so
   loop-invariant uniform copies feeding branch compares hoist and merge
   with ALU copies in the loop preheader.

Signed-off-by: DjDeveloperr <hey@djdev.me>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners November 27, 2026 05:19
@DjDeveloperr

DjDeveloperr commented Nov 27, 2026 •

Copy link
Copy Markdown
Author

J773g (M4 Mac mini, G16G B0, second generation) at exact head 3ea292e40fc1, against its aurora-wip merge-base 6041c9351efa: PASS, no regression. The compute rows are unchanged on G16G, as at the older head.

Both arms are release Borealis Vulkan overlays built natively on the Mac and loaded from private prefixes through VK_DRIVER_FILES, on the stock kernel 7.3.0-ARCH-m4mainefed1ae3. System Mesa wasn't touched. Each arm's vulkaninfo shows its git SHA.

VK CTS at 2 workers, 89,959 cases: dEQP-VK.compute.* (67,553), glsl.loops.* (624), ssbo.layout.random.* (1,881) and spirv_assembly.instruction.compute.* (19,901). Both arms give 25,518 Pass and 64,441 NotSupported, with 0 cases that differ.

gpubench-vk ABBA (us_per_submit, head/base; lower is better; CRCs equal on all four runs where the row checks them):

row A1 / B1 / B2 / A2 head/base
compute.uber kind=uniform, d1 / d4 396.83 / 396.83 / 396.30 / 396.83 · 187.62 / 187.73 / 187.62 / 187.62 0.999 / 1.000
compute.uber kind=divergent, d1 / d4 710.90 / 712.59 / 712.59 / 710.90 · 483.09 / 482.32 / 482.32 / 482.32 1.002 / 0.999
compute.conv2d kind=gaussian 1080p, d4 551.47 / 550.46 / 551.47 / 549.45 1.001
compute.fp16 mode=alu_mix, d1 / d4 689.66 / 684.93 / 686.50 / 686.50 · 450.45 ×4 0.997 / 1.000
compute.heavy kind=alu, d4 541.52 ×4 1.000
control compute.light d16 35.33 / 35.16 / 34.78 / 35.07 0.993

An earlier ABBA pass in the same hold overlapped a native build on the Mac, so it's discarded; the table is the clean rerun.

GPU health: 0 faults, 0 recoveries and failed 0 errno 0 degraded 0 at start and end. GB6 Particle Physics isn't installed on this Mac, so there's no output check here.


Older head ac5e53a157bb: J773g (M4 Mac mini, G16G B0, second generation) at ac5e53a157bb, against its parent 2cb5e1a5cbd9: PASS, no regression. The compute rows measured here are unchanged on G16G.

Both arms are release Borealis Vulkan overlays, cross-built off the Mac and loaded from private prefixes through VK_DRIVER_FILES, on the stock kernel 7.3.0-ARCH-m4mainefed1ae3. System Mesa wasn't touched. Each arm's vulkaninfo shows its git SHA.

gpubench-vk ABBA (us_per_submit, head/base; lower is better; CRCs equal on all four runs where the row checks them):

row A1 / B1 / B2 / A2 head/base
compute.uber kind=uniform, d1 396.30 / 396.30 / 396.30 / 396.83 0.999
compute.uber kind=uniform, d4 188.09 / 188.21 / 188.09 / 188.56 0.999
compute.uber kind=divergent, d1 710.90 / 709.22 / 712.59 / 712.59 0.999
compute.uber kind=divergent, d4 482.32 / 483.09 / 482.32 / 483.09 1.000
compute.conv2d kind=gaussian 1080p, d4 551.47 / 551.47 / 551.47 / 551.47 1.000
compute.fp16 mode=alu_mix, d1 681.82 / 681.82 / 680.27 / 683.37 0.998
compute.fp16 mode=alu_mix, d4 455.93 / 456.62 / 456.62 / 455.93 1.002
compute.heavy kind=alu, d4 541.52 / 541.52 / 541.52 / 541.52 1.000
control compute.light d16 35.29 / 35.11 / 34.79 / 35.55 0.987

VK CTS at 2 workers, dEQP-VK.compute.pipeline.*: 22,533 cases, 17,924 of them cooperative_matrix. Both arms give 4,329 Pass and 18,204 NotSupported, with 0 cases that differ.

GPU health: 0 faults, 0 recoveries and failed 0 errno 0 degraded 0 at start and end.

GB6 Particle Physics wasn't run on this Mac.

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: FINISH, then merge at ac5e53a157bb8a4f8b442be16d8c97001ba81079

Blockers: none in the code. The branch is DIRTY against aurora-wip. Please merge aurora-wip once (no rebase). The conflict is real, in agx_nir_unroll_runtime_loops.c, which this PR touches:

  • count_unrollable() gained a third argument, and #1183's new caller (count_unrollable(loop, cl.nif) near the runtime-step path) needs NULL.
  • aurora-wip's count_unrollable() now also skips load_const/undef. Keep that skip and add your top_level counter inside the same braces.
  • loaded_dwords() is needed again by loop_is_readonly_with_loads(), which keeps the forward declaration of loop_is_readonly().

My resolution (below) builds and passes the gate. The 8x rows at the current head then no longer cover the merged file.

Checked: I read the whole diff and tried to break u32_add_no_wrap(). I found no input that breaks it:

  • iand with a constant <= K, ushr by s > 0 <= UINT32_MAX >> s, and usub_sat(x, m) <= UINT32_MAX - m are all exact bounds. Shift counts are masked like NIR's, so ushr 32 gives no bound.
  • The bcsel(uge(N,K), N-M, 0) form with 0 < M <= K is exactly what guard_bound() emits for unsigned REL_LT/LE. rest < limit <= UINT32_MAX-M with uc <= M+1 cannot carry. The signed form (INT32_MIN default) mirrors it.
  • The u2u32 narrow and ishl low-zero-bit arguments are right.
  • Loop-guard path: the compare must be the first CF node after the header, the access cannot sit in the header or inside the break if, and rest is the same SSA scalar the header tested in this iteration. For the signed path, non-negativity needs a const init >= 0, a 2-source phi (no continue edges) and max_rest + step <= INT32_MAX, so the IV cannot wrap negative.
  • checked_offsets refuses everything.
  • fneg(fneg(x)) unwrap: bit-exact, and the dominance check is there.
  • LICM branch-compare uses: the register-demand revert still bounds it.
  • The encoding == AGX3B retry in agx_compile_shader_nir_unrolled() keys on the ISA encoding's register file, not on a chip. Acceptable.

Local drm-shim gate (x86 clang, asahi + poly): aurora-wip 65866bbd 336/336, merged 336/336. The new tests are real: with only the PR's three test files on aurora-wip, agx_tests fails 4 of them (OptLicm.HoistsUniformUsedByBranchCompare, LowerAddressCheckedOffsets.ZeroExtendedByteOffsetGuardProof, GuardChains.CoalesceFloatThreshTreeVariantsAndRefusals, GuardChains.CoalescesEightGuardedIfsAndCompactPrefixLoopUnrollsByEight).

Non-blocking: loaded_dwords_in_loop(..., true) now applies to every loop with more than 4 iterations, not only the compact-guarded ones, and the address, LICM and guard-chain changes reach every AGX3 chip. So this needs rows beyond J700.
Row owed: J773g/J713 (G16G) and J714s (M5, AGX3C byte offsets) at the merged head: dEQP-VK.compute.* dEQP-VK.glsl.loops.* dEQP-VK.ssbo.layout.random.* dEQP-VK.spirv_assembly.instruction.compute.*, plus Particle Physics output check.

Evidence
  • base aurora-wip 65866bb: Ok 336 Fail 0
  • aurora-wip + ac5e53a, conflicts resolved as above: Ok 336 Fail 0
  • aurora-wip + only the PR's test-guard-chains.cpp / test-lower-address-checked-offsets.cpp / test-opt-licm.cpp: agx_tests FAIL, 4 FAILED TESTS (listed above)

Resolve two small merge hunks in agx_nir_unroll_runtime_loops.c:
- keep aurora-wip's load_const/undef exclusion inside the instruction
  counter while tracking top_level instructions
- keep both loaded_dwords() and aurora-wip's loop_is_readonly() forward
  declaration.

Signed-off-by: DjDeveloperr <hey@djdev.me>
…e caller

Fix the 1-line compile break after merging aurora-wip's new
count_unrollable() call site in agx_nir_unroll_runtime_loops.c.

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

DjDeveloperr commented Nov 27, 2026 •

Copy link
Copy Markdown
Author

J700 (MacBook Neo, G17P B1) at 3ea292e40fc1, against merge-base 6041c9351efa: PASS. Geekbench 6 Particle Physics is 21 % less GPU time with 0 validation errors, and CTS shows 0 Fail.

  • Setup:

    • Stock kernel 7.3.0-41 with no reboot. One isolated Mesa build per SHA, both from fedora-mbuild with the same options.
    • vulkaninfo showed each build's own driver id (git-6041c9351e and git-3ea292e40f) on the Apple A18 Pro.
    • Shader cache off, MAX_RECOVERIES=0.
  • Geekbench 6.7.1 Vulkan:

    • Offline in a loopback-only network namespace, nothing uploaded.
    • Same boot, 8 runs in the order A1 B1 B2 A2 B3 A3 A4 B4 (ABBA+BAAB).
    • GPU busy time per iteration from the frame anatomy. Values are the median of 4 runs per arm, lower is better.
    workload base ms head ms head vs base spread base / head
    Particle Physics 42.697 33.684 −21.1 % 0.0 % / 6.2 %
    Gaussian Blur 11.966 11.154 −6.8 % 16.2 % / 7.0 %
    Feature Matching 17.897 17.770 −0.7 % 0.4 % / 0.1 %
    Horizon Detection 22.318 22.260 −0.3 % 0.1 % / 0.2 %
    Background Blur 9.500 9.521 +0.2 % 0.5 % / 0.5 %
    Face Detection 11.733 11.736 0.0 % 0.3 % / 0.3 %
    Edge Detection 16.726 16.725 0.0 % 0.2 % / 0.2 %
    Stereo Matching 3.230 3.231 0.0 % 0.1 % / 0.1 %
    • Particle Physics: base runs are 42.697 ×4. The head runs are 35.788, 33.683, 33.684 and 33.685; the first head run is the slower one, and the other three match to the microsecond.
    • Gaussian Blur: the base is bimodal (11.05/11.12 vs 12.81/12.98), so I don't count it.
    • Validation: 0 Geekbench validation errors on all 8 runs.
  • Vulkan CTS on the head, 89,959 cases:

    • all of dEQP-VK.compute.* (67,553: pipeline, shader_object_spirv, shader_object_binary);
    • spirv_assembly.instruction.compute.* (19,901);
    • ssbo.layout.random.* (1,881);
    • glsl.loops.* (624).

    Results: 25,884 Pass, 64,075 NotSupported, 0 Fail, 0 recoveries.

  • Health: 0 GPU faults, 0 driver warnings, 0 AVC denials, 0 failed units and 0 core dumps. stock.sh was identical before and after.


Exact-head addendum (25022fffb995 vs merge-base a97571c6b283, post-#1204 merge): PASS.

  • Setup: Isolated release Borealis VK overlays on MacBook Neo (J700, G17P B1), stock kernel 7.3.0-41.fc44.aurora.aarch64, no reboot, stock.diff=0, state.diff=0.
  • Geekbench 6.7.1 Vulkan ABBA+BAAB (4× base + 4× head, 0 validation errors on all 8 runs):
    • Particle Physics: 42.698 -> 33.684 ms (-21.11%, 0.0% spread: base 42.697–42.698, head 33.684–33.685).
    • Other deterministic workloads flat (Background Blur -0.12%, Face Detection +0.02%, Horizon Detection -0.13%, Edge Detection +0.09%, Feature Matching -0.41%, Stereo Matching -0.02%; Gaussian Blur shows the same bimodal ~11.0 vs ~12.5 ms variance on both arms).
  • Compute+ VK CTS on exact head 25022fffb995: 89,959 cases (25,884 Pass, 64,075 NotSupported, 0 Fail).
  • Health: 0 GPU faults/recoveries, 0 AVCs, 0 core dumps.

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: FINISH, then merge at 3ea292e40fc136a55af00d6440bdee1369efdd5c

Blockers: none in the code. One row is still owed before merge: J714s (M5 Pro, AGX3C byte offsets) at this head. Run dEQP-VK.compute.*, dEQP-VK.glsl.loops.*, dEQP-VK.ssbo.layout.random.*, dEQP-VK.spirv_assembly.instruction.compute.* and the Particle Physics output check. The M5 is the only AGX3C chip in the set, and the byte-offset fold changes its address path. There was no M5 row at the older head either, and the delta since then is a real conflict merge, so no earlier row carries over. Merge once that row is on the PR.

Checked: I read the delta ac5e53a157bb..3ea292e40fc1: the merge of aurora-wip 6041c9351efa plus the one-line follow-up. The resolution in agx_nir_unroll_runtime_loops.c is the one I asked for:

  • count_unrollable() keeps aurora-wip's load_const/undef skip and counts top_level inside the same braces.
  • #1183's peel_straight_prefix() caller passes NULL for top_level_out.
  • loaded_dwords() and the loop_is_readonly() forward declaration stay for loop_is_readonly_with_loads().

Comparing the PR's net diff against its merge-base before and after shows only those hunks; the rest of the PR diff is unchanged. aurora-wip has moved 53 commits past 6041c935, and the head still merges into the current tip 5ab97d0f2c60 without conflicts. Rows at this head: J773g (G16G) shows no regression with 0 CTS differences across 89,959 cases. J700 (G17P) shows Particle Physics at -21 % GPU time, 0 validation errors, and 0 Fail across 89,959 CTS cases.

Evidence

Local drm-shim gate (x86 clang, release + asserts, meson test --suite asahi --suite poly):

  • aurora-wip 5ab97d0f2c60: Ok 338, Fail 0
  • aurora-wip 5ab97d0f2c60 + 3ea292e40fc1 (clean merge): Ok 338, Fail 0

Net-diff comparison: git diff 2cb5e1a5cbd9 ac5e53a157bb vs git diff 6041c9351efa 3ea292e40fc1. Only the count_unrollable() braces, the NULL argument and the forward-declaration move differ.

@RyanTheTide

Copy link
Copy Markdown

Merge order changed: #1204 merged first (a97571c), because it was ready first: J516s row at its head (posted 11:31Z), plus J700 and J714s. This PR now conflicts with aurora-wip in src/asahi/compiler/agx_nir_unroll_runtime_loops.c (the choose_factor() clash flagged in the 3ea292e review).

To finish:

  1. Merge aurora-wip a97571c6 into the branch. The branch doesn't allow maintainer edits, so we can't push the merge.
  2. Rows at the new head: J773g and J700 again, plus the J714s M5 row that was already owed.

The approval at 3ea292e covers the code. We'll do a resolution review of the merge commit and gate it as soon as it's pushed.

…20261126

Resolve choose_factor() conflict against #1204 (a97571c) in
agx_nir_unroll_runtime_loops.c by keeping #1204's max_trips() bound and
ending with #1202's budget check. Also brace the EXPECT_EQ in
test-opt-licm.cpp to silence -Wdangling-else.

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

Copy link
Copy Markdown
Author

Verdict at 25022fffb995: ready

Blockers

None.

Checked

Nit (not blocking): two of the new proof rules have no test that fails when they're made unsound: dropping M <= K in the bcsel bound, and dropping c < 2^s in the ishl rule. One negative control each would hold them, e.g. ishl(x, 3) + 8 and bcsel(uge(n, 4), n - 8, 0) + c must keep the add.

Still owed before merge:

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: FINISH, then merge at 25022fffb995d4217fe6396f69df9b4ff023fe1c

Blockers: none in the code. Rows are owed at this head: J773g (G16G) and J700 (G17P), plus the J714s (M5) row that was already owed. The merge hand-resolves a conflict in agx_nir_unroll_runtime_loops.c, a file this PR touches, and the factor a loop gets now depends on #1204's trip bound too. So the rows at 3ea292e40fc1 don't carry over.

Checked: this is a resolution review of the aurora-wip merge 25022fffb995 (git show --remerge-diff).

  • choose_factor(). The resolution is the union of both sides, in this order:

    1. #1202's compact_guarded_prefix budget (2x max_instrs only when 4x fits and the unconditional prefix stays within half);
    2. the halving to the budget;
    3. the 16-dword in-flight cap above 4x;
    4. #1204's max_trips() cap (2 * f > trips halves; f < 2 returns 0);
    5. the final check against budget, not max_instrs.

    The trip cap can only lower f, so the 2x budget never grants more than #1202 already allowed, and a constant-trip loop can't be unrolled past its trip count.

  • Runtime step and step 0. In struct counted_loop, step == 0 means a loop-invariant runtime step (step_def). max_trips() returns UINT64_MAX for step <= 0, offset_is_step, a non-constant bound or REL_* other than LT/LE, before it divides by cl->step. So runtime-step loops get no trip cap and keep this PR's factor, and there is no division by zero. M5RuntimeLoops.RuntimeStepReductionUnrolls (runtime step), M5RuntimeLoops.TripBoundLimitsFactor (#1204's cap) and GuardChains.CoalescesEightGuardedIfsAndCompactPrefixLoopUnrollsByEight (this PR's 8x budget with a runtime bound) all pass in the merged tree.

  • test-opt-licm.cpp:369. Braces only: they fix the -Wdangling-else warning, and the test is unchanged.

  • Merge. No other hunk in the merge differs from a plain merge. The head merges cleanly into aurora-wip fffdc5c7c634.

  • Nit (non-blocking, also in your own review): the M <= K part of the bcsel bound and c < 2^s in the ishl rule have no negative test.

Evidence

Local drm-shim gate (x86 clang, release + asserts, meson test --suite asahi --suite poly):

  • aurora-wip fffdc5c7c634: Ok 338, Fail 0
  • aurora-wip fffdc5c7c634 + 25022fffb995 (clean merge, tree bd93d97bac70): Ok 338, Fail 0

@DjDeveloperr

Copy link
Copy Markdown
Author

J714s (MacBook Pro 14" M5 Pro, G17S B1, AGX3C) row at 3ea292e40fc1 against its merge base 6041c9351efa: PASS. Particle Physics is 20.6 % faster with 0 validation messages, and no new CTS failures.

Setup:

  • Isolated Mesa kits built on the M5 from one warm tree:
    • A = 6041c9351efa, the merge base with aurora-wip;
    • B = 3ea292e40fc1, this PR's head.
  • driverInfo reads git-6041c9351e / git-3ea292e40f.
  • The default kernel 7.3.0-m5-cdirect16, headless. The system Mesa and the kernel were not changed.
  • MESA_SHADER_CACHE_DISABLE=1.

1. Vulkan CTS (deqp-vk 1.4.7.1, 16 jobs): compute.*, glsl.loops.*, ssbo.layout.random.* and spirv_assembly.instruction.compute.* in full, 89,959 cases on B.

  • Result: 27,744 Pass, 62,186 NotSupported, 28 Fail, 1 Flake.
  • The 28 Fail are all spirv_assembly.instruction.compute.untyped_pointers.vulkan_memory_model.cooperative_matrix.*.store.*. The base fails the same 28 cases: B's non-pass cases were run again on both kits, and both lists are identical. They aren't from this PR.
  • The Flake (compute.pipeline.cooperative_matrix.khr_a.subgroupscope.spacetodepth.float16_float16.buffer.rowmajor.tensorlayout) passed on retry.

2. Geekbench 6.7.1 Vulkan:

  • How it was run: offline (no network; the result upload at the end fails by design), LimitMEMLOCK 512 MiB for external host memory. Order A B B A, one session.
  • Validation: 0 validation messages on all 4 runs, all 8 workloads run.
  • Results: median per-iteration time of each workload (20 iterations):
Workload A (ms, runs) B (ms, runs) Δ
Particle Physics 8.586, 8.580 6.812, 6.813 −20.6 %
Feature Matching 6.309, 6.289 6.410, 6.360 +1.4 %
Gaussian Blur 2.715, 2.730 2.739, 2.747 +0.8 %
Background Blur 2.582, 2.578 2.592, 2.589 +0.4 %
Face Detection 3.244, 3.264 3.259, 3.268 +0.3 %
Edge Detection 3.727, 3.713 3.720, 3.733 +0.2 %
Horizon Detection 5.313, 5.585 5.605, 5.595 +0.2 % against A's second run (A's first run, 5.313, is the outlier)
Stereo Matching 0.702, 0.701 0.698, 0.701 −0.3 %
  • Particle Physics: the gain matches the J700 row, and the run-to-run spread is ±0.01 ms on both arms.
  • Feature Matching: +1.4 % here (A 6.289–6.309, B 6.360–6.410 ms), against −0.6 % on the J700.

3. Kernel log: 0 GPU faults, 0 WARN and 0 error lines in both slots. The GPU was online with 0 crashed and 0 quarantined owners before and after.

@DjDeveloperr

Copy link
Copy Markdown
Author

Verification row — MacBook Pro M5 Pro (J714s, G17S B1, AGX3C), exact head 25022fffb995

Follow-up to the earlier 3ea292e40fc1 row, re-verified on exact head 25022fffb995d4217fe6396f69df9b4ff023fe1c vs merge base a97571c6b2839d527d7682d75ebc3c934d56a8b8 (aurora-wip).

  • Environment: MacBook Pro M5 Pro (J714s, G17S B1), kernel 7.3.0-m5-cdirect16, isolated Mesa kits loaded via VK_DRIVER_FILES (no kernel or ESP changes).
  • Vulkan CTS (89,959 cases on head 25022fffb995, 16 jobs): 27,745 Pass / 62,186 NotSupported / 28 Fail — 0 regressions.
    • dEQP-VK.compute.* (67,553): 15,214 Pass, 52,339 Skip, 0 Fail
    • dEQP-VK.glsl.loops.* (624): 624 Pass, 0 Fail
    • dEQP-VK.ssbo.layout.random.* (1,881): 1,875 Pass, 6 Skip, 0 Fail
    • dEQP-VK.spirv_assembly.instruction.compute.* (19,901): 10,032 Pass, 9,841 Skip, 28 Fail
    • All 28 failures (spirv_assembly.instruction.compute.untyped_pointers.vulkan_memory_model.cooperative_matrix.*.store.*) re-ran and failed identically (28/28) on merge base a97571c6b283.
  • Geekbench 6.7.1 Vulkan (A B B A, offline, validation_msgs=0 on all 4 runs):
    • Particle Physics: 8.576 / 8.565 ms (base mean 8.571 ms) → 6.846 / 6.812 ms (head mean 6.829 ms, -20.3%)
    • Other 7 workloads (Background Blur, Face Detection, Horizon Detection, Edge Detection, Gaussian Blur, Feature Matching, Stereo Matching): within ±1.0% of base (Feature Matching 6.302 → 6.352 ms, +0.8%).
  • Health: 0 GPU faults, 0 kernel errors, 0 WARNs, crashed=0, quarantined=0, GPU live at start and end.

@RyanTheTide

Copy link
Copy Markdown

25022fffb995 J700 (Neo, Apple A18 Pro / G17P B1, 7.3.0-aurora-fleet89) + J615 (M3 Air, Apple M3 / G15G C0, 7.3.0-aurora-fleet90-airs2) PASS: Borealis exact-head overlay ICD (VK_DRIVER_FILES, -Dbuildtype=release -Db_ndebug=false, stock /usr/lib64/libvulkan_asahi.so verified byte-identical before/after); meson test --suite asahi 215/215 PASS; deqp-vk on J700 2,239 PASS / 0 FAIL (api.smoke.* 8/8, glsl.loops.* 1,5 138/138, ssbo.layout.random.* 1,5 400/400, compute.pipeline.basic.* 80/81, spirv_assembly.instruction.compute.* 1,5 1613/1979) and on J615 2,157 PASS / 0 FAIL (api.smoke.* 8/8, glsl.loops.* 1,5 138/138, ssbo.layout.random.* 1,5 400/400, compute.pipeline.basic.* 80/81, spirv_assembly.instruction.compute.* 1,5 1531/1979); 0 GPU faults/recoveries, Enforcing, 0 failed units, 0 new AVC.

@RyanTheTide
RyanTheTide merged commit 0b9fc69 into aurora-wip Nov 27, 2026
@RyanTheTide
RyanTheTide deleted the neo/agx3-loop-offset-unroll-20261126 branch November 27, 2026 14:36
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