Shaders: walk a predecessor's live-out registers once instead of searching it per register #2518
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2520"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by liandraraiane on 2026-11-25T15:13:44Z.
The IR's renaming looked up every live register in its predecessor's sorted live-out list by binary search, and again for every phi argument. Both sides are in register order, so one walk along the list
serves them all. The live-out lists are also sized before they are filled.
Change:
crates/victory-shader/src/ir.rs(build_bounded), plus a newir_buildbenchmark.Measurement
cargo bench -p victory-shader --bench ir_build(synthetic programs, no title files or GPU), median of 9, release build:With 8 registers the change is within noise.
Tests
cargo test -p victory-shader --lib: 144 passed, 2 ignored (Ubuntu 24.04).mainfor the benchmark's programs.Not tested
clippy -D warnings, GPU tests).AI use
Claude Code (Claude Sonnet 5.5) profiled, wrote the change and the benchmark, and drafted this description. A person reviewed it and opened the PR.
Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T15:27:43Z.
Verification (Windows 11, WARP/CPU only) — head
be6ae54e88af9a4dea8f94889469a803f0ca8a88Tested: the PR head, which is
origin/main940d32fplus the PR commits (merge-base940d32f; clean merge, fast-forward). Windows 11 Pro 10.0.26200, rustc/cargo 1.98.1.VICTORY_WARP=1andVICTORY_D3D12_WARP=1set so nothing runs on a physical GPU.cargo test -p victory-shader --locked --lib -- --test-threads=1cargo test -p victory-shader --locked --lib ir:: -- --test-threads=1cargo clippy -p victory-shader --all-targets --locked -- -D warningscargo xtask policyasset policy: 183 files okcargo bench -p victory-shader --locked --bench ir_buildThe 2 failures are the WARP baseline:
gathers_at_a_level_match_the_hardwareandpermutes_read_the_lane_named_and_zero_from_lanes_left_outfail identically onorigin/main940d32funder forced WARP (245 passed, 2 failed, 3 ignored there too; this PR adds no tests, so the counts match).Bench (single run each on this machine, so only indicative; the PR's bench file copied onto
origin/mainfor the "before" column), median of 9:Diff read:
members()yields registers in0..REGSorder andRegderivesOrdin the same variant order the oldbinary_search_by_keyrelied on, so the forward walk inlookup_fromis equivalent to the search (a register missing fromoutsleaves the cursor on the next larger entry and returnsNONE, as before). Phis are only pushed in that onemembersloop, so they are in register order when the per-predecessor walk fillsargs; arg order still followsblock.preds. Thedebug_assertwas rewritten to the all-phis form with the same meaning. No findings. Coverage note: the change is only checked by the existing IR/emit tests (no new unit test pins the ordering assumption), which pass.AI use: Claude Code (Claude Sonnet 5.5).
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T18:32:12Z.
Automated triage for the maintainers.
In
build_bounded(crates/victory-shader/src/ir.rs), the per-register binary search in a predecessor's live-out list becomes one forward walk (lookup_from). This applies to single-predecessor blocks and to phi arguments, and the walk restarts for each predecessor. I checked the ordering it relies on:outsis built bymembersin index order, the live-in registers and the phis (pushed only in thatmembersloop) come in the same order, and a missing register returnsNONEas before. Their_buildbench target is synthetic and adds no dependency.The speed-up is measured on synthetic programs only (about 25 % with 128 live registers). The gain on real translations is not measured.
CI:
checkpassing.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by rezioliver-collab on 2026-11-25T21:03:38Z.
On an Apple M1, the full IR dump matched byte for byte between
940d32f(base) andbe6ae54e(PR) for both loop shapes in Wave32 and Wave64, including the order of every phi argument.I built each commit separately on macOS 14.7 with native Rust 1.98.1 (dev profile). I passed the same synthetic instruction words to
ir::buildwith 16 VGPRs at each wave size, then compared the completeProgramdebug dumps directly, preserving block, predecessor and operand order.Both fixtures carry
s2ands9through the loop. For each phi, I also checked that each argument was the value last written to that register by the corresponding predecessor. For example, in block 2 of the two-entry Wave32 case, predecessors[0, 1, 4]supplieds2SSA value IDs[4, 22, 7]in that order on both commits.Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T02:05:05Z.
Review: COMMENTED
Reviewed and verified against
main(63bcca43) on Windows 11 — clean optimization and ready to merge (note: overlaps with #2957 which replacesir.rs's SSA builder):Reg's derivedOrd(S(0..127) < Scc < V(0..255)) matchesindex(reg)andmembers()enumeration order, soouts[p]andblock.phisare strictly ascending and the two-pointerlookup_from(&outs[p], &mut walk, reg)walk cannot miss any live-out entry.Local verification:
cargo test --locked -p victory-shader --lib -- ir::: 9/9 passedcargo bench --locked -p victory-shader --bench ir_build: ran cleanly (2.38ms–29.22msacross 8..128 regs / 500..2000 ifs)cargo clippy --all-targets -- -D warnings+cargo xtask policy(192 files ok): 0 warningsImported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-27T00:50:47Z.
Review: APPROVED
LGTM — verified on Windows:
lookup_from) over sortedouts[p]and register-orderedmembers/block.phisis exact and avoids redundant binary searches and allocationscargo test -p victory-shader --lib ir::passed (9/9)cargo clippy -p victory-shader --all-targets -- -D warnings(includingbenches/ir_build.rs) passed with 0 warningscargo xtask policypassed (192 files ok)Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Pull request closed