startup: lower s_waitcnt_depctr as a wait without effect in gfx2hlsl #2437
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2445"
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:00:21Z.
Refs #2413
What
tools/startup/gfx2hlsl.pyrefuseds_waitcnt_depctr. It now lowers it likes_nop.Why this is a no-op
S_WAITCNT_DEPCTR(SOPP 0x23, gfx10 and later) with one immediate operand and no register definition, use or side-effect flag:llvm/lib/Target/AMDGPU/SOPInstructions.td(release/15.x).GCNHazardRecognizer::fixVMEMtoScalarWriteHazardsinsertss_waitcnt_depctr 0xffe3before a scalar write that a pending memory instruction still reads (llvm/lib/Target/AMDGPU/GCNHazardRecognizer.cpp, release/15.x).The translator keeps no outstanding operation that a dependency counter could count, so the wait has nothing to change. I could not read the Mesa ACO notes (the host refused automated fetches), so this rests on the LLVM sources alone.
In the 298 local slot 57 mesh requests of #2413, every program contains this form; it is one of several refusals in each, so this change alone translates none of them.
Test
tests/startup_gfx2hlsl_waitcnt_depctr_check.py(pure Python, plus anllvm-mcencoding mode):s_wait_idle,s_sleepands_round_modestay refused;binary <llvm-mc>: the five encodings match LLVM 15.Commands and results (x64 Windows, Python 3, LLVM 15
llvm-mc):Registered as
startup_gfx2hlsl_waitcnt_depctrinCMakeLists.txt, in both workflow lists and inAGENTS.md. Not run through ctest; no GPU test is involved.Not covered
s_waitcnt lgkmcnt(0)between a store and its barrier; this wait does not replace it.tools/pixel_aot.pyand the bounded mesh lowerers are unchanged.🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T17:10:33Z.
The new entry is pinned; the older one in the same tuple is not
Baseline:
s_waitcnt_depctr: 5 immediates leave the translation unchanged; 3 neighbouring forms refused, exit 0.'s_waitcnt_depctr'removed's_waitcnt'removed (the pre-existing member)The first is what this PR is for, and it is caught in the way that matters: the fixture translates the reference program (
MOV, ADD), then the same program with the wait inserted at each of three positions, and comparesstage.lines, stage.sym, stage.used_s, stage.used_v, stage.exports, stage.masksfor equality with the plain run. That is a stronger assertion than "no line was emitted" — it also catches a wait that quietly touched a symbol, mask or export.The second survivor is pre-existing rather than introduced here, but it is worth knowing:
's_waitcnt'sits in the same tuple, has no case, and removing it changes nothing any check notices. If someone reshuffles that tuple, thes_waitcntentry can disappear silently.Two controls I would add, given how cheap the harness already is
s_waitcnt_depctrwith zero operands. The disassembler always prints the immediate, so a text entrys_waitcnt_depctralone is malformed. Today the op is handled through the no-op list, so I would expect it to be accepted and dropped — the same class of defect the rest of this tree now refuses (the guards in #2396/#2373/#2408). It is not covered here, and a one-line case would say which behaviour you intend.s_waitcnt_depctrwith a register operand.s_waitcnt_depctr s0cannot be encoded (LLVM defines it with one immediate, as the comment says); if the text entry accepts it silently, that is the same gap. If it refuses, the refusal is what should be asserted so it stays that way.The comparison-by-state assertion in
controls()is the part I would keep exactly as it is —state(moved) != state(plain)for an instruction with an effect is the negative control that stops the whole comparison from passing vacuously, and it is the one most fixtures of this shape omit.On the referenced model
The comment cites
SOPInstructions.td(S_WAITCNT_DEPCTR) andGCNHazardRecognizer.cpp(fixVMEMtoScalarWriteHazards) for "one immediate, no register definition, use or side effect", which is what makes "the model has no counter to wait on" defensible rather than an assumption. That is the right kind of citation for this decision, because it is the decision a reader will want to argue with.AI-assisted; both mutations and the read of the fixture were done locally on Windows 11 build 26300.9974.
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T17:11:12Z.
Follow-up measurement: the whole no-op family accepts any operand list, and that is one line away from being the same defect the rest of the tree refuses
Prompted by my own suggestion above (
s_waitcnt_depctrwith no operands), I measured every member of the tuple this PR edits, using the sameStage.__new__harness astests/startup_gfx2hlsl_readfirstlane_uniform_check.py:All fourteen are accepted and none emits a line. For a no-op that is harmless in the sense that nothing wrong is emitted — but it means the match is on the mnemonic alone, so
s_nop s0ors_waitcnt s0(neither of which can be encoded) translate as successfully as the canonical forms, and the refusal census counts them as handled instructions rather than as text the translator did not understand.That is the same shape as the operand-count work in #2396 and #2373: the ptx entry point accepts a form the ISA cannot produce, and the only cost of refusing is a line in a table.
A shape that stays out of everyone's way
If you would rather not grow this PR, the guard can live where the list is matched, keyed by the shapes the disassembler actually prints:
v_nopis the only zero-operand member, which is exactly the case a "one immediate" rule would get wrong — worth having in the dict rather than in the prose.Whether that belongs here or in a follow-up is your call; I am reporting the measurement rather than opening a competing PR that edits the same tuple mid-review.
AI-assisted; the fourteen cases were run locally on Windows 11 build 26300.9974.
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T17:12:00Z.
Correction to my own suggestion above: the shape table I proposed would break the existing fixtures
I checked what the tree's own fixtures spell before recommending anyone implement this, and the answer is that a strict per-mnemonic shape is wrong for three of the members:
So
NOOP_SHAPES = {'s_inst_prefetch': (1,), 's_setprio': (1,), …}from my previous comment would refuse forms this repository's own fixtures already emit (s_setpriobare,s_inst_prefetchbare). Any table has to allow those, which reduces the guard to "reject a register or an extra operand" — worth far less than the version I described, and not worth touching this tuple for in a PR whose subject is the depctr entry.I would rather retract the suggestion than have it implemented and then debugged against a red suite. What the measurement does still support is only the narrow claim:
s_nop s0ands_waitcnt s0are accepted today, and if you want them refused it has to be a form check (immediate vs register) rather than an operand count — the counts are already varied for legitimate reasons.Nothing about the depctr change itself changes: the entry, the state-comparison control and the three neighbouring refusals are all correct, and my earlier table stands.
AI-assisted; the fixture spellings above were counted over
tests/*.pyonmainat4b09d2be.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T18:32:34Z.
Review: COMMENTED
Review of head
1734479f(code and tests only, comment review).Checked
s_waitcnt_depctrjoins the existing no-op list next tos_waitcnt,s_nop,s_clause. That is the right sibling. The translator has no outstanding operation that a dependency counter could count, so treating it as a no-op fits the model. The LLVM references in the body are the only source for this (the author says so); I did not re-check them..github/workflows/windows.yml: two added test lines only. The PR's own CI run shows "Build and test on Windows" and "Run platform-independent Python checks on Linux" green on this head, so the added entries ran. I did not run CI myself.CMakeLists.txtandAGENTS.md: one test entry and one list line, matching sibling checks.Commands run (Linux, in a review worktree)
python3 -B tests/startup_gfx2hlsl_waitcnt_depctr_check.py: ok (5 immediates unchanged, 3 neighbouring forms refused). Thebinarymode needsllvm-mc-15, which is not installed here, so I did not run it.python3 tests/docs_links_check.py,python3 tests/bidi_controls_check.py,git diff --check origin/main...HEAD: cleans_waitcnt_depctrfrom the no-op list. The new check FAILS. Reverted.Notes for the maintainer
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-25T18:35:01Z.
Review: APPROVED
Approved at head
1734479f.s_waitcnt_depctrjoins the no-op tuple. It only delays the wave until the dependency counters reach their thresholds, and the translator models no outstanding operation a counter could count, so treating it ass_nopis right. The change only accepts a form that was refused before, so no stored translation changes and no cache revision bump is needed.Commands executed (Windows 11 build 26300, Python 3.13, llvm-mc 15.0.7)
s_waitcnt_depctr: 5 immediates leave the translation unchanged; 3 neighbouring forms refused.binarymode:s_waitcnt_depctr encodings match llvm-mc.main(222935b1, clean): the check passes.Negative control
's_waitcnt_depctr'from the tuple intools/startup/gfx2hlsl.py.gfx2hlsl.Unsupported: s_waitcnt_depctr. After reverting, it passes.@ChazY11's notes on operand shapes concern the pre-existing no-op tuple, and their own follow-up shows a strict shape table would break existing fixtures, so that is outside this PR.
Merge checks: required CI passed at this head. The
/O2and coverage skips come from explicit workflow conditions. There are no unresolved review threads and no dependencies.Note: #2447 carries the same commit and depends on this PR, so it will need a rebase once this lands.
AI-assisted; commands listed were executed locally.