Recompiler: upper lanes drop the scalar state past s_movrelsd_2_b32 #1726
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!1726
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1726/head"
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?
@b3IKK on GitHub · 2026-11-24 19:56 UTC · original
b3IKK:recomp/upper-lanes-movrelsd→main· +29 −2 · 1 files · 1 commits · closed without mergingAddresses
XCL-BT-037from #1488.upper_lanes::steptreatss_movreld_b32as writing any SGPR, because its destination iss[dst + m0], but nots_movrelsd_2_b32, whose destination iss[dst + m0[25:16]](and its sources[src + m0[9:0]]). The scalar state it knew for a register the instruction may have written therefore survived: with a destination offset other than 0, the actual destination kept its constant, and an upper lane that read that register resolved to a wrongRead::Const.This takes
s_movrelsd_2_b32with thes_movreldforms (the emitter andx64_masksalready handle it that way).Since the review (@upipibi): the first version's test used
m0 = 1, which is the source offset. That program writess10froms21and leavess11alone, somain'sConst(0)fors11was the right answer and the test only passed because the fix forgets every SGPR. The description's "fails onmain" was true and proved nothing about the bug. The test now usesm0 = 0x10000(destination offset 1):s_movrelsd_2_b32 s10, s20writess11froms20, andmainanswersConst(0)where the register is unknown.What is in it
crates/xcl/src/gpu/recomp/upper_lanes.rs:s_movrelsd_2_b32invalidates the scalar state likes_movreld; testmovrelsd_writes_a_register_its_dst_field_does_not_name(m0 = 0x10000, a constant ins11,s_movrelsd_2_b32 s10, s20→ the read must beUnknown), and the same shape withs_movreld_b32andm0 = 1asserting the existing behaviour.Tested
stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1).\scripts\test.ps1(cargo build --workspace+cargo test --workspace -- --test-threads=4): 976 passed, 0 failed, 45 ignored (SKIPPED: the wave64 / direct-DXIL per-lane tests that need 64-lane hardware or a semantics mode this adapter refuses,no heap windows, andcannot disable the driver cache (Windows Developer Mode is required))cargo test -p xcl --lib -- movrelsd_writes_a_register: 1 passed, 0 failed; with the one-line change reverted: 0 passed, 1 failed —left: [Const(0)], right: [Unknown]Regression run
main (
20cf130, clean tree, no local changes):PR (
beb5438, clean tree, no local changes):(The head is on
689f2db;mainmoved to20cf130while the suite ran, and the main block is that commit, run right after the PR's. Both peak higher than the blocks this PR had before, 14.5 GB: several long runs of the title on this machine in between filled its caches, and its runs now commit 17–20 GB in the first minute whatever the build. I have not isolated why.)Not tested
s_movrelsd_2_b32re-targeted (the unit test builds the sequence directly)AI use
XCL-BT-037againstupper_lanes, the emitter andx64_masks, wrote the fix and test, corrected the test's offset after the review (and confirmed it then fails without the fix for the stated reason), rebased onto689f2db, ran the test suite andscripts/smoke.ps1regression runs, and drafted this PR description.@upipibi on GitHub · 2026-11-24 20:06 UTC · original
The fix is right, but the test and the description use the wrong offset.
s_movrelsd_2_b32takes the source offset from M0[9:0] and the destination offset from M0[25:16]:SGPR[SDST + M0[25:16]] = SGPR[SSRC0 + M0[9:0]]. That is howemit.rs:1308anddxil/lower.rssmovrelonmainalready lower it.With
m0 = 1,s_movrelsd_2_b32 s10, s20writes s10 from s21. s11 is untouched, somain'sConst(0)for s11 was the correct answer for that program. The test passes with the fix only because the fix forgets every SGPR, which is sound but less precise.The case the PR is about needs the destination offset,
m0 = 0x10000, which writes s11 from s20. I checked it at8b20a4d(CPU-only test, the same program withSome(0x10000)as the m0 literal):[Unknown], passes;left: [Const(0)], right: [Unknown], fails.Using
0x10000in the first case (and adjusting its comment and the description) would make the test fail onmainfor the stated reason.AI-assisted (Claude Code).
@b3IKK on GitHub · 2026-11-24 21:47 UTC · original
Rebased onto
1d027e5and re-ran both with the current scripts/smoke.ps1 (#677's hashed itle: line): 960 passed, 0 failed, 43 ignored.@DavidM1911 on GitHub · 2026-11-24 22:37 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~23 ignored.Thanks!
@b3IKK on GitHub · 2026-11-24 23:25 UTC · original
@upipibi you are right, and I checked it against
emit.rs("s_movrelsd_2_b32" => (m0 & 0x3FF, (m0 >> 16) & 0x3FF)): the source offset isM0[9:0]and the destination offsetM0[25:16]. Withm0 = 1my program wrotes10froms21,s11was untouched, andmain'sConst(0)was the correct answer. The test passed with the fix only because the fix forgets every SGPR, so "fails onmain" in the description was true and showed nothing about the bug.Pushed
beb5438(rebased onto689f2db):m0 = 0x10000, sos_movrelsd_2_b32 s10, s20writess11froms20;s_movreld_b32case keepsm0 = 1, which is that instruction's destination offset.Same result as yours: with the fix
[Unknown], with the one-line change revertedleft: [Const(0)], right: [Unknown]. Suite: 976 passed, 0 failed, 45 ignored.The fix itself is unchanged and still coarser than it could be (it forgets every SGPR, as
s_movrelddoes, rather than only the registersM0[25:16]can reach). I left it that way to match the existings_movreldhandling.AI use: OpenCode, Claude Fable 5.2 made the change, ran the tests and wrote this comment.
@upipibi on GitHub · 2026-11-24 23:42 UTC · original
Checked
beb5438merged ontomain20cf130: the first case now writes s11 from s20 throughm0 = 0x10000(destination offset M0[25:16] = 1, source offset M0[9:0] = 0), as the ISA has it. Tests matchingupper_lanes/movrel: 13 passed, 0 failed, includingmovrelsd_writes_a_register_its_dst_field_does_not_name. Thanks for fixing it up.@b3IKK on GitHub · 2026-11-25 00:03 UTC · original
Closing in favour of #1616, which came first and makes the same change (#1607, group D46):
S_MOVRELSD_2_B32joins theS_MOVRELDarm ofupper_lanes::step. One thing from the review here that may be useful there: the instruction's destination offset isM0[25:16]and its source offsetM0[9:0], so a test of the register it re-targets needsm0 = 0x10000, notm0 = 1. AI use: OpenCode, Claude Fable 5.2.github-bot referenced this pull request2026-11-26 06:18:31 +00:00
@DavidM1911 on GitHub · 2026-11-26 06:17 UTC · original
Re-verification on RTX 3060 Ti (Windows 11), new head merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.Thanks!
— Devin
Pull request closed