shader: lower s_sext_i32_i8/i16, s_cmov_b32/b64 and s_cmovk_i32 in gfx2hlsl (Part of #1723) #2071

Manually merged
github merged 5 commits from gh-pr/2071/head into gh-pr/2071/base 2026-11-26 23:54:09 +00:00
Owner

@⁠tedin7 on GitHub · 2026-11-25 00:01 UTC · original
tedin7:x2w-b3-s-sext-cmov → main · +202 −4 · 6 files · 5 commits · merged 2026-11-25 01:57 UTC

Part of #1723

What this unblocks: batch 3 item #2, five scalar opcodes (s_sext_i32_i8, s_sext_i32_i16, s_cmov_b32, s_cmov_b64, s_cmovk_i32) that startup shaders hit and gfx2hlsl refused.

s_sext_i32_i8/i16 sign-extend the low 8/16 bits and set SCC to result != 0. s_cmov_b32/b64 and s_cmovk_i32 write SCC ? source : old destination and leave SCC alone; s_cmovk_i32 sign-extends its 16-bit immediate. Lane-mask operands, m0/exec/vcc destinations and the discard destination are refused.

Verification:

  • python3 -B tests/startup_gfx2hlsl_s_sext_cmov_check.py -> all ok (on origin/main the same test fails with AssertionError: refused: s_sext_i32_i8)
  • python3 -B tests/startup_gfx2hlsl_s_lshl_add_check.py -> exit 0
  • python3 -B tests/startup_gfx2hlsl_bit_alu_check.py -> exit 0
  • python3 -B tests/startup_gfx2hlsl_op_refusals_check.py -> exit 0
  • python3 -B tests/startup_gfx2hlsl_refusals_check.py -> exit 0
  • Not run: a Win2025 build; the change is Python only and registered as startup_gfx2hlsl_s_sext_cmov in CMakeLists.txt.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-25 00:01 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2071) `tedin7:x2w-b3-s-sext-cmov` → `main` · +202 −4 · 6 files · 5 commits · merged 2026-11-25 01:57 UTC Part of #1723 What this unblocks: batch 3 item #2, five scalar opcodes (`s_sext_i32_i8`, `s_sext_i32_i16`, `s_cmov_b32`, `s_cmov_b64`, `s_cmovk_i32`) that startup shaders hit and gfx2hlsl refused. `s_sext_i32_i8/i16` sign-extend the low 8/16 bits and set SCC to `result != 0`. `s_cmov_b32/b64` and `s_cmovk_i32` write `SCC ? source : old destination` and leave SCC alone; `s_cmovk_i32` sign-extends its 16-bit immediate. Lane-mask operands, `m0`/`exec`/`vcc` destinations and the discard destination are refused. Verification: - `python3 -B tests/startup_gfx2hlsl_s_sext_cmov_check.py` -> `all ok` (on origin/main the same test fails with `AssertionError: refused: s_sext_i32_i8`) - `python3 -B tests/startup_gfx2hlsl_s_lshl_add_check.py` -> exit 0 - `python3 -B tests/startup_gfx2hlsl_bit_alu_check.py` -> exit 0 - `python3 -B tests/startup_gfx2hlsl_op_refusals_check.py` -> exit 0 - `python3 -B tests/startup_gfx2hlsl_refusals_check.py` -> exit 0 - Not run: a Win2025 build; the change is Python only and registered as `startup_gfx2hlsl_s_sext_cmov` in CMakeLists.txt. AI-assisted; commands listed were executed locally.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:54:06 +00:00
github manually merged commit 5c10218888 into gh-pr/2071/base 2026-11-26 23:54:09 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-25 00:01 UTC · original · edited 2026-11-25 00:10 UTC

Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T00:10:21.260018Z adf137b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@⁠codex review" or "@⁠codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-25 00:01 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2071#issuecomment-7148051177) · edited 2026-11-25 00:10 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"adf137b94390c38348f0a22bea29479250e82168","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-25T00:10:21.260018Z">2026-11-25T00:10:21.260018Z</relative-time> | `adf137b` | PR opened | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@⁠codex review" or "@⁠codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-25 00:10 UTC · original

P1 Badge Preserve SCC when lowering the scalar sign-extends

For shaders that compare before s_sext_i32_i8/i16 and consume that condition afterward, these entries silently replace it with (result != 0). Both RDNA2 instructions preserve SCC, as the existing tools/pixel_aot.py scalar table already models with None. With incoming SCC=1, extending zero followed by s_cmov_b32 therefore incorrectly keeps the old destination instead of moving the source. Set the SCC rule to None and update the new fixture to verify preservation of both incoming SCC states rather than asserting a nonzero-result flag.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-25 00:10 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2071#discussion_r4688378133) **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Preserve SCC when lowering the scalar sign-extends** For shaders that compare before `s_sext_i32_i8/i16` and consume that condition afterward, these entries silently replace it with `(result != 0)`. Both RDNA2 instructions preserve SCC, as the existing `tools/pixel_aot.py` scalar table already models with `None`. With incoming SCC=1, extending zero followed by `s_cmov_b32` therefore incorrectly keeps the old destination instead of moving the source. Set the SCC rule to `None` and update the new fixture to verify preservation of both incoming SCC states rather than asserting a nonzero-result flag. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-25 00:10 UTC · original

P2 Badge Check both halves of 64-bit conditional-move operands

For a register pair, is_lane_mask() checks only its starting SGPR, so a mask stored in the high word bypasses this guard and is treated as a complete 32-bit scalar. With SCC=1, the LLVM-accepted sequence s_mov_b32 s3, exec_lo; s_cmov_b64 s[4:5], s[2:3]; s_lshr_b32 s5, s5, 1 produces zero instead of 0x7fffffff on an all-active wave: the translator stores only the lane's EXEC bit in s3, then copies it into an untagged s5. Check both registers of each source and destination pair before accepting the full-width move.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-25 00:10 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2071#discussion_r4688378141) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Check both halves of 64-bit conditional-move operands** For a register pair, `is_lane_mask()` checks only its starting SGPR, so a mask stored in the high word bypasses this guard and is treated as a complete 32-bit scalar. With SCC=1, the LLVM-accepted sequence `s_mov_b32 s3, exec_lo; s_cmov_b64 s[4:5], s[2:3]; s_lshr_b32 s5, s5, 1` produces zero instead of `0x7fffffff` on an all-active wave: the translator stores only the lane's EXEC bit in `s3`, then copies it into an untagged `s5`. Check both registers of each source and destination pair before accepting the full-width move. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
@ -2260,1 +2260,4 @@
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_sopk_signext_check.py")
# Scalar sign-extends and conditional moves (batch 3 #2).
add_test(NAME startup_gfx2hlsl_s_sext_cmov COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_s_sext_cmov_check.py")
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-25 00:10 UTC · original

P1 Badge Document the new startup scalar translation capability

This adds five previously refused startup-translator instructions, but neither README.md nor docs/experiments.md changes with the public capability, contrary to the requirement in AGENTS.md. A documentation search finds existing notes for these mnemonics under pixel_aot, not this translator. Update the capability documentation with the supported/refused operand forms and the python3 -B tests/startup_gfx2hlsl_s_sext_cmov_check.py reproduction command, explicitly distinguishing CPU evaluation from Windows/D3D12 validation.

AGENTS.md reference: AGENTS.md:L211-L212

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-25 00:10 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2071#discussion_r4688378148) **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Document the new startup scalar translation capability** This adds five previously refused startup-translator instructions, but neither `README.md` nor `docs/experiments.md` changes with the public capability, contrary to the requirement in `AGENTS.md`. A documentation search finds existing notes for these mnemonics under `pixel_aot`, not this translator. Update the capability documentation with the supported/refused operand forms and the `python3 -B tests/startup_gfx2hlsl_s_sext_cmov_check.py` reproduction command, explicitly distinguishing CPU evaluation from Windows/D3D12 validation. AGENTS.md reference: [AGENTS.md:L211-L212](https://github.com/R0Y00/Xbox2Windows/blob/adf137b94390c38348f0a22bea29479250e82168/AGENTS.md#L211-L212) Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 01:00 UTC · original

SCC preservation was fixed in f4ac3e62 (rebased); both sext entries use SCC None and the fixture checks an unset SCC stays unchanged. Latest head dc7d54e2.

AI-assisted; commands listed were executed locally: python3 -B tests/startup_gfx2hlsl_s_sext_cmov_check.py

**@⁠tedin7** on GitHub · 2026-11-25 01:00 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2071#discussion_r4688750756) SCC preservation was fixed in f4ac3e62 (rebased); both sext entries use SCC None and the fixture checks an unset SCC stays unchanged. Latest head dc7d54e2. AI-assisted; commands listed were executed locally: python3 -B tests/startup_gfx2hlsl_s_sext_cmov_check.py
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 01:00 UTC · original

Fixed in dc7d54e2: s_cmov_b32/b64 now check both halves of the source and destination pairs for a lane mask, with a regression test (fails before, passes after).

AI-assisted; commands listed were executed locally: python3 -B tests/startup_gfx2hlsl_s_sext_cmov_check.py

**@⁠tedin7** on GitHub · 2026-11-25 01:00 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2071#discussion_r4688750981) Fixed in dc7d54e2: s_cmov_b32/b64 now check both halves of the source and destination pairs for a lane mask, with a regression test (fails before, passes after). AI-assisted; commands listed were executed locally: python3 -B tests/startup_gfx2hlsl_s_sext_cmov_check.py
@ -2260,1 +2260,4 @@
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_sopk_signext_check.py")
# Scalar sign-extends and conditional moves (batch 3 #2).
add_test(NAME startup_gfx2hlsl_s_sext_cmov COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_s_sext_cmov_check.py")
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 01:00 UTC · original

Fixed in dc7d54e2: README row plus a docs/experiments.md section list supported and refused forms, the reproduction command, and state that this is CPU evaluation only, not Windows/D3D12 validation.

AI-assisted; commands listed were executed locally: python3 -B tests/startup_gfx2hlsl_s_sext_cmov_check.py

**@⁠tedin7** on GitHub · 2026-11-25 01:00 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2071#discussion_r4688751128) Fixed in dc7d54e2: README row plus a docs/experiments.md section list supported and refused forms, the reproduction command, and state that this is CPU evaluation only, not Windows/D3D12 validation. AI-assisted; commands listed were executed locally: python3 -B tests/startup_gfx2hlsl_s_sext_cmov_check.py
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-25 01:35 UTC · original

I resolved the CTest conflict and kept both registrations. The conditional move now uses the same signed SOPK immediate parser as the merged sign-extension change, and register pairs are checked for width, alignment, and range before use. On Windows the scalar sext/cmov, SOPK, cselect, mask overwrite, scalar arity, and documentation checks passed. The SOPK fixture still rejects an out-of-range immediate.

**@⁠R0Y00** on GitHub · 2026-11-25 01:35 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2071#issuecomment-7149727405) I resolved the CTest conflict and kept both registrations. The conditional move now uses the same signed SOPK immediate parser as the merged sign-extension change, and register pairs are checked for width, alignment, and range before use. On Windows the scalar sext/cmov, SOPK, cselect, mask overwrite, scalar arity, and documentation checks passed. The SOPK fixture still rejects an out-of-range immediate.
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-25 01:52 UTC · original

The overlapping updates left s_cmovk truncating out-of-range text and loosened pair checks. I kept your CTest update and restored the shared SOPK parser and exact pair validation, with five refusals in the dedicated cmov test. Valid binary cmov cases, SOPK, cselect, mask overwrite and scalar arity pass.

**@⁠R0Y00** on GitHub · 2026-11-25 01:52 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2071#issuecomment-7150050801) The overlapping updates left s_cmovk truncating out-of-range text and loosened pair checks. I kept your CTest update and restored the shared SOPK parser and exact pair validation, with five refusals in the dedicated cmov test. Valid binary cmov cases, SOPK, cselect, mask overwrite and scalar arity pass.
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-25 00:10 UTC · original · reviewed

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: adf137b943

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@⁠codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback".

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-25 00:10 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2071#pullrequestreview-6049516081) · **reviewed** <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `adf137b943` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@⁠codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback". </details>
This discussion has been locked. Commenting is limited to contributors.
No description provided.