Shaders: walk a predecessor's live-out registers once instead of searching it per register #2520
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2520
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@liandraraiane on GitHub · 2026-11-25 15:13 UTC · original
liandraraiane:perf/shader-translation-profiling→main· +80 −13 · 3 files · 1 commits · openThe 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.
@oni-swr on GitHub · 2026-11-25 15:27 UTC · original
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).
@Marvisak on GitHub · 2026-11-25 18:32 UTC · original
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
@rezioliver-collab on GitHub · 2026-11-25 21:03 UTC · original
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.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.