Skip to content

compute: lower s_or_saveexec_b32 in the direct wave32 path - #3193

Merged
R0Y00 merged 1 commit into
R0Y00:mainfrom
Leyukaka:or-saveexec-b32
Nov 28, 2026
Merged

R0Y00 merged 1 commit into
R0Y00:mainfrom
Leyukaka:or-saveexec-b32

Conversation

@Leyukaka

Copy link
Copy Markdown
Collaborator

Fixes #3158. Part of #2935. Target branch main.

Change (src/gfx1013_compute_native.cpp, src/gfx1013_direct_compute.inl): direct wave32 compute lowers s_or_saveexec_b32 like s_and_saveexec_b32, with OR.

  • D = old EXEC.
  • EXEC = old EXEC | S0.
  • SCC = (EXEC != 0).
  • As with s_mov_b32 exec_lo and s_or_saveexec_b64, EXEC is stored as computed, including bits past the group. A lane runs only if its own bit is set.
  • transfer now marks EXEC numeric after s_and_saveexec_b32 as well; before, that op went through the generic SOP1 branch, which cleared only its destination.
  • An EXEC destination is refused.

Tests. The setup was Windows 11 build 26300.9974 with an NVIDIA GeForce RTX 5080 (driver 32.0.16.2101) and DXC from the Windows SDK 10.0.26100, on main 80668b97 plus this commit.

  • native_or_saveexec_hardware (new) runs in 8- and 32-thread groups, against a CPU reference. It covers these sources:

    • -1;
    • an SGPR that aliases the destination;
    • a literal;
    • vcc_lo;
    • an empty mask;
    • bit 31, which is past the 8-thread group.

    It checks the saved EXEC, the new EXEC, SCC (primed to the opposite value) and a restore through s_mov_b32 exec_lo.

  • native_direct_container checks the EXEC-destination refusal and a descriptor-SCC case.

  • native_wave_request_hardware, native_lane_access_hardware, native_permlane* and native_dpp* pass.

  • Mutation checks, run by hand:

    • AND instead of OR fails native_or_saveexec_hardware;
    • clamping EXEC to the group fails it too;
    • accepting an EXEC destination fails native_direct_container.

Measured on a local capture (counts and instruction shape only) with compile_dxil --jobs 8 gfx1013-direct-cs@36 --requests on main 80668b97.

AI-assisted.

@pigalot pigalot 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.

I reviewed c9e32e20 over current main c45bf9ab. The trial merge conflicts in tests/native_direct_container_check.py: #3189 (995c1327) added its descriptor-sop1-* checks at the same spot as this PR's two new checks. The conflict is purely additive, so I resolved it locally by keeping both blocks (tree 7cf7bb3b, git diff --cached --check clean) and tested that. The branch still needs a rebase or a merge of main before it can land.

What I traced.

  • Semantics: for s_or_saveexec_b32 the lowering saves the old EXEC to D before writing, sets EXEC to old | S0, and sets SCC to EXEC != 0. That matches the RDNA SOP1 definition. a is read before write(i.dst), so a source that aliases the destination sees the old value (the sgpr case).
  • SCC liveness after #3189: the PR adds s_or_saveexec_b32 to the overwrites list, next to s_and_saveexec_b32. That is right, because the op always writes SCC. #3189's preserves_sop1 list does not contain it, so the merged tree classifies it consistently.
  • Destination guard: i.dst > 107 refuses exec_lo and the other special registers, while SGPRs and vcc are accepted.
  • Wave64 and graphics: these keep their existing paths, because or_saveexec requires compute && !wave64.

What I ran on the resolved merge:

  • dev: full build, then

    ctest --test-dir out/build/dev --no-tests=error -j 4 -R '^(native_direct_container|native_.*saveexec.*|native_wave_request.*|native_lane_access.*|native_permlane.*|native_dpp.*|native_scalar.*)$' -E '_hardware$'
    ctest --test-dir out/build/dev --no-tests=error -j 1 -R '^(native_or_saveexec|native_wave_request|native_lane_access|native_permlane.*|native_dpp.*)_hardware$'

    3/3 CPU and 6/6 hardware tests pass (native_or_saveexec, native_wave_request, native_dpp_mirror, native_dpp_quad, native_dpp_row, native_lane_access), with no skips.

  • release /O2: built compile_dxil and native_store_replay, then ran native_or_saveexec_hardware and native_direct_container. 2/2 pass.

Mutants, each rebuilt in dev and run against native_or_saveexec_hardware and native_direct_container (the unmutated baseline passes first):

Mutant Result
no OR lowering (negative control: main's behaviour) killed (both tests)
OR → AND killed (hardware)
EXEC-destination refusal removed killed (container)
D gets the new mask instead of the old EXEC killed (hardware)
SCC from the old EXEC killed (hardware)
EXEC clamped to the 8-thread group killed (hardware)
transfer branch removed survives
transfer keeps the old EXEC symbol (set(126, {}) dropped) survives
transfer branch only for s_or_saveexec_b32 (main's s_and_saveexec_b32 handling) survives

Restored and rebuilt afterwards; git diff --quiet is clean.

Findings.

  1. Rebase needed (above). Keeping both check blocks is the resolution I tested.
  2. The transfer change is not pinned (non-blocking). No test fails without it, for either op. That includes the s_and_saveexec_b32 part, which changes behaviour beyond this PR's title: EXEC becomes numeric after it. I believe the change is correct, because the generic SOP1 branch left EXEC with its pre-op symbol. A case where the stale symbol is observable would pin it, or it could move to its own PR. One possible case, which I have not run: a constant s_mov_b32 exec_lo, then s_or_saveexec_b32, then a consumer of EXEC's symbol.

Verdict: comment. GitHub reports c9e32e20 as conflicting, so I'm not approving it. Apart from the rebase I found nothing blocking, and I'll retest and approve the rebased head.

Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088; Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; DXC 1.9.2602.17; Python 3.12.10; wave32; debug layer off.
CI: Build and test on Windows, Assemble and translate gfx1013 fixtures and Run platform-independent Python checks on Linux pass on c9e32e20 against its own base.

This reply was AI-assisted.

@KelboLive

Copy link
Copy Markdown
Contributor

Review of c9e32e20 (integrated over main):

D = old EXEC, EXEC = old EXEC | S0, SCC = (EXEC != 0), like
s_and_saveexec_b32 with OR. As with s_mov_b32 exec_lo, EXEC keeps every
bit, including bits past the group; a lane runs only if its own bit is
set. An EXEC destination is refused.

native_or_saveexec_hardware covers -1, an SGPR aliasing the destination,
a literal, vcc_lo, an empty mask and a bit past the group, in 8- and
32-thread groups, with the saved EXEC, the new EXEC, SCC and a restore.

AI-assisted.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Reviewed c8bf4dc over main 2d6dad1 (integrated tree 974293e72afa1e48fa420ca8a37ed5610595e826). The merge retains both sets of descriptor/SCC controls. The wave32 Compute path reads the source and old EXEC before writing the destination, preserves bits outside a short group, and derives SCC from the new mask. The EXEC-destination refusal remains covered, and the unchanged wave-size and lane-access cases passed.

ctest --test-dir <build> --no-tests=error --output-on-failure -j 1 -R "^native_(direct_container|(or_saveexec|wave_request|lane_access|dpp8|packed_dot2_f16_compute)_hardware)$"

Debug 6/6 and Release /O2 6/6, zero skips. RTX 4060 Laptop GPU 32.0.16.1656, Windows 11 26200.9974, standalone replay without the debug layer. Hosted required Windows CI passed. The capture-census evidence tracks first refusals only; the fixture independently checks the result bits and side effects.

@R0Y00
R0Y00 merged commit f9286e7 into R0Y00:main Nov 28, 2026
5 checks passed

@pigalot pigalot 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.

Retested c8bf4dcd merged over current main 24eb18b9. The merge is clean (tree 65eb0165) and git diff --cached --check is clean.

My comment review on c9e32e20.

  • Rebase needed: addressed. The branch is rebased and the PR is mergeable. The PR's own diff, c8bf4dcd against its merge base, is byte-identical to c9e32e20 against its base. So the lowering, the overwrites entry, the EXEC-destination guard and the tests are what I traced before. The native_direct_container_check.py checks sit next to #3189's descriptor-sop1-* block, as in my local resolution.
  • The transfer change is still not pinned (non-blocking). No test fails without it, as before.

What I ran.

  • Builds: full dev and release /O2.

  • CPU, full suite: ctest --test-dir out/build/dev --no-tests=error -j 8 -E '(startup_audio|_hardware$)' gives 1985 tests: 1934 pass, 0 fail, 51 capability skips.

  • CPU, release: native_direct_container passes.

  • Hardware:

    ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^(native_or_saveexec|native_and_saveexec|native_wave_request|native_lane_access|native_permlane.*|native_dpp.*)_hardware$'

    8/8 pass in each preset, with no skips: native_or_saveexec, native_wave_request, native_lane_access, native_permlane, native_dpp8, native_dpp_mirror, native_dpp_quad and native_dpp_row.

The mutants from my earlier review were run on the same code and still apply.

Verdict: approve on c8bf4dcd. This supersedes my comment review on c9e32e20.

Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088; Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; DXC 1.9.2602.17; Python 3.12.10; wave32; debug layer off.
CI: Build and test on Windows, Assemble and translate gfx1013 fixtures and Run platform-independent Python checks on Linux pass on c8bf4dcd.

This reply was AI-assisted.

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.

direct compute: lower s_or_saveexec_b32 (wave32)

4 participants