shader: lower s_cmov_b32, s_cmov_b64 and s_cmovk_i32 in the direct compute path #3071
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3071"
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 legacy-code-archaeologist on 2026-11-27T14:07:13Z.
Lowers
s_cmov_b32,s_cmov_b64(SOP1) ands_cmovk_i32(SOPK) in the direct C++ compute path (src/gfx1013_direct_compute.inl), addsreads_scctracking inuses_scc_after(), and clears constant/symbolic state ons_cmovk_i32intransfer()(src/gfx1013_compute_native.cpp).Differences vs
tools/startup/gfx2hlsl.pyscalar_cmovgfx2hlsl.pyrefusesvccand lane-mask operands and accepts only an aligned SGPR pair fors_cmov_b64S0.vccass_cmov_b64destination, wave32vcc_lo/vcc_hion the 32-bit forms, and inline integers (-16..64, sign-extended) or 32-bit literals (pair_high()zero-extension) ons_cmov_b64.Verification
Measured on Windows 10.0.26100 (
devpreset) onupstream/main429f11d5+ this commit:ctest --preset dev --no-tests=error -R '^native_salu_cmov_' -V:native_salu_cmov_ir(passed): dumps DXIL IR vianative_compute_ir_dumpfor all 24 cases (SCC=0andSCC=1across 12 forms including wave32vcc_hidst/src,vccdst,-1234,0x7FFF,-1, and0x80000001), evaluates lane 0 to verifyD = SCC ? S0 : D, preservedSCC, untouched neighbors, and sign-extended-1234(4294966062vs64302); verifies thetransfer()s_cmovk_i32baseline + exact-pc+0x10refusal and 11 destination/source refusals (including 3 no-epilogue symbolic-descriptor dst cases at exact pc+0x20).native_salu_cmov_controls(passed): compiles all 12 accepted forms viacompile_dxil, verifies thetransfer()baseline + all 12 exact-pc/diagnostic refusals, and checks 5 reference mutants.native_salu_cmov_hardware(skipped, exit77): Quadro M1000M does not support shader model 6.6 with wave32, so GPU readback (including the unmeasured0x80000001literal high word) is not measured on hardware here.ctest --preset dev --no-tests=error -R '^native_.*_(controls|ir)$' --output-on-failure: 47/47 passed.python -B tests/docs_links_check.py: passed (102 Markdown files, 590 links).ignores_scc,inverted_select,writes_nothing,zero_ext_cmovk,keeps_old_high_word, and droppings_cmovk_i32fromtransfer()) each failednative_salu_cmov_ir.Fixes #3070
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-27T18:01:51Z.
Thanks for this. The lowering reads cleanly: operands are read before the writes, the immediate is sign-extended
as in
s_movk_i32, and the encodings in the fixture disassemble as named.I ran
native_salu_cmov_check.py controlsagainst a few deliberately broken builds ofcompile_dxil:s_cmovk_i32zero-extends;s_cmov_b64keeps the old high word.All five still pass
controls. A build that accepts anexecdestination fails, as it should. I think the reasonis that
controlsonly checks'select i1' in dump. Every program fromcompute_program()already has seven ofthose (the closing
s_cselect_b32 s26, 1, 0and the lane-masked vector moves), even with nos_cmovlowering atall. The "5 reference mutants differ" step compares the Python reference with itself. The real assertions are in
hardware, which skipped on your machine and doesn't run in CI. As far as I can tell,D = SCC ? S0 : Disn'tchecked anywhere that runs. Could you add one of these?
native_f16_alu_check.py irdoes withnative_compute_ir_dump) asserting the selectoperand order, the sign-extended
-1234and thes_cmov_b64high word.hardwarerun on a GPU with SM 6.6 wave32, reported with adapter, driver, commit and debug-layer status.Smaller points:
hardware. Compiling each incontrolswould catch a later changethat refuses one:
s_cmov_b32from an SGPR or1.0;s_cmov_b64from-1or a literal;vccas thes_cmov_b64destination;vcc_hi.0x80000001literal case is the one where zero and sign extension differ. LLVM encodes0x80000001and0xffffffff80000001identically, so only a measurement or an ISA reference settles it.s_cmovk_i32entry intransfer()also keeps the suite green. A control that observes it, or anote that it is precautionary, would help.
scalar_cmovingfx2hlsl.pyrefusesvccand lane-mask operands, and takes only an SGPR pair as the 64-bitsource. The direct path accepts more, so "matching" in the doc and commit could say what differs.
reads_sccentries don't change the liveness result: these instructions were already treated as SCCreaders through
uncertain_scalar. Keeping them is fine.comes from the epilogue when there is no
s_cmov.transfer()condition.This comment was AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-27T18:13:10Z.
@JohnConnorNPC Thank you for the detailed review and for testing those broken lowerings! Addressed all points in rebased commit
9ec0c0a6onupstream/main(429f11d5):native_salu_cmov_ir): Addedirmode intests/native_salu_cmov_check.py(registered intests/cmake/native_salu_cmov.cmakeusingnative_compute_ir_dump) that evaluates lane 0 across all 24 cases (SCC=0andSCC=1for all 12 accepted forms). It verifiesD = SCC ? S0 : D, preservedSCC, untouched neighbor words, thes_cmov_b64high word, and sign-extended-1234(4294966062present and64302absent in the IR). Verified locally that all five broken builds you listed (ignore SCC, inverted select, write nothing, zero-extendeds_cmovk_i32, kept old high word ons_cmov_b64) now failnative_salu_cmov_ir(exit1). (native_salu_cmov_hardwarestill skips with77on Quadro M1000M — no SM 6.6 wave32 GPU here.)controls:controlsnow compiles all 12 accepted forms viacompile_dxil(s_cmov_b32SGPR/literal/1.0/wave32vcc_hidst & src,s_cmovk_i32-1234/0x7FFF/wave32vcc_hidst,s_cmov_b64pair/-1/0x80000001/vccdst).0x80000001ons_cmov_b64: Documented indocs/experiments/native-direct-salu-cmov.mdthat 32-bit literal zero-extension comes frompair_high()(consistent withs_mov_b64,s_cselect_b64,s_not_b64, ands_lshr_b64) and remains unmeasured on SM 6.6 wave32 hardware here.s_cmovk_i32intransfer(): Added an observable baseline + negative control wheres_mov_b32 s21, 0->s_cmovk_i32 s21, 1is followed bys_load_dwordx4 s[32:35], s[20:21], 0x20(refused at+0x10withdirect descriptor address outside bound table). Droppings_cmovk_i32fromtransfer()causes this check to failnative_salu_cmov_ir(exit1).gfx2hlsl.pyscalar_cmov: Updated the commit message anddocs/experiments/native-direct-salu-cmov.mdto spell out the differences instead of saying "matching", and noted the existinguncertain_scalarcoverage forreads_scc.s_cmov_b64,s_cmov_b32,s_cmovk_i32) and assertednative compute +0x20: unbound numeric SGPR s24, and rebased ontoupstream/main429f11d5(resolving thetransfer()context overlap with#3091).Verification on Windows 10.0.26100 (
devpreset):native_salu_cmov_irandnative_salu_cmov_controlspass;native_salu_cmov_hardwareskips (77); all 47native_*_(controls|ir)tests pass;python -B tests/docs_links_check.pypasses (102 files, 590 links).AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-27T20:32:50Z.
Review: APPROVED
I reviewed
9ec0c0a6merged intomain2e74b778(tree44389212, clean merge). This includes the hardware run JohnConnorNPC asked for in option 2.What I traced.
s_cmov_b64with overlapping source and destination is safe.vcc_hi(107) as destination and source.s_cmov_b64acceptsvcc(106) or an even SGPR pair, and takes inline or literal sources throughpair_high().s_cmovk_i32sign-extends viaint16_t, ass_movk_i32does.transfer()now clearss_cmovk_i32destinations along withs_movk's neighbours.What I ran. I built
compile_dxil native_store_replay native_compute_ir_dumpindevandrelease, then ran:ctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^native_salu_cmov_'native_salu_cmov_hardwareran and passed: all 24 cases reportresult words, preserved SCC and guards matched. That covers 12 forms × SCC 0/1, including wave32vcc_hisource and destination,vccas destination,-1234and the0x80000001literal.Mutants (in
src/gfx1013_direct_compute.inl, rebuilt each time):_ir_hardwareselect(cond, old_lo, next))s_cmov_b64keeps the old high word('cmov64 pair SCC=1', (0, 2309737967, 3735928559), (2309737967, 19088743))_controlspasses in both cases, as expected for a compile-only check. Restored, all pass, andgit diff --checkis clean.Still unmeasured: whether gfx1013 zero- or sign-extends a 32-bit literal in
s_cmov_b64. The hardware run shows only that the lowering matches the PR's reference, which followspair_high()(zero-extension). Settling it needs RDNA 2 hardware or an ISA statement.Verdict: approve on
9ec0c0a6.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 Windowspasses on9ec0c0a6. There are no review threads.This reply was AI-assisted.