shader: pixel_aot forward branches on a scalar compare (s_cbranch_scc0/scc1) — scope question #1413
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows#1413
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@MasterDomino on GitHub · 2026-11-24 10:59 UTC · original
With masked regions now accepting the s_mov close and one else arm (#1328, #1371), I measured which control flow still separates the local pixel programs from
pixel_aot. Scalar-condition branches turn out to be much more common than deeper region nesting. This is a proposal and a scope question only; no code yet.Setup
upstream/mainat04e307cf, LLVM 15.0.7LLVM-C.dll(pixel_aot.disassemblewith offsets).What remains after #1371
s_cbranch_execzs_cbranch_vccnzs_cbranch_scc0s_cbranch_scc1s_branchs_cbranch_vcczForward SCC branches
SCC is written by scalar instructions, so a branch on it is taken or not taken by the whole wave. In this input it is almost always a scalar compare. Last SCC writer before the branch:
s_cmp_eq_*s_cmp_lg_*s_andn2_*s_cmp_lt_*s_cmp_gt_*s_cmp_eq_u64s_cmpk_eq_*s_cmp_ge_*pixel_aotalready tracks a compare's SCC as an HLSL bool (scc{i}, read bys_cselect/s_cmov).Shapes of the forward
s_cbranch_scc0/s_cbranch_scc1branches:s_branchover a branch-free second blockOf the 36,365 skip and diamond blocks, 11,348 contain only ALU and scalar work. 25,017 contain an image, buffer, scalar load or export, and 3,159 write EXEC.
Proposal
Stage 1: one forward
s_cbranch_scc0/s_cbranch_scc1over a branch-free block.s_cmp_*/s_cmpk_*result on tracked scalar operands. Any other or untracked SCC is refused.scc0/scc1, and the branch dropped.Later stages, each a separate review:
s_branch;ifinstead of selects;s_cbranch_vccz/vccnz, whose "any lane" meaning needs a uniformity argument first.Questions
ifblocks, so that later stages with samples share one lowering?If this direction works, I'd take stage 1.
Limits
AI-assisted.
@R0Y00 on GitHub · 2026-11-24 11:22 UTC · original
A single forward SCC-led skip is a good first PR. A select merge is fine for side-effect-free ALU that is safe to evaluate on either path. Start with vector writes so the first change can reuse the existing masked-region definedness checks. Require a tracked uniform scalar compare, the real forward target boundary, and an incoming definition for any VGPR later read after a conditional write. Keep memory, EXEC writes, observable scalar/wave updates and nesting out of this slice. The proposed polarity and dropped-branch controls, both directions with a runtime constant, and LLVM 15 round trip cover the key cases.
@MasterDomino on GitHub · 2026-11-24 11:23 UTC · original
Claiming stage 1 as scoped: one forward
s_cbranch_scc0/scc1skip over a vector-only block, a tracked uniforms_cmpSCC, the real forward target boundary, select merges with the existing masked-region definedness (an incoming definition required for any VGPR read after a conditional write), and memory, EXEC writes, scalar/wave updates and nesting kept out. Tests: both polarities and the dropped branch as mismatching controls, taken/not-taken through a runtime constant, LLVM 15 round trip. I'll link the PR here.AI-assisted.
@MasterDomino on GitHub · 2026-11-24 11:33 UTC · original
Stage 1 PR: #1440. Tracked
s_cmp/s_bitcmpSCC only, real forward target, vector-only block merged with selects on SCC/!SCC using the masked-region definedness (also checked at the target), SCC/VCC preserved. WARP and RX 9070 XT: 6/6 cases (flag 0/1/7 for both forms) match, 6/6 polarity and dropped-branch mutant cases mismatch; 14/14 region and skip CTests pass.AI-assisted.
@R0Y00 on GitHub · 2026-11-24 11:42 UTC · original
The single forward SCC skip landed in #1440 at
ea475f35. The Windows Release SCC-skip and existing EXEC-region fixtures passed on RTX 4060 Laptop and WARP (4/4, no skips). This covers one forward skip over vector ALU using a tracked uniform comparison, including the polarity and dropped-branch controls. The diamond and blocks with observable side effects remain outside this implementation.@MasterDomino on GitHub · 2026-11-24 11:44 UTC · original
With stage 1 on main (#1440), here is a plan for stage 2, the diamond. On the local input that shape is 9,004 branches in 3,201 records. I'd like your go-ahead before coding.
Shape
Scope
s_cmp/s_bitcmpSCC.s_branch. Thes_branchmust be the last instruction of block A and land after block B. A diamond whose conditional branch lands anywhere else stays a stage-1 skip or is refused.cond_A ? A : B, with the pre-branch value standing in for a block that did not write it. A register undefined before the branch and not written in both blocks stays undefined after JOIN.s_branchstay out.Tests
s_branchdropped (A falls through into B);s_branchor on JOIN;s_branchnot last in block A, landing inside block B, or going backward;Does this match what you want for stage 2? If so I'll take it.
AI-assisted.
@R0Y00 on GitHub · 2026-11-24 14:04 UTC · original
Go ahead with stage 2 as a single structured forward SCC if/else diamond on top of #1440. Reuse the tracked uniform
s_cmp/s_bitcmpcondition and the existing branch-target decoding. Both targets must be real instruction boundaries. The conditional edge must enter B immediately after A’s terminals_branch, and thats_branchmust land exactly at JOIN, after B. Keep both arms within the existing vector-only gate and preserve SCC, VCC, and EXEC. Leave nesting, backward branches, memory, waits, and other observable side effects out of this slice.Start both arms from the incoming VGPR state. Preserve an incoming value on any arm that leaves it alone. A value that was undefined on entry must be defined by both arms before a post-join read. Please keep both SCC polarities and runtime flags 0/1/7, the B-read-of-an-A-written register, the dropped-branch and flipped-polarity mutants, and the malformed-target rejection cases. Run the LLVM 15 round trip with both labels and report WARP and RX 9070 XT results separately.
@MasterDomino on GitHub · 2026-11-24 14:59 UTC · original
Claiming stage 2 as scoped (single forward SCC if/else diamond on top of #1440). PR link to follow.
AI-assisted.
@MasterDomino on GitHub · 2026-11-24 15:14 UTC · original
Stage 2 PR: #1625. WARP: 6/6 diamond cases match, 8/8 mutant cases (stale-A, flipped polarity, dropped s_branch) mismatch. RX 9070 XT (
32.0.31044.16): same, 6/6 and 8/8. LLVM 15 round trip with both labels passes; malformed targets, nesting and definedness controls incheck_scc_diamond_controls.AI-assisted.
@MasterDomino on GitHub · 2026-11-24 16:03 UTC · original
Stage 2 is on main (#1625). Before coding anything further, here are the measurements for the next step, and a question about order.
Source: one local input (12,101 PS records, the same population as #711; 12,000 disassemble), on stages 1+2 (
117ebb8b), LLVM 15.0.7. Aggregates only.What the remaining uniform SCC blocks contain
34,180 forward SCC blocks in 6,877 records: 25,176 skips (6,682 records) and 9,004 diamonds (3,201 records). Blocks that contain
s_endpgmare not counted.s_waitcnts_load_*s_buffer_load_*image_sample*buffer_load_*image_storeexp,buffer_stores_cmp/s_cmpk, except 12 blocks (6 records) ons_bcnt1_i32_b64.EXEC at the branch (linear estimate)
Two possible next slices
A. Scalar state inside a uniform skip or diamond, at entry mask.
REGION_SALUsubset._lz. 125 of them also needv_madak_f32, which the translator lowers butREGION_ALUdoes not admit.B. Uniform branches inside a WQM span or under partial EXEC.
Sampling inside an arm would be a later stage. It would be either a select over a speculative sample (static binding, defined derivatives) or an HLSL
ifwith the merged values declared before it.Would you prefer A first as the small, low-risk slice, or B directly? I'll wait for your answer before claiming.
AI-assisted.
@R0Y00 on GitHub · 2026-11-24 16:05 UTC · original
Stage 2 landed in #1625 at
874cc3fa. The SCC diamond controls are included in both serial and parallel form coverage, and the final head passed both Linux jobs and Windows. Independent RTX and WARP Release draws passed after resolving the test registration conflict. This covers the approved forward diamond. Further branch shapes still need separate evidence.