Skip to content

shader: lower the SDWA v_movrel* forms in pixel_aot - #1934

Merged
R0Y00 merged 1 commit into
R0Y00:mainfrom
legacy-code-archaeologist:shader/sdwa-movrel
Nov 24, 2026
Merged

R0Y00 merged 1 commit into
R0Y00:mainfrom
legacy-code-archaeologist:shader/sdwa-movrel

Conversation

@legacy-code-archaeologist

Copy link
Copy Markdown
Contributor

Refs #1917. I built this before the issue had a maintainer reply; if you want the scope narrowed, I'll adjust. This completes the VGPR movrel encodings: plain (#1785), DPP (already there), SDWA (here), swaprel (#1844) and scalar (#1894).

What

tools/pixel_aot.py lowers v_movreld_b32_sdwa, v_movrels_b32_sdwa, v_movrelsd_b32_sdwa and v_movrelsd_2_b32_sdwa through the existing movrel block. LLVM 15 spells them identically for gfx1013 and gfx1030, for example 7e1886f9 00001518 as v_movrels_b32_sdwa v12, v24 dst_sel:WORD_1 dst_unused:UNUSED_PRESERVE src0_sel:BYTE_0.

  • Unchanged: the m0 rules, the refusals and the source-before-destination reads.

  • Selections, applied as v_mov_b32_sdwa applies them (sdwa_source, sdwa_dest):

    • the source selection, with an optional sext(...), applies to the indexed source word;
    • the destination selection applies to each indexed destination;
    • UNUSED_PRESERVE keeps the unselected bits from that destination's own tracked old value, so under a dynamic m0 each reachable destination merges its own word.
    • This order is an assumption: it follows the RDNA 2 naming and the other movrel forms, and has not been measured on RDNA hardware.
  • Refused:

    • UNUSED_SEXT;
    • UNUSED_PRESERVE into an untracked destination;
    • clamp;
    • 16-bit (low-half) values as the source or as the kept destination;
    • SGPR sources;
    • the movrel refusals.

    Under a dynamic m0, every reachable destination must hold a tracked numeric word, also for UNUSED_PAD, as for the other movrel forms.

Evidence

SDWA_MOVREL_BODY (tests/pixel_aot_check.py) runs each move with a dynamic and then a static m0 over integer banks. It mixes BYTE, WORD and DWORD selections, sext, UNUSED_PAD and UNUSED_PRESERVE, and exports four words through the bit-exact R32G32B32A32_UINT target, where they must equal an independent SDWA model. The expected words on the two DPP_MOVREL_SETS:

0x008856aa 0x3600ffbb 0xffffffdd 0x332143bb
0x00cc56aa 0x3600ffb9 0x0048ffdd 0x887743bb
  • Draw controls (pixel_mismatch required):
    • a dropped source selection;
    • UNUSED_PRESERVE turned into UNUSED_PAD;
    • an ignored dynamic m0;
    • the wrong source byte;
    • a missing sext.
  • Translation controls: nine refusals, the entry mask, and a dynamic UNUSED_PRESERVE move inside one bank in which each reachable register merges its own old word.

Windows 11 Pro 26100.9168, DXC 10.0.26100, debug layer unavailable:

ctest --preset dev --no-tests=error -R "^pixel_aot_sdwa_movrel_" -V
Adapter Driver Result
WARP 10.0.26100.8972 bit-exact on both sets; all 5 controls mismatched
NVIDIA Quadro M1000M 32.0.15.7371 same

Other runs:

  • LLVM 15 round trip: tests/pixel_aot_check.py binary passes. llvm-mc is clang 15.0.7's integrated assembler, with llvm-objcopy and LLVM-C.dll from the same build.
  • Full ctest --preset dev -E '_hardware$': 854/854.
  • After the rebase onto tests: pin the swaprel selects and the plain movrel entry-mask refusal #1875:
    • the sdwa/plain/swaprel/smovrel movrel draws pass, 8/8;
    • the no-argument controls exit 0;
    • tests/form_coverage_check.py passes;
    • tools/form_coverage.py --gaps gfx1030 no longer lists any v_movrel* form.

🤖 Generated with Claude Code

v_movreld_b32_sdwa, v_movrels_b32_sdwa, v_movrelsd_b32_sdwa and
v_movrelsd_2_b32_sdwa (LLVM 15 spells them identically for gfx1013 and
gfx1030) now go through the movrel block: the m0 rules, refusals and
source-before-destination reads are unchanged. The source selection, with
an optional sext(...), applies to the indexed source word and the
destination selection to each indexed destination, as v_mov_b32_sdwa
applies them; UNUSED_PRESERVE keeps the bits from that destination's own
tracked old value, so under a dynamic m0 each reachable destination
merges its own word (order read from the RDNA 2 naming, not measured on
RDNA hardware). UNUSED_SEXT, UNUSED_PRESERVE into an untracked
destination, clamp, 16-bit values, SGPR sources and the movrel refusals
are refused.

SDWA_MOVREL_BODY runs each move with a dynamic and a static m0 over
integer banks with BYTE, WORD and DWORD selections, sext, PAD and
PRESERVE, exported through the bit-exact R32G32B32A32_UINT target against
an independent SDWA model; five controls must mismatch. The translation
controls check nine refusals, the entry mask and a dynamic PRESERVE move
inside one bank.

Windows 11 26100: pixel_aot_sdwa_movrel_warp (WARP 10.0.26100.8972) and
_hardware (Quadro M1000M, 32.0.15.7371) match bit for bit on both sets;
every control mismatched. pixel_aot_check.py binary with LLVM 15 passes.
Full dev suite without _hardware: 854/854.

Refs R0Y00#1917

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of head bc03f191030951c765c8d1af26f415b6041fdb7a.

Result: 0 P1, 0 P2. The change is correct and clean-room. I am not merging it, because older open PRs already cover the same files (see "Merge note").

What I read:

  • tools/pixel_aot.py: SDWA v_movreld/movrels/movrelsd/movrelsd_2 are lowered through the existing movrel block. sdwa_source applies to the indexed source word. sdwa_dest applies to each reachable destination, merging that destination's own tracked old value for UNUSED_PRESERVE. UNUSED_SEXT and an unbalanced sext( are refused.
  • CMakeLists.txt: only registers pixel_aot_sdwa_movrel_${adapter}.
  • docs/experiments.md: describes the behavior and says the operand order is not measured on RDNA hardware.
  • No copied vendor code.

Commands run locally (exit codes):

  • python3 -B tests/pixel_aot_check.py: 0
  • python3 tests/docs_links_check.py: 0 (18 files, 386 links)
  • python3 tests/bidi_controls_check.py: 0
  • git diff --check origin/main...HEAD: 0
  • git merge-tree --write-tree --name-only origin/main HEAD: no conflicts
  • Windows Server 2025 node, x2w_pipe.py win2025 1934 scoped to ^pixel_aot_(sdwa_movrel|swaprel|smovrel)_: Debug 6/6 and Release /O2 6/6 passed. form_coverage_check.py passed there.

Mutations (each reverted afterwards):

  1. Dropped sdwa_source(...) in the movrel block. pixel_aot_check.py on Linux still passes, so the translation checks do not pin the source selection. The pixel_aot_sdwa_movrel_warp and pixel_aot_sdwa_movrel_hardware draws on Windows fail, so the GPU test kills it.
  2. Replaced the dynamic-m0 sdwa_dest(...) merge with the raw value. pixel_aot_check.py fails, so it is killed.

Non-blocking suggestion: pin a source-selection text in the Linux translation controls too. Then mutation 1 fails without a GPU.

CI at the time of review: the Linux Python job passed. The two Windows jobs and the fixtures job were still pending.

Merge note: #1923, #1790, #1612, #1670 and #1572 are older, open and not drafts. They rewrite CMakeLists.txt, docs/experiments.md, tests/pixel_aot_check.py and tools/pixel_aot.py in the same regions. They have no CHANGES_REQUESTED, so the competing-PR gate stays closed. This one will need a rebase after any of them lands.

AI-assisted; commands listed were executed locally.

@ChazY11

ChazY11 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Ran it, and found one lowering effect the fixture does not pin

Windows 11 build 26300.9974, device-free path only:

out/pe-env/Scripts/python.exe -B tests/pixel_aot_check.py
exit 0

(pixel_aot_check.py binary needs <llvm-mc> <llvm-objcopy> <libLLVM> on this machine and exits 1 with a usage line, so the
LLVM round trip did not run for me — that is my environment, not your branch.)

Mutations

mutation result
SDWA_MOVREL_PATTERN no longer matched (plain forms only) caught
UNUSED_SEXT refusal disabled caught
the first sdwa_dest(...) call replaced by pass caught
swizzled = sdwa_source(swizzled, sdwa_sel[0], sdwa_sel[1]) replaced by pass not caught

The last one is a real behavioural change, not an equivalent mutant. With SDWA_MOVREL_BODY:

unmutated:  uint dpp_val49 = ((asuint(dpp_src49) >> 0u) & 0xffffu);
mutated:    uint dpp_val49 = asuint(dpp_src49);

i.e. the source selection (src0_sel) stops being applied and the raw word flows into the destination write. The check still
passes.

Why it passes

The positive case is asserted at line 16481:

sdwa_hlsl = translate_int(uncompressed_export(SDWA_MOVREL_BODY))
assert "dpp_soff" in sdwa_hlsl and "dpp_doff" in sdwa_hlsl and "QuadRead" not in sdwa_hlsl

which establishes the instruction is accepted and does not become a quad read, but says nothing about the two selections being
applied. Everything else added in this area is a refusal case (UNUSED_PRESERVE, UNUSED_SEXT, clamp, dynamic m0, the
v24, v25 pair, missing m0), so the accepted path is only tested by presence of two identifiers.

Suggested fix, one line each, in the same style the DPP cases already use:

assert "((asuint(dpp_src27) >> 24u) & 0xffu)" in sdwa_hlsl      # src0_sel:BYTE_3 with sext
assert "((asuint(alu30) & 0xffff0000u) | ((dpp_val37 & 0xffffu) << 0u))" in sdwa_hlsl   # dst_sel:WORD_0

(Those two substrings come from the unmutated output above; pick whichever cases your body actually contains — the point is that
one substring per selection should be required, so dropping either call fails.)

What is good here

The refusal set is thorough, the m0 rules are shared with the plain forms rather than copied, and UNUSED_SEXT/UNUSED_PRESERVE
being refused rather than guessed is the right call — UNUSED_PRESERVE needs a tracked numeric destination and the error says so.

Verdict

One blocking-ish gap: the source selection is unpinned. Everything else I could break was caught.

Notes

  • AI-assisted review.

@R0Y00
R0Y00 merged commit 387bdaf into R0Y00:main Nov 24, 2026
5 checks passed
R0Y00 pushed a commit that referenced this pull request Nov 24, 2026
Follow-up to ChazY11's review of #1934: the device-free pixel_aot_check.py
run only checked that SDWA_MOVREL_BODY translates, so dropping the source
selection still passed it (the draw caught it). SDWA_MOVREL_PINS now lists
the exact expression each source and destination selection of the body
produces, with temporaries as \d+, and how often it must appear (once per
static move, once per reachable destination of a dynamic one).

Each of five one-line mutations of tools/pixel_aot.py, applied alone, now
makes `python -B tests/pixel_aot_check.py` exit 1: the source selection
dropped (the reported survivor), sext ignored, the single-destination
selection dropped, the dynamic-destination selection dropped, and dynamic
UNUSED_PRESERVE treated as UNUSED_PAD. tools/pixel_aot.py is unchanged.

Refs #1917, #1934

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants