Repository navigation
agx: unswitch affine interior bounds guards and peel rotated 2D stencils - #762
DjDeveloperr wants to merge 4 commits into
Conversation
|
Review at 7110ac2. The split helps, and the two bugs from #758 are fixed for the cases reported there: child remap tables per nested guard (agx_nir_unroll_runtime_loops.c:2940, :2952) keep y's clones out of x's check, and base/stride/limit are now emitted under
No new chip/board compares, params or env switches in this PR; commit trailers are fine. |
0dee159 to
73cad5b
Compare
7110ac2 to
e8c1ebc
Compare
|
Review at e8c1ebc. The PR is rebased onto the new base (73cad5b). I compared the two PR commits with range-diff against 7110ac2. Status of the points from my last review:
Nothing new found in the two commits beyond the above. No chip, board or firmware compares, no params or env switches; commit trailers are fine. Verdict: NITS (item 4). Rows owed at e8c1ebc, by the author: Neo (A18 Pro) and M4 Pro (both G17P), M3 (G15G), M4 (G16G) with dEQP-VK compute + glsl.loops + ssbo.layout and the ABBA numbers, an M5 row, and a robustness run on a device that supports those cases. Also the binary-size table, and a note in this PR when the base branch PR lands, because this head now sits on a rewritten base. |
In agx_nir_opt_flatten_loads, sink matching terminal store_shared instructions out of single-block if/else diamonds into one store_shared(phi(v_then, v_else), saddr) after the if when both arms compute structurally equivalent pure-ALU shared offsets (intersecting access flags, refusing volatile/atomic stores, and capping same_pure_expr work to a 64-node budget to prevent exponential recursion). Also flatten contiguous runs of >= 4 small single-load divergent ifs in the same CF list (separated only by pure ALU or non-volatile store_shared, reset on barriers or other CF nodes, and excluding load_global_constant so UBO reads stay intact for uniform DMA): - Burst threshold (>= 4): isolated 1-3 divergent loads rarely amortize speculative zero-page redirection when an arm is cold, whereas >= 4 consecutive guarded tile loads remove >= 4 serial load-wait CF barriers so global loads issue back-to-back with overlapped latency and let LICM hoist shared tile-address math. - Per-arm cap (MIN2(limit, 24)): admits a 2D/3D index + byte offset + descriptor setup (~8-16 NIR ops) while keeping speculative untaken ALU bounded across a multi-if burst. Reaches all shader stages under (AGX3B || AGX3C) && !emit_agx3d (AGX3B: G15/G16/G17P/G17A; AGX3C: G17G/G17S / M5). AGX2 and G18G are unchanged. Signed-off-by: DjDeveloperr <hey@djdev.me>
For 1D and 2D counted stencil loops whose body is guarded by an affine coordinate bounds check (0 <= base + iv * stride < limit, expressed as a short-circuit diamond phi, bcsel, iand/ior, or unsigned ult/uge), emit an exact zero-overflow interior guard before the loop: bound > 0 && stride >= 0 && base >= 0 && base < limit && umul_high(bound - 1, stride) == 0 && (bound - 1) * stride < (uint32_t)(limit - base) On the interior fast path, folding the bounds guard removes per-tap and per-row branches, exposes invariant address math to LICM, and enables runtime loop unrolling without bloating the cold border fallback (marked partially_unrolled). For 2D nested stencils where both outer and inner loops carry such guards and the inner guard parameters are invariant across the outer loop, a single combined interior_y && interior_x check produces one branchless 2D fast path. Fault safety and SSA dominance: - 2D outer loops with any jump (break/continue/return) outside the loop terminator and inner loop are rejected so iteration 0 is guaranteed to reach the outer guard before any hoisted non-speculatable loads. - emit_interior_check rematerializes bound_out first (verified pure or header-safe invariant), rematerializes base_out/stride_out strictly inside if (bound_out > 0) so top-tested inner loops with trip == 0 never execute in-body load_global_constant instructions, and rematerializes limit_out strictly inside if (stride >= 0 && base >= 0) so short-circuit limit loads only run when iteration 0 has coord(0) >= 0. - Nested guard blocks use cloned child remap tables so clones emitted inside a first check's then-branch never leak into a second sequential check's remap table (preserving SSA dominance in 2D checks with shared in-loop limit defs). Budgets and widenings: - Direct 2D nest cap (<= 120 non-const ops) keeps the simplified interior fast path well below the 256-op splittable_outer limit with headroom for downstream peeling/unrolling; 1D loops use 4..80 body ops (<= 1/4 of the 320-op runtime-unroll cap), and tot >= 4 skips trivial 1-3 op selects. - Whole-function non-const op guardrail (1024 ops, chosen empirically above the largest vision stencil shaders) prevents compounding unswitch duplication across multi-loop megashaders before downstream unrolling. - pure_loop_invariant now permits load_global_constant with ACCESS_CAN_SPECULATE (alongside the already-permitted load_preamble and load_push_constant), which also widens agx_nir_opt_unswitch_invariant_if to speculatable global-constant conditions. Runs under agx3_compute_opts ((AGX3B || AGX3C) && !emit_agx3d), reaching all shader stages on AGX3B (G15/G16/G17P/G17A) and AGX3C without emit_agx3d (G17G/G17S / M5). AGX2 and G18G are unchanged. Signed-off-by: DjDeveloperr <hey@djdev.me>
Extend peel_straight_prefix and unswitch_nested's small-window split to also handle rotated (bottom-tested, offset == step, REL_LT/REL_GT) compact branchless 2D stencil loops with memory loads (not only top-tested 8-bit loops). For exact-trip 3x3 stencils this peels both inner and outer loops completely straight-line; for 4..7-wide inner windows (such as 5x5 depthwise convolutions) it peels 4 straight-line iterations followed by a guarded rotated remainder loop. Thresholds and cleanup: - ops <= 40 in loop_is_compact_branchless_load_loop bounds a 4x peel to <= 160 NIR ops (half of the 320-op runtime-unroll budget). - Outer 3x3 peel preserves the existing <= 64 cap for top-tested nests and uses <= 80 only for rotated nests (which include extra latch step/compare ops before post-peel DCE; 3 * 80 = 240 <= 256 splittable_outer cap). - In peel_straight_prefix, check latch_register before emitting bound_def and restore SSA if bailing out so a false return leaves the shader clean. Runs under agx3_unroll ((AGX3B || AGX3C) && !emit_agx3d), reaching all shader stages on AGX3B (G15/G16/G17P/G17A) and AGX3C without emit_agx3d (G17G/G17S / M5). AGX2 and G18G are unchanged. Signed-off-by: DjDeveloperr <hey@djdev.me>
e8c1ebc to
8f7cee6
Compare
73cad5b to
f9f69ac
Compare
|
Review at 8f7cee6. This is a rebase onto the new #761 head (f9f69ac). range-diff against e8c1ebc shows both PR commits unchanged, so the code points from my last review hold as they were.
Commits have only the human Signed-off-by. No chip/board/fw compares, no params or env switches. Verdict: APPROVE on code. Merge waits on the rows, owed by the author at 8f7cee6: Neo (A18 Pro) and M4 Pro (both G17P), M3 (G15G), M4 (G16G) with dEQP-VK compute + glsl.loops + ssbo.layout and the ABBA numbers on the three touched kernels, an M5 row, and a robustness run on a device that supports those cases. #761 also has to land first, since this PR is stacked on it. |
|
Addressed remaining review items from
Assisted-by: LLM (Antigravity:Gemini 4 Neon) |
Bare-Metal M5 Pro (
|
| CTS Group | Passed | Failed | Not Supported |
|---|---|---|---|
dEQP-VK.compute.pipeline.basic.* (full) |
80/81 | 0 | 1 |
dEQP-VK.glsl.loops.* (full) |
624/624 | 0 | 0 |
dEQP-VK.ssbo.* (489 evenly-sampled of 12,225) |
487/489 | 0 | 2 |
dEQP-VK.ubo.* (491 evenly-sampled of 13,240) |
491/491 | 0 | 0 |
- GPU faults (
dmesg):0(delta = 0).
|
Exact-head verification on Apple M4 (
Single-Threaded CTS (
|
| Suite / Group | Passed | NS | Failed |
|---|---|---|---|
dEQP-VK.compute.pipeline.basic.* |
79/81 |
2 |
0 |
dEQP-VK.glsl.loops.* |
624/624 |
0 |
0 |
dEQP-VK.ssbo.layout.single_basic_type.std430.* |
303/303 |
0 |
0 |
dEQP-VK.ubo.{random,2_level_struct,single_basic} |
118/160 |
42 |
0 |
dEQP-VK.robustness.*robustness2.* (1d comp/v/f) |
36/36 |
0 |
0 |
dEQP-VK.robustness.index_access.* |
31/40 |
9 |
0 |
dEQP-VK.robustness.buffer_access.{v,f,c} + rob2 |
120/156 |
36 |
0 |
| VK unique total (deduplicated) | 1,275/1,364 |
89 |
0 |
dEQP-GLES31.functional.compute.basic.* |
41/41 |
0 |
0 |
dEQP-GLES31.functional.ssbo.layout...std430.* |
121/121 |
0 |
0 |
| GLES31 total | 162/162 |
0 |
0 |
gpubench-vk ABCCBA: #762 R3 (8f7cee6d4c) vs #761 R3 (f9f69ac793) & Cumulative vs #758 R2 (01a39fa4f9)
108/108 unique 6-leg VK CRCs bit-identical PASS (72/72 pairwise), 0 non-cooling dmesg lines. Neutral ±0.3% across non-GB6 compute vs #761 R3, preserving cumulative -1.81% (d=1) / -1.72% (d=4) compute.edge kind=harris GPU win vs #758 R2.
| Workload | d |
Wall (us_per_submit) #761 R3 -> #762 R3 |
Wall delta (#762 vs #761) |
GPU (gpu_us) #761 R3 -> #762 R3 |
GPU delta (#762 vs #761) |
Cumulative GPU (#762 vs #758 R2) |
CRC |
|---|---|---|---|---|---|---|---|
compute.conv2d kind=gaussian,res=1080p |
1 |
1242.24 -> 1246.12 |
+0.31% (0.997×) |
909.38 -> 908.03 |
-0.15% (1.001×) |
-3.35% (1.035×) |
2d55a14d PASS |
compute.conv2d kind=gaussian,res=1080p |
4 |
913.24 -> 915.34 |
+0.23% (0.998×) |
910.08 -> 910.65 |
+0.06% (0.999×) |
+0.06% (0.999×) |
2d55a14d PASS |
compute.conv2d kind=bilateral,res=1080p |
1 |
1746.76 -> 1746.76 |
+0.00% (1.000×) |
1469.73 -> 1469.54 |
-0.01% (1.000×) |
-0.01% (1.000×) |
6cdc0716 PASS |
compute.conv2d kind=bilateral,res=1080p |
4 |
1481.48 -> 1481.48 |
+0.00% (1.000×) |
1472.60 -> 1472.29 |
-0.02% (1.000×) |
-0.02% (1.000×) |
6cdc0716 PASS |
compute.stereo disp=64 |
1 |
19090.91 -> 19090.91 |
+0.00% (1.000×) |
18727.35 -> 18722.00 |
-0.03% (1.000×) |
-0.03% (1.000×) |
c62aadf9 PASS |
compute.stereo disp=64 |
2 |
18181.82 -> 18181.82 |
+0.00% (1.000×) |
18721.82 -> 18724.23 |
+0.01% (1.000×) |
+0.00% (1.000×) |
c62aadf9 PASS |
compute.edge kind=sobel,res=1080p |
1 |
793.65 -> 790.56 |
-0.39% (1.004×) |
513.50 -> 512.06 |
-0.28% (1.003×) |
+0.32% (0.997×) |
27c79e6d PASS |
compute.edge kind=sobel,res=1080p |
4 |
522.20 -> 520.85 |
-0.26% (1.003×) |
518.67 -> 516.90 |
-0.34% (1.003×) |
+0.35% (0.997×) |
27c79e6d PASS |
compute.edge kind=harris,res=1080p |
1 |
954.70 -> 947.89 |
-0.71% (1.007×) |
663.06 -> 662.62 |
-0.07% (1.001×) |
-1.81% (1.018×) |
4cebadfc PASS |
compute.edge kind=harris,res=1080p |
4 |
690.85 -> 690.85 |
+0.00% (1.000×) |
688.53 -> 686.48 |
-0.30% (1.003×) |
-1.72% (1.017×) |
4cebadfc PASS |
compute.uber kind=divergent |
1 |
722.02 -> 723.33 |
+0.18% (0.998×) |
500.02 -> 499.98 |
-0.01% (1.000×) |
+0.00% (1.000×) |
9963f56c PASS |
compute.uber kind=divergent |
4 |
504.41 -> 503.78 |
-0.13% (1.001×) |
502.20 -> 502.19 |
-0.00% (1.000×) |
-0.00% (1.000×) |
9963f56c PASS |
compute.uber kind=uniform |
1 |
411.52 -> 411.95 |
+0.10% (0.999×) |
185.77 -> 185.73 |
-0.02% (1.000×) |
-0.02% (1.000×) |
b022fbaf PASS |
compute.uber kind=uniform |
4 |
190.57 -> 191.21 |
+0.34% (0.997×) |
187.85 -> 187.90 |
+0.02% (1.000×) |
+0.01% (1.000×) |
b022fbaf PASS |
compute.uber kind=ilp |
1 |
610.70 -> 617.29 |
+1.08% (0.989×) |
383.47 -> 383.72 |
+0.07% (0.999×) |
+0.07% (0.999×) |
19f35e30 PASS |
compute.uber kind=ilp |
4 |
389.86 -> 390.24 |
+0.10% (0.999×) |
387.06 -> 387.44 |
+0.10% (0.999×) |
+0.15% (0.999×) |
19f35e30 PASS |
compute.light |
1 |
138.81 -> 133.69 |
-3.69% (1.038×) |
1.58 -> 1.58 |
+0.00% (1.000×) |
-0.03% (1.000×) |
n/a |
compute.light |
4 |
56.00 -> 55.63 |
-0.67% (1.007×) |
1.58 -> 1.58 |
+0.00% (1.000×) |
+0.00% (1.000×) |
n/a |
compute.heavy |
1 |
787.40 -> 788.96 |
+0.20% (0.998×) |
544.31 -> 544.33 |
+0.00% (1.000×) |
-0.00% (1.000×) |
n/a |
compute.heavy |
4 |
547.95 -> 547.95 |
+0.00% (1.000×) |
544.33 -> 544.33 |
+0.00% (1.000×) |
+0.00% (1.000×) |
n/a |
compute.cull_mdi |
1 |
2469.14 -> 2469.14 |
+0.00% (1.000×) |
1273.13 -> 1272.80 |
-0.03% (1.000×) |
+0.37% (0.996×) |
57276de2 PASS |
compute.cull_mdi |
4 |
1753.65 -> 1863.50 |
+6.26% (0.941×) |
1338.41 -> 1361.39 |
+1.72% (0.983×) |
+1.66% (0.984×) |
57276de2 PASS |
gpubench-gl ABCCBA: #762 R3 vs #761 R3
24/24 unique 6-leg GL CRCs PASS (16/16 pairwise), DMESG_DELTA=0, 0 regressions.
| Workload | d |
Wall (us_per_submit) #761 R3 -> #762 R3 |
Wall delta / speedup | GPU (gpu_us) #761 R3 -> #762 R3 |
GPU delta / speedup | CRC |
|---|---|---|---|---|---|---|
compute.uber kind=divergent |
1 |
735.29 -> 738.92 |
+0.49% (0.995×) |
n/a |
n/a |
9963f56c PASS |
compute.uber kind=divergent |
4 |
506.76 -> 507.62 |
+0.17% (0.998×) |
n/a |
n/a |
9963f56c PASS |
compute.uber kind=uniform |
1 |
427.96 -> 430.42 |
+0.57% (0.994×) |
n/a |
n/a |
b022fbaf PASS |
compute.uber kind=uniform |
4 |
192.93 -> 192.31 |
-0.32% (1.003×) |
n/a |
n/a |
b022fbaf PASS |
compute.image |
1 |
453.86 -> 456.63 |
+0.61% (0.994×) |
n/a |
n/a |
n/a |
compute.image |
4 |
192.80 -> 192.55 |
-0.13% (1.001×) |
n/a |
n/a |
n/a |
compute.heavy |
1 |
800.01 -> 800.01 |
+0.00% (1.000×) |
5.10 -> 5.38 |
+5.47% (0.948×) |
n/a |
compute.heavy |
2 |
561.80 -> 561.80 |
+0.00% (1.000×) |
5.25 -> 5.42 |
+3.33% (0.968×) |
n/a |
compute.heavy |
4 |
561.80 -> 561.80 |
+0.00% (1.000×) |
5.35 -> 5.38 |
+0.38% (0.996×) |
n/a |
compute.heavy |
8 |
561.80 -> 561.80 |
+0.00% (1.000×) |
5.29 -> 5.42 |
+2.35% (0.977×) |
n/a |
compute.heavy |
16 |
561.80 -> 566.07 |
+0.76% (0.992×) |
5.38 -> 5.40 |
+0.23% (0.998×) |
n/a |
compute.heavy |
32 |
559.70 -> 559.70 |
+0.00% (1.000×) |
5.42 -> 5.40 |
-0.40% (1.004×) |
n/a |
compute.heavy |
64 |
559.70 -> 559.70 |
+0.00% (1.000×) |
5.40 -> 5.50 |
+1.77% (0.983×) |
n/a |
- Post-flight health:
DMESG_CLEAN_DELTA=0,NON_COOLING_CLEAN_DELTA=0,0GPU faults / kernel bugs (REAL_FULL_BOOT_KERNEL_BUGS=0,SCHED_WHILE_ATOMIC=0,INTERRUPT_RC_WARN=0),IDLE_CLEAN.
Assisted-by: LLM (Gemini:4 Neon)
f9f69ac to
8e2d121
Compare
There was a problem hiding this comment.
Verdict: HOLD at 8f7cee6d
Blockers:
- Targets open non-default base branch
perf/agx3b-flatten-tile-load-bursts(#761, which is itself stacked on#758) and is currentlyCONFLICTINGwith that base.
Checked:
- Checked base branch status (
#761is stillOPEN, targetingperf/agx3b-wave7-blur-fm-deep) and PR mergeability (CONFLICTING). - Deferred full line-by-line review until
#758/#761land (or#762is cleanly rebased onto currentaurora-wip).
Evidence
- Base ref:
perf/agx3b-flatten-tile-load-bursts(mesa#761state:OPEN). - Mergeability:
CONFLICTINGat8f7cee6d.
Use the shared typed access qualifier in both arms of the negative store-sinking fixture. Signed-off-by: DjDeveloperr <hey@djdev.me>
There was a problem hiding this comment.
Verdict: HOLD at 0f664273d308
Blockers:
- Confirm
meson test --suite asahi(includingtest-agx3-vision-optsandtest-flatten-loads) passes at the post-merge head0f664273d308and retarget ontoaurora-wiponce approved parent#761lands. - Pending independent maintainer approval before merge.
Checked:
- Audited merge commit
0f664273d308: resolves the conflict cleanly against approved parent#761(MERGEABLE, only+5/-5insrc/asahi/compiler/test/test-flatten-loads.cpp); zero production code changes relative to8f7cee6d4c11, which already passed dual-generation bare-metal verification on M5 Pro (J714s,G17S B1) and M4 (J773g,G16G B0). - Audited
emit_interior_check()andagx_nir_opt_unswitch_interior_bounds()insrc/asahi/compiler/agx_nir_unroll_runtime_loops.c:- Signed/unsigned overflow check is exact (
bound > 0,stride >= 0,base >= 0,base < limitguaranteeing1 <= span <= INT32_MAX,umul_high(N - 1, stride) == 0, andult(delta, span)proving0 <= base + iv * stride < limitwith no 32-bit signed/unsigned overflow). - Nested
ifblocks (pos_if,chk_if) isolate clonedremaphash tables (pos_remap,limit_remap), preserving SSA dominance across sequential 2D checks and guarding in-bodyload_global_constantrematerialization behindbound > 0/stride >= 0 && base >= 0. - Rotated-loop peeling in
peel_straight_prefix()properly guardsoffset == step,REL_LT/REL_GT, andback_edge_live_outs(), wrapping the tail loop in a continuationifwhenkeep_tailis set.
- Signed/unsigned overflow check is exact (
- Audited
src/asahi/compiler/agx_compile.c(agx_nir_opt_unswitch_interior_boundswired ahead ofagx_nir_unroll_runtime_loops) andagx_nir.h.
Evidence
- Head:
0f664273d3089e69658ba98c4f77812fa82ff7c6(baseperf/agx3b-flatten-tile-load-bursts/#761approved at8e2d1218,MERGEABLE). - No compiler or soundness defects found in
0f664273d308.
|
Merged stack parent #761 at |
There was a problem hiding this comment.
Verdict: MERGE at 0f664273d308
Converts this App's earlier review at the same head to an approval under the 12-01 merge bar (better than before and doesn't break; block only on a shown failure). No code blocker was found in it. The merge gate (a row on one Mac at this head + fast CI) is tracked by pr-readiness, not held here.
Checked: - Audited merge commit 0f664273d308: resolves the conflict cleanly against approved parent #761 (MERGEABLE, only +5/-5 in src/asahi/compiler/test/test-flatten-loads.cpp); zero production code changes relative to 8f7cee6d4c11, which already passed dual-generation bare-metal verification on M5 Pro (J714s, G17S B1) and M4 (J773g, G16G B0).
- Audited
emit_interior_check()andagx_nir_opt_unswitch_interior_bounds()insrc/asahi/compiler/agx_nir_unroll_runtime_loops.c:- Signed/unsigned overflow check is exact (
bound > 0,stride >= 0,base >= 0,base < limitguaranteeing1 <= span <= INT32_MAX,umul_high(N - 1, stride) == 0, andult(delta, span)proving0 <= base + iv * stride < limitwith no 32-bit signed/unsigned overflow). - Nested
ifblocks (pos_if,chk_if) isolate clonedremaphash tables (pos_remap,limit_remap), preserving SSA dominance across sequential 2D checks and guarding in-bodyload_global_constantrematerialization behindbound > 0/stride >= 0 && base >= 0. - Rotated-loop peeling in
peel_straight_prefix()properly guardsoffset == step,REL_LT/REL_GT, andback_edge_live_outs(), wrapping the tail loop in a continuationifwhenkeep_tailis set.
- Signed/unsigned overflow check is exact (
- Audited
src/asahi/compiler/agx_compile.c(agx_nir_opt_unswitch_interior_boundswired ahead ofagx_nir_unroll_runtime_loops) andagx_nir.h.
Follow-ups (not blocking): Merge parent #761 first; follow-ups: post-merge meson asahi, maintainer approval
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
A current-trunk port of the rotated small-window code now reaches the intended path on J615 (M3 Air, G15G C0, saved Edge). The decisive fixture change was passing the 8-bit inner-loop endpoint as a push constant so it is invariant with respect to the outer loop. The original UBO fixture compiled identically in both arms. At local preview The narrow port preserves the already-landed affine-bounds pass from #656. It passed 1,948 compiler tests with one skip, including the nonzero-start fixture, and the separate affine-bounds host test. I have the rotated-only commits ready to check on the #1537 base. |
|
Thanks, Dj, for the rotated stencil peel. I carried that part and your original sign-off into #1539, stacked on #1538. The affine-bounds work is already in #656. I moved the small-window trip checks into their respective branches and reran the corrected stack on J615. The paired GPU time fell 40.46% for 3×3 and 35.52% for 5×5. The 8×8 comparison was within 0.06% in every block, and every process matched the CPU reference. I’ll keep this PR open until the replacement lands. |
|
Thanks, Dj. Your rotated-stencil work landed in #1539 as |
Split out from #758 per review (
#issuecomment-7088943090/#issuecomment-7088946412), stacked on #761 (f9f69ac793a). (Note: this head sits on #761 R3; once #761 lands, this PR will be cleanly rebased onto the merged base if needed.)Summary
agx: unswitch affine interior bounds guards out of stencil loops(4fa09f548ff)0 <= base + iv * stride < limit) out of counted stencil loops using an exact zero-overflow interior predicate (bound > 0 && stride >= 0 && base >= 0 && base < limit && umul_high(bound - 1, stride) == 0 && (bound - 1) * stride < (uint32_t)(limit - base)), producing a branchless interior fast path and marking the cold border fallbackpartially_unrolled.load_global_constantwithACCESS_CAN_SPECULATEinpure_loop_invariant(which also widensagx_nir_opt_unswitch_invariant_if).#758and#762reviews:emit_interior_checkclonesremapinto isolated child hash tables (clone_remap_table) forpos_if(bound > 0) andchk_if(stride >= 0 && base >= 0), preventing in-loop defs cloned insidey's nested branches from leaking intox's check (AGX3VisionOpts.InteriorBounds2DSharedInLoopConstLimit).emit_interior_checkrematerializes onlybound_outbeforeif (bound_out > 0)(requiringheader_safe_invariantfor the 2D inner bound), rematerializesbase_out/stride_outinsideif (bound_out > 0), and rematerializeslimit_outinsideif (stride >= 0 && base >= 0)(AGX3VisionOpts.InteriorBounds2DInLoopConstLoadsTripZero).outer_has_jump_outside()rejecting outer loops containing anybreak/continue/returnoutside the loop terminator and inner loop (AGX3VisionOpts.InteriorBounds2DEarlyOuterBreakTripZero, testing early outer break with poison unmapped addresses).max_fn_instrs = 1024(measured across the 80-SPV Geekbench 6 Vulkan corpus: stencil/vision shaders are73..266pre-unswitch NIR ops —b7279a2573,gauss-h91,gauss-v94,bc7e1ec6101,face-depthwise/720b8163153,stereo266; the largest non-GEMM compute shader07bceaa7is869ops; already-unrolled tiled GEMM megashadersface-gemm-aligned1054andface-gemm-edge1095sit just above1024and are cleanly skipped), 2D outer body<= 120(below the256downstream 3x3 cap), 1D body4..80.imadshl_agxformula ((a * b) + (c << sh)) and 8-bit load masking in the unit-test NIR interpreter.agx: extend small-window 3x3 and 4x peeling to rotated 2D stencil loops(8f7cee6d4c1)peel_small_window_inner_loopandpeel_small_3x3_outer_loopto rotated (bottom_tested) compact branchless 2D stencil loops (<= 40NIR ops -><= 160ops at 4x peel).<= 64outer 3x3 peel cap for top-tested nests and uses<= 80for rotated nests (3 * 80 = 240 <= 256).latch_register(iv_reg) before emittingbound_definpeel_straight_prefixand restores SSA on bail-out.AGX3VisionOpts.Rotated8BitInnerNonZeroStartverifying thef >= 8 && loop_has_8bit_load(inner)arm on rotated 8-bit inner loops with non-zero positive/negative/near-INT32 starts and trips1..10.Reach
Runs under
agx3_compute_opts/agx3_unroll((AGX3B || AGX3C) && !emit_agx3d), reaching all shader stages onAGX3B(G15/G16/G17P/G17A) andAGX3Cwithoutemit_agx3d(G17G/G17S/ M5).AGX2andG18Gare unchanged.Per-Chip Binary-Size & Shader-DB Table (80 GB6 Vulkan SPVs,
#762R38f7cee6d4c1vs#761R3f9f69ac793a)All 4 chips: 80/80 OK, 0 fails, 0 spills, 0 thread-occupancy drops (all 1024 threads); exactly 4/80 shaders touched (3 unique kernels:
bc7e1ec6,b7279a25,face-depthwise/720b8163):bc7e1ec606976e14face-depthwise(720b8163)b7279a25da0866d2G15G(M3)16149 -> 17210 (+6.57%)155248 -> 165394 (+6.54%)183->535i,1752->4852B (2.77x), GPR29->41238->478i,2342->4810B (2.05x), GPR25->33148->377i,1350->3460B (2.56x), GPR39->43G16G(M4)16149 -> 17210 (+6.57%)155248 -> 165394 (+6.54%)183->535i,1752->4852B (2.77x), GPR29->41238->478i,2342->4810B (2.05x), GPR25->33148->377i,1350->3460B (2.56x), GPR39->43G17P(A18 Pro / M4 Pro)16393 -> 17389 (+6.08%)168136 -> 178250 (+6.02%)170->494i,1710->4938B (2.89x), GPR29->29229->462i,2336->4776B (2.04x), GPR25->33147->353i,1364->3370B (2.47x), GPR39->39G17S(M5)13456 -> 14411 (+7.10%)127022 -> 136814 (+7.71%)147->491i,1494->5058B (3.39x), GPR25->39205->405i,1952->4010B (2.05x), GPR23->33135->346i,1272->3384B (2.66x), GPR31->39(Border fallback path: cold border threads execute the exact original un-unrolled loop guarded behind one upfront interior check, adding only the ~6-op upfront predicate on border lanes while interior threads execute the completely branchless peeled 3x3 fast path.)
Verification
-Db_ndebug=false)meson test --suite asahi --suite poly --timeout-multiplier 2: 170/170 OK (0 fails).G17PABCCBA + CTS, plus cross-chip M4/M5/M3 rows) posted in comments below.