gfx2hlsl: lower s_nand_b32, s_nor_b32 and s_xnor_b32 on lane masks #2451
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2459"
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?
Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-25T17:21:11Z.
What / Why
gfx2hlsl.pyrefuses the three scalar complements (s_nand_b32,s_nor_b32,s_xnor_b32) whenever an operand is alane mask (
<op> on a lane mask). The guard was added because the per-lane model keeps one bit of a mask, while theguest SCC is (whole 32-bit complemented word != 0), which a one-lane projection cannot show.
The destination value has no such problem: bit i of
~(S0 op S1)depends only on bit i of each source. With everysource a lane mask the lane's bit of the result is exact. Only SCC is not.
Change
Accepted:
s_nand_b32/s_nor_b32/s_xnor_b32with an SGPR destination (s0..s105) when every source isvcc_lo,exec_loor an SGPR holding a lane mask. EmitssD = (~(a op b)) & 1;and marks sD as a mask.SCC is not emitted. The instruction records an SCC effect that is not modelled, and the existing stale-SCC scan
(the one used for SCC from descriptor data) refuses the program if any instruction can read that SCC before the
next SCC write, through joins and back edges:
scc from a lane-mask complement in <reader>. The scan now carriesthe kind of the stale write; the descriptor message is unchanged.
The mask mark follows program order. Because it is now the proof for accepting the form, a marked SGPR stays
proven at a branch target only if the block of its last write dominates the target and no block on a path from
that write to the target writes the register again. Otherwise the complement is refused
(
<op> on a lane mask joined at a branch target) until the register is written again. Other users of the markare unchanged.
Still refused (
<op> on a lane mask): a mask next to a plain word or a constant, avcc_lo,exec_loorm0destination,
vcc_hi/exec_hi.docs/experiments.md: the paragraph on the 32-bit scalar complements states the accepted and refused forms.Tests
tests/startup_gfx2hlsl_sop2_complement_check.py(extended, pure Python):lanes of 196 edge-word pairs against
(~(a op b) >> lane) & 1, SCC left at its sentinel.existing lane-mask refusal controls (5 per operation) pass unchanged.
s_and_saveexec_b32accepted; SCC write then read accepted; an SCCread refused in 4 shapes per operation (direct
s_cselect_b32,s_cbranch_scc1, a read behind a jump that skipsthe SCC write, a read at a loop head reached over the back edge).
before the split and on no arm is accepted across the join; a rewrite after the join proves it again; an
overwritten mask is refused as a plain word.
Commands and results (Windows, Python 3.11+ venv):
Not run: the
binaryanddecodemodes (need llvm-mc / libLLVM), and the device checks.Measured
First refusal per request over 124 vertex/pixel requests captured locally, translated with this change on top of a
local merge of open translator PRs (the requests do not reach these instructions on main alone):
s_nand_b32 on a lane maskv_cndmask_b32v_readfirstlane_b32requires a proven uniform sourceimage_gather4_lzrequires a constant samplerAll 62 first refusals are one shape: two compare masks, the complement, then
s_and_saveexec_b32, whichoverwrites SCC. None of the 62 was refused by the join rule at that complement. The SCC scan runs only on a program
that translates to the end, and all 62 still stop at a later, unrelated refusal, so it has not run on them. Static
count instead: over the 300 complement instructions in the 120 pixel programs that contain one, the same scan run
with every complement marked stale finds no SCC reader (0 programs). Later complements in these programs are not
reached yet, so the join rule is measured on the first one only.
Limits
s_cselect_b32 sN, -1, 0) is still refused.s_not_b32ands_orn2_b32on lane masks are accepted and emit aper-lane SCC, although their guest SCC has the same whole-word property; and a 32-bit
and/or/xorof a lane maskwith a plain word emits
(mask op word) & 1, which reads bit 0 of the word for every lane.🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T18:26:41Z.
Review: COMMENTED
Review of head
d94dae50(Linux checks only; no Windows run by me).What I checked
tools/startup/gfx2hlsl.py,tests/startup_gfx2hlsl_sop2_complement_check.py,docs/experiments.md. Small, additive, no CI/launcher/hook files.gfx2hlsl.py~2415-2426), so per-lane bit i is exact. SCC is not emitted anddescriptor_scc_readsnow refuses any program that can read it before the next SCC write.unjoined_masks(dominance + re-write on a path to the branch target) looks right to me for forward joins and back edges.s_not_b32/s_orn2_b32on lane masks andand/or/xorof a mask with a plain word still emit a per-lane SCC. Those are out of scope here, fine as a follow-up.Commands run (all passed)
python3 -B tests/startup_gfx2hlsl_sop2_complement_check.py-> PASSpython3 tests/docs_links_check.py-> 19 files, 465 links OKpython3 tests/bidi_controls_check.py-> OKgit diff --check origin/main...HEAD-> cleanjoin_masksrefusal (line 2425) -> test FAILS ("a mask that another path into the branch target changes is refused").anymask source instead ofall(line 2422) -> test FAILS (mixed/constant/mask-destination forms stay refused).git checkout -- .after each.Notes
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T18:22:16Z.
Five mutations: three caught, two survive — and I could not establish that either survivor is a gap
Baseline:
startup_gfx2hlsl_sop2_complement_check.pyPASS, wholestartup_gfx2hlsl_*family green.scc=Nonerule dropped (scc=None if lane_complement else scc→ alwaysscc)is_lane_masksources no longer force the general pathdst[1] <= 105→<= 106)word_complementdropped fromlane_complement(any op with a mask dst and mask sources takes the complement path)The three caught rows are the ones that decide correctness: SCC must stay untouched on the lane-complement path (the complement of a mask does not carry the operation's carry semantics), a mask joined at a branch target is not provably per-lane, and a mix of mask and ordinary sources must fall back to the word path. Good.
The two survivors, stated as unexercised rather than as gaps
dst[1] <= 105→106. There is no fixture register at that boundary, so nothing distinguishes them today. Whether 106 is actually wrong depends on how the SGPR index maps to the emitted declaration; I did not establish a difference, so I am not calling it a gap — only unasserted.word_complementdropped. I tried to show a behaviour change withs_and_b32(non-complemented, mask destination, mask sources), comparing the emitted lines with and without the mutation. My probe did not reach the branch: the stage'smasksset is empty unless a mask register is first introduced, sois_lane_maskwas false and both versions emitted an empty line. That is my harness limitation, not evidence of equivalence — and not evidence of a gap either.If you want that line pinned, the cheapest case is one where a non-complemented op takes a mask destination and mask sources, e.g. after
s_mov_b64 exec, -1soexecis inmasks, thens_and_b32 s[10:11], vcc, exec, asserting the emitted expression is the plain&and not the complemented form. That is the shape theword_complementconjunct exists to exclude, and it currently has no fixture.One note on the width bound
dst[1] <= 105is the same constant the shift-add path uses at line 2428 (dst[1] > 105), so the two are consistent — worth a named constant or a comment saying why 105, because a future SGPR-count change would need both.AI-assisted; the five mutations and the probe were run locally on Windows 11 build 26300.9974.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T19:05:28Z.
Review: COMMENTED
Review of head
523925679a(comment only).Checked against origin/main:
Stage.unjoined_masksplus the newjoin_maskstrack whether a lane-mask mark holds at a branch target (dominating last write, no rewrite on a path into the target). The refusal fires only for the complement ops, so other lowerings are unchanged.descriptor_scc_readsnow yields the effect kind and refuses any SCC read reachable before the next SCC write, also through branches and back edges. Thedescriptormessage text is unchanged.Commands run in a worktree on this head:
python3 tests/startup_gfx2hlsl_sop2_complement_check.py-> PASSpython3 tests/docs_links_check.py-> passpython3 tests/bidi_controls_check.py-> passgit diff --check origin/main...HEAD-> cleanscc=None if lane_complement else sccchanged toscc=scc-> the check FAILS (16 failing lines)Note: like the sibling complement checks, the test runs the emitted lines against an integer reference per lane, not a D3D12 WARP readback. The lowering is a single
(~(a op b)) & 1on one-bit lane values, so I consider that enough here.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T19:05:56Z.
Win2025 WARP receipt for head
52392567(dev + release, pipeline run 2026-11-25).Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
523925679a6a527afae1231f79e0abb695249021:--preset dev):cmake --build --preset dev --target d3d12_xs_device_obj d3d12_xs_shim -- -j 2):0.45s(configure0.00s)/O2(--preset release):cmake --build --preset release --target d3d12_xs_device_obj d3d12_xs_shim -- -j 2):1.01s(configure0.00s)tests/mesh_heap_sampler_check.pyok (0.5s),tests/startup_buffer_address_check.pyok (0.3s),tests/startup_compute_request_offline_check.pyok (0.3s),tests/startup_compute_translate_check.pyok (0.2s),tests/startup_flat_param_check.pyok (0.1s),tests/startup_gfx2hlsl_add_sub_co_check.pyok (0.1s),tests/startup_gfx2hlsl_add_sub_co_ci_check.pyok (0.1s),tests/startup_gfx2hlsl_bit_alu_check.pyok (0.5s),tests/startup_gfx2hlsl_capture_check.pyok (0.7s),tests/startup_gfx2hlsl_cmp16_check.pyok (0.2s),tests/startup_gfx2hlsl_compare_dst_check.pyok (0.1s),tests/startup_gfx2hlsl_compute_check.pyok (0.2s),tests/startup_gfx2hlsl_cselect_mask_check.pyok (0.1s),tests/startup_gfx2hlsl_cvt_alu_check.pyok (0.1s),tests/startup_gfx2hlsl_f32_lg_check.pyok (1.0s),tests/startup_gfx2hlsl_f32_nan_check.pyok (3.9s),tests/startup_gfx2hlsl_handler_arity_check.pyok (0.1s),tests/startup_gfx2hlsl_image_arity_check.pyok (0.1s),tests/startup_gfx2hlsl_image_get_lod_check.pyok (0.1s),tests/startup_gfx2hlsl_int_med3_check.pyok (0.1s),tests/startup_gfx2hlsl_join_symbols_check.pyok (0.1s),tests/startup_gfx2hlsl_loop_constants_check.pyok (0.1s),tests/startup_gfx2hlsl_mask_overwrite_check.pyok (0.1s),tests/startup_gfx2hlsl_operand_count_check.pyok (0.1s),tests/startup_gfx2hlsl_readfirstlane_recompute_check.pyok (0.1s),tests/startup_gfx2hlsl_readfirstlane_uniform_check.pyok (0.1s),tests/startup_gfx2hlsl_refusals_check.pyok (0.3s),tests/startup_gfx2hlsl_root_check.pyok (0.5s),tests/startup_gfx2hlsl_saveexec_same_reg_check.pyok (0.1s),tests/startup_gfx2hlsl_scalar_brev_fold_check.pyok (0.1s),tests/startup_gfx2hlsl_scalar_m0_check.pyok (0.1s),tests/startup_gfx2hlsl_sdwa_cvt_check.pyok (0.2s),tests/startup_gfx2hlsl_sgpr_spill_check.pyok (0.1s),tests/startup_gfx2hlsl_shift64_check.pyok (0.1s),tests/startup_gfx2hlsl_smem_offset_check.pyok (0.1s),tests/startup_gfx2hlsl_sop2_complement_check.pyok (4.7s),tests/startup_gfx2hlsl_sopk_accum_check.pyok (0.6s),tests/startup_gfx2hlsl_sopk_signext_check.pyok (0.1s),tests/startup_gfx2hlsl_swap_check.pyok (0.2s),tests/startup_gfx2hlsl_vopc_sdwa_check.pyok (3.5s),tests/startup_gfx2hlsl_waitcnt_depctr_check.pyok (0.1s),tests/startup_gfx2hlsl_watch_check.pyok (2.3s),tests/startup_image_2d_array_check.pyok (0.1s),tests/startup_image_3d_check.pyok (0.1s),tests/startup_image_gather_lz_check.pyok (0.4s),tests/startup_image_load_d16_check.pyok (0.7s),tests/startup_image_sample_a16_check.pyok (0.1s),tests/startup_image_sample_b_check.pyok (0.1s),tests/startup_image_sample_c_check.pyok (0.2s),tests/startup_image_sample_l_check.pyok (0.1s),tests/startup_image_sample_lod_check.pyok (0.1s),tests/startup_inline_sampler_check.pyok (0.1s),tests/startup_run_ps1_check.pyok (7.9s),tests/startup_run_sh_check.pyFAIL (0.1s),tests/startup_sampler_heap_check.pyok (0.1s),tests/startup_smem_address_check.pyok (0.1s),tests/startup_stream_fetch_check.pyok (0.2s),tests/startup_stream_interface_check.pyok (0.2s),tests/startup_translator_check.pyok (0.3s)sccache: 0/2 hits; wall37.2sNote: tests/startup_run_sh_check.py returned the skip code (77, no POSIX shell on the VM); it is not touched by this PR.
AI-assisted; commands listed were executed locally.