Repository navigation
Conversation
…o a scalar branch there skips the rest find_local_exec_folds built the region's sub-CFG from edges inside the region only. An s_cbranch_scc0/scc1 (or any branch) from inside the region straight to the join lost that edge, so cfg_structure.structure placed the next block without a %pc guard and emit_folded_region ran it on the exit path too. Edges to the join now go to an exit node that is dropped from the tree. Test and design.md row added. AI-assisted.
|
Tested What I ran:
Code review:
|
Kam471
left a comment
There was a problem hiding this comment.
Ran this at a54ea0ee on Windows 11, RTX 5070 Ti.
tests/semantic/test_wave64_emulate_opt.py-> 23 tests, OK (5.7 s);git diff --checkclean. The newtest_folded_region_scalar_branch_to_join_skips_the_restcovers taken and not-takenscc0/scc1at 64 and 128 threads and asserts the region is still folded.- GPU emulated run,
LEONIDA_W64_EMULATE=1 run_gpu_tests.py --filter cs_w64xwith this translator -> 19/19 passed, includingcs_w64x_saveexec_b64,cs_w64x_mask_reuse(2),cs_w64x_sbarrier,cs_w64x_wg128_branches,cs_w64x_partial_scmp.
find_local_exec_folds now gives a sub_end exit node to edges into skip and drops that empty guard from the tree, so the blocks after an in-region scalar exit keep their %pc guard. With the old edge dropped, the test's four taken cases ran the rest of the region. No blocking issue; still not GPU-verified specifically for the exit sequence, as the row says.
|
Tested head
The scalar-branch join handling in the wave64 emulator matches the description. AI-assisted (Devin). |
|
Verified GPU, semantic & negative-control checks
AI-assisted (Gemini, Antigravity). |
whattheflop
left a comment
There was a problem hiding this comment.
AI-assisted Windows CPU check at a54ea0ee, uv CPython 3.12.13. The exact scalar-exit case matched all 768 lane words across the eight taken and fallthrough variants at 64 and 128 threads. All eight retained one dispatch switch case and passed Vulkan 1.2 spirv-val.
I inspected the generated modules before attempting the exact case on Radeon. The existing wave64 scheduler emits overlapping non-atomic workgroup stores in its initial clear and round reset. Those code paths predate this PR, and #4247 (SHADER-708) already addresses them. I submitted no GPU dispatches for these fixtures. This is CPU confirmation of the branch fix, with hardware verification of the exact sequence pending that scheduler change.
Flyander
left a comment
There was a problem hiding this comment.
Reviewed the control-flow exit handling and its regression cases; I found no additional correctness issue in this pass.
whattheflop
left a comment
There was a problem hiding this comment.
Follow-up to the CPU-only review. Scratch 619d84ef combines a54ea0ee with #4247 5f16276d on d0835dd9. On Windows Radeon iGPU (25.10.30.02), all eight exact early-exit variants completed with 768/768 lane words matching and zero GPU-assisted validation errors or race reports. This covers the 64- and 128-thread emulated case with #4247. Details in #166. AI-assisted.
|
Verdict: approve (nits only). The change is correct and the new test is a real regression test. Two checks I ran myself, in a clean worktree at
Why one exit node is exact rather than approximate: the region closure in Extra evidence: a loop inside the region with an early exit to the join fails on Nits:
AI-assisted review. |
Claimed in the coordination issue as: new SHADER item (claim comment)
What and why
Under
--wave64-emulate, a folded lane-locals_cbranch_execzregion could ignore a scalar branch that leaves the region early. Example:Native wave64 (structured and
--dispatch-loop) leaves v4 alone on every lane, as the ISA says. The emulated translation added 21 on every lane that entered the region, with subgroup size 32 or 64.Cause:
find_local_exec_foldsintools/wave64_emulate_opt.pybuilt the region's sub-CFG from the edges inside the region only. The inner block's edge toskip(the join) was dropped, socfg_structure.structuresaw a straight line and put the next block in with no%pcguard.emit_folded_regionstored the right%pcfor the branch and then ran the next block anyway.Fix: edges to the join now go to an exit node
sub_endin the sub-CFG, so later blocks of the region get their%pcguard._drop_tree_blockremoves the exit node from the tree before_unwrap_known_pc_guards, so it emits nothing. Regions without such an exit edge get the same tree as before, and the region is still folded (the test checks for one switch case).Found with a local differential: cf_diff-style wave64 programs (plus cross-lane leaves) translated as compute shaders, emulated vs native vs
tools/cf_ref.py. I minimized it from one program out of about 1,800.Tested
All on Linux x86_64, Python 3.13.5, on the CPU only. There is no GPU on this machine, so this is not GPU-verified.
test_folded_region_scalar_branch_to_join_skips_the_restintests/semantic/test_wave64_emulate_opt.py. It covers taken and not-takens_cbranch_scc0/scc1to the join at 64 and 128 threads on the file's barrier-checking workgroup interpreter, and it asserts that the region is still folded. Onmain(03b09a08) the 4 taken-branch subtests fail (for example122 != 1 : lane 3). With the fix the whole file passes (23 tests).python -m pytest testswith llvm-mc 22.1.8 and Debian spirv-tools on PATH: 13,895 passed and 11 failed. Those 11 are the same ones that fail onmainand are already claimed elsewhere:test_loop_ballot_barrier(tests: test_loop_ballot_barrier follows #2089's structured wave64 emulation (main red since 1cc7497b) #3995),test_mutationsv_mul_legacy anchor (tests/semantic: re-anchor the v_mul_legacy_f32 mutation after the flush change #3883),test_cmp_class_f64rejected forms (fix(rdna2spirv): route v_cmp(x)_class_f64 to cmp_class_f64 so malformed forms are rejected #3885/rdna2spirv: reject a modified class mask and a non-EXEC v_cmpx destination (TEST-853) #3948),test_u16_high_halfd16 spirv-val (rdna2spirv: register the buffer-format table constants before the dump #4466), andtest_fma_khr(FMAKHRis unknown to this older spirv-tools).test_loop_ballot_barrier.pywith this change: 15 passed.python -m compileall -q tools tests: clean.python -I make_game.py --help: OK.node --test tests/test_*.cjs: 47 passed.AI-assisted.
Checklist
docs/design.md, with how it was confirmed.