Skip to content

shader: lower s_cmp_eq_u64, s_cmp_lg_u64, s_bitcmp0_b64 and s_bitcmp1_b64 in the direct compute path - #3081

Merged
pigalot merged 1 commit into
R0Y00:mainfrom
legacy-code-archaeologist:shader/direct-salu-cmp64
Nov 27, 2026
Merged

pigalot merged 1 commit into
R0Y00:mainfrom
legacy-code-archaeologist:shader/direct-salu-cmp64

Conversation

@legacy-code-archaeologist

@legacy-code-archaeologist legacy-code-archaeologist commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Lowers s_cmp_eq_u64, s_cmp_lg_u64, s_bitcmp0_b64, and s_bitcmp1_b64 in the direct C++ compute path (src/gfx1013_direct_compute.inl) to pure 32-bit DXIL writes of SCC.

Verification

Measured on Windows 10.0.26100 (dev preset) on upstream/main 88cddb09 + cc7a8fbe:

  • ctest --preset dev --no-tests=error -R '^native_salu_cmp64_' -V:
    • native_salu_cmp64_ir (passed): dumps DXIL IR via native_compute_ir_dump for all 22 cases (aligned pairs, null, negative inline -1, 32-bit literal 0x80000001, bits 0/31/32/63, wrapped SGPR indices 65/96), asserts pure 32-bit IR (no i64 ops), evaluates lane 0 to verify s[22:23] is untouched and exact SCC is stored, verifies 7 operand refusals, and catches 6 oracle mutants.
    • native_salu_cmp64_controls (passed): compiles all 22 cases together via compile_dxil to pure 32-bit DXIL, verifies the 7 operand refusals and 6 oracle mutants.
    • native_salu_cmp64_hardware (skipped, exit 77): NVIDIA Quadro M1000M does not support shader model 6.6 with wave32, so GPU readback is not measured locally.
  • ctest --preset dev --no-tests=error -R '^native_.*_(controls|ir)$' --output-on-failure: 47/47 passed (51.67s).
  • python -B tests/docs_links_check.py: passed (102 Markdown files, 589 links).
  • Broken-lowering sensitivity check: 5 deliberate broken builds (low_word_only_cmp, high_word_only_cmp, swap_and_or, ignore_bit5, invert_bitcmp) each failed native_salu_cmp64_ir (exit 1).

Fixes #3078
Refs #2935

AI-assisted.

@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 bc6dc3b (comment only).

The lowering reads correctly to me: 64-bit equality as two 32-bit compares joined with and/or, and the bit test picking the high word for index bit 5 with the shift masked to the word.

What holds me back from merging: the semantics are not checked by anything that runs. controls asserts only that icmp eq i32, icmp ne i32 and lshr i32 appear in the DXIL dump, which other instructions in the same program could also produce, and native_salu_cmp64_hardware skipped on your machine and skips on WARP. Could you add either an IR-level control that pins the compare operands and the high-word selection (like native_f16_alu_check.py ir with native_compute_ir_dump), or a hardware run on an SM 6.6 wave32 GPU, reported with adapter, driver and commit? The same gap was pointed out on #3071.

Command: git diff origin/main...pull/3081/head -- src/ tests/ (read).

AI-assisted; commands listed were executed locally.

Lower s_cmp_eq_u64, s_cmp_lg_u64, s_bitcmp0_b64 and s_bitcmp1_b64 in DirectCompute::scalar() using pure 32-bit DXIL ops writing SCC only, with IR-level evaluation (native_salu_cmp64_ir) via native_compute_ir_dump and compile controls (native_salu_cmp64_controls).

Fixes R0Y00#3078 (part of R0Y00#2935). AI-assisted.
@legacy-code-archaeologist

Copy link
Copy Markdown
Contributor Author

@tedin7 Thanks for catching that gap! Added the IR-level check in rebased commit cc7a8fbe on upstream/main (88cddb09):

  • native_salu_cmp64_ir (tests/cmake/native_salu_cmp64.cmake, tests/native_salu_cmp64_check.py): Dumps DXIL IR via native_compute_ir_dump for all 22 cases across s_cmp_eq_u64, s_cmp_lg_u64, s_bitcmp0_b64, and s_bitcmp1_b64, asserts no 64-bit integer IR ops appear, and evaluates lane 0 (interpret_pair_stores) to verify both the preserved SGPR pair (s[22:23]) and the exact stored SCC result (pinning the low/high word compares, sign/zero-extension of inline -1 / literal 0x80000001, and bit-5 high-word select in s_bitcmp*), plus all 7 operand refusals.
  • Broken-lowering sensitivity: Verified locally that 5 broken builds (low_word_only_cmp, high_word_only_cmp, swap_and_or, ignore_bit5, invert_bitcmp) each fail native_salu_cmp64_ir (exit 1).
  • Verification (Windows 10.0.26100, dev preset): native_salu_cmp64_ir and native_salu_cmp64_controls pass; native_salu_cmp64_hardware skips with 77 on NVIDIA Quadro M1000M (SM 6.1, no SM 6.6 wave32); ^native_.*_(controls|ir)$ passes 47/47; python -B tests/docs_links_check.py passes (102 files, 589 links). Also updated docs/experiments/native-direct-salu-cmp64.md.

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 cc7a8fbe merged into main 671d2f46 (tree 4971b9a6, clean merge; main now includes #3071). This includes the hardware run tedin7 asked for.

What I traced.

  • s_cmp_eq_u64 / s_cmp_lg_u64: two 32-bit compares, joined with and / or.
  • s_bitcmp0_b64 / s_bitcmp1_b64: the word is chosen by index bit 5. shift() masks the amount to 5 bits, so this is exactly bit S1[5:0].
  • Sources: null reads as 0. pair_high() refuses unaligned pairs and wave64 specials, and sign-extends negative inline constants. The new code also refuses vcc and exec.
  • Only SCC is written.

What I ran. I built compile_dxil native_store_replay native_compute_ir_dump in dev and release, then ran:
ctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^native_salu_(cmp64|cmov)_'

  • 6/6 passed in each preset. I included cmov because the two PRs share uses_scc_after() and the SOPC/SOP1 dispatch.
  • native_salu_cmp64_hardware ran and passed all 22 cases, each reporting preserved pair, SCC and guards matched. These include eq hi differs / eq lo differs, bits 0/31/32/63, null, -1 and the 0x80000001 literal.

Mutants (in src/gfx1013_direct_compute.inl, rebuilt each time):

mutant _ir _hardware
bit test always reads the low word (word = a_lo) fails at ('bitcmp1 bit 32 set', (512, 0, 0), 1) fails at ('bitcmp1 bit 32 set', (0, 1), 1)
s_cmp_eq_u64 joins the halves with or fails at ('eq hi differs', (512, 1, 0), 0) fails

Restored, all pass, and git diff --check is clean.

Still unmeasured (the same caveat as #3071): whether gfx1013 zero-extends the 32-bit literal in a 64-bit compare. The hardware run shows only that the lowering matches the PR's pair_high() reference.

Verdict: approve on cc7a8fbe.

Environment: NVIDIA GeForce RTX 5090 (wave 32..32, SM 6.8), driver 32.0.16.1088; Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; DXC 1.9.2602.17; Python 3.12.10.
CI: Build and test on Windows passes on cc7a8fbe.

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.

shader: lower s_cmp_eq_u64, s_cmp_lg_u64, s_bitcmp0_b64 and s_bitcmp1_b64 in the direct compute path

3 participants