Repository navigation
rdna2spirv: the heap base is built once in the entry block, not at every memory access (SHADER-822, -1.9% SPIR-V) - #4633
Conversation
…ery memory access Gen.host_addr loaded push-constant words 1 and 2, widened them, shifted and or-ed them at every s_load, s_buffer_load, buffer and global access: six instructions each time for a value that can't change during the invocation. %main's entry block now builds %heap_base once (HEAP_BASE_ENTRY, next to the access chains it loads through), and host_addr adds to it. The entry block dominates every block of %main, and host_addr is only called for %main's body (the access chains it loads through were already local to %main). The interpreters in test_scalar_mem_smem.py and test_global_mem_offset.py run the body alone, so they read %heap_base as the heap base they set, in place of the two loads they modelled. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… base once Four accesses (two s_load, an s_buffer_load and a buffer_load) load each push-constant word of the base once, add to %heap_base at least four times, and define it in %main's entry block. main's translator loads the words four times, and the test fails there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Verified PR #4633 on Windows 11 (25H2
Looked over AI-assisted (Gemini, Antigravity). |
Kam471
left a comment
There was a problem hiding this comment.
Ran this at 68cbe16f on Windows 11.
tests/semantic/test_heap_base_once.py-> 1 test, OK;test_global_mem_offset.py11 OK;test_scalar_mem_smem.py41 OK;git diff --checkclean.tests/test_translate.pywithLLVM_MCset -> 581 passed, 4 skipped (52 s).- GPU with this translator, RTX 5070 Ti:
--filter cs_store1/1,--filter cs_smem4/4 (cs_smem_bounds,cs_smem_sload_neg,cs_smem_soffset_imm,cs_smem_stride_alignexact),--filter cs_global1/1 (cs_global_neg_offset).
The entry block of %main builds %heap_base once from push-constant dwords 1–2 and host_addr adds to it; the entry block dominates every use, and the push constants are invariant per invocation. The structural test pins one load pair and at least four OpIAdd %ulong %heap_base uses, so the per-access rebuild cannot come back silently. No blocking issue.
|
Tested GPU suite, Dell Latitude 5501 (Linux Mint 22.3), test programs built from
SHADER-774's module (the largest compute module, ~89k RDNA2 instructions, from my own copy; sizes only): this PR's head against
No game data beyond counts. Tested and written by Claude (Claude Code), posting from @theswiss24's account. |
|
Verified on Linux: merges cleanly into current main; the hoist is gated by gen.uses_heap, the base is defined in the %main entry block (dominance holds), and the new test_heap_base_once passes here on the merged tree (re-run) — one base chain, >=4 uses, on a synthetic module. Everything runnable is green: the adapted semantic suites, the translator-use guard, test_pc_tail_ubo (8 passed, pytest) and the full test_translate suite (596 passed). The -1.9% corpus figure cannot be reproduced locally, but the instruction-count claim is visible in the emitted module. CI pending. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run). |
New SHADER item. Claim: #4571 (comment)
Gen.host_addrturns an Xbox GPU address into a host one by adding the heap base, push-constant words 1 and 2 (or%pc_tail's with--pc-tail-ubo). At every memory access it rebuilt that base from scratch: twoOpLoads, twoOpUConverts, a shift and an or. That happened for everys_load_*,s_buffer_load_*,buffer_*andglobal_*access. The value can't change during the invocation, so%main's entry block now builds%heap_baseonce, and each access is a singleOpIAddto it.Commits
rdna2spirv:HEAP_BASE_ENTRYbuilds%heap_baseright after the two access chains it loads through, andhost_addradds to it.%main, so every use is valid SSA.host_addris only reached from%main's body: the access chains%ud_base_lo_p/%ud_base_hi_pit loaded through were already local to%main.test_scalar_mem_smem.pyandtest_global_mem_offset.pyrun the body alone. They now read%heap_baseas the heap base they set, instead of modelling the two loads.tests/semantic/test_heap_base_once.py: a module with four accesses (twos_load, ans_buffer_loadand abuffer_load) checks three things:%heap_baseat least four times;%heap_basein the entry block.mainloads the words four times, and the test fails there.Measured on my own 1.0.2.1 corpus (shard 0/40, counts only)
maind0835dd9spirv-valtools/rdna2spirv.pyis the same at03b09a08andd0835dd9, so the baseline holds.mainalready has:test_loop_ballot_barrier(5),test_cmp_class_f64(2), andtest_mutations' legacy anchor (2, fixed by tests/semantic: re-anchor the v_mul_legacy_f32 mutation after the flush change #3883).tests/test_pc_tail_ubo.pypasses.scripts/run_gpu_tests.pyon an RTX 3060 (NVIDIA 610.88): 164/210 passed, 46 skipped, the same asmain. The rest oftests/gives the same 8 failures asmain, each with an open fix.Independent of #4345, #4391, #4477, #4510, and of @SweatierKey's #4473/#4518, which forward register values and
%active, not push constants. Each one removes a different redundancy. AI-assisted (Claude Code).🤖 Generated with Claude Code