diff options
| author | whoalin1 <207920491+whoalin1@users.noreply.github.com> | 2026-11-24 23:56:36 +0200 |
|---|---|---|
| committer | whoalin1 <207920491+whoalin1@users.noreply.github.com> | 2026-11-25 03:41:00 +0200 |
| commit | 8e5cf5aef1942811bc6e377077b8dc8f388ff8fc (patch) | |
| tree | b71201c0323af882a783ad0504a12cd2e7f7e569 /tools/wave64_emulate_opt.py | |
| parent | 53ef382d7097290ecb1387f2400eaa7d134585b6 (diff) | |
fix(rdna2spirv): include END in out_pcs for trailing conditional branches
A conditional branch in the last basic block (no fallthrough block, so
len(raw_edges[b]) == 1) emits OpSelect(%cond, tgt, len(blocks)) and can
leave %pc at either tgt or cfg_structure.END.
Compute exact per-block out_pcs in rdna2spirv._block_out_pcs (matching
wave64_emulate_opt), pass it through capped_tree() into both
cfg_structure.structure() (so single-target fall-off-the-end blocks also
keep their dominated target guard) and unwrap_known_pc_guards(), and
pass compact_out_pcs into cfg_structure.structure() in wave64_emulate_opt.
Add unit and semantic regression tests covering both the loop back-edge
repro reported in review and the non-loop dominated-target variant.
Co-Authored-By: Gemini 4 Neon <noreply@google.com>
Diffstat (limited to 'tools/wave64_emulate_opt.py')
| -rw-r--r-- | tools/wave64_emulate_opt.py | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/tools/wave64_emulate_opt.py b/tools/wave64_emulate_opt.py index d41f5575c..4b5212721 100644 --- a/tools/wave64_emulate_opt.py +++ b/tools/wave64_emulate_opt.py | |||
| @@ -1549,23 +1549,26 @@ def plan_structured_emulation(blocks, raw_edges, succ, folds, fold_chain, absorb | |||
| 1549 | eff_succ[b] = nxt | 1549 | eff_succ[b] = nxt |
| 1550 | eff_succ_compact.append([eff_idx[s] for s in nxt]) | 1550 | eff_succ_compact.append([eff_idx[s] for s in nxt]) |
| 1551 | 1551 | ||
| 1552 | compact_tree = cfg_structure.structure(eff_succ_compact) | ||
| 1553 | if compact_tree is None: | ||
| 1554 | return None | ||
| 1555 | tree = _map_tree_ids(compact_tree, eff_blocks) | ||
| 1556 | |||
| 1557 | out_pcs = {} | 1552 | out_pcs = {} |
| 1558 | for b in eff_blocks: | 1553 | for b in eff_blocks: |
| 1559 | tail = chain_of[b][-1] | 1554 | tail = chain_of[b][-1] |
| 1560 | s = set(eff_succ[b]) | 1555 | s = set(eff_succ[b]) |
| 1561 | if not s: | 1556 | if not s: |
| 1562 | s.add(-1) | 1557 | s.add(cfg_structure.END) |
| 1563 | elif tail not in folds and len(raw_edges[tail]) == 1: | 1558 | elif tail not in folds and len(raw_edges[tail]) == 1: |
| 1564 | last = active_blocks[tail][-1] if active_blocks[tail] else None | 1559 | last = active_blocks[tail][-1] if active_blocks[tail] else None |
| 1565 | op = base_op(last["op"]) if last is not None else None | 1560 | op = base_op(last["op"]) if last is not None else None |
| 1566 | if op in BRANCHES and op != "s_branch": | 1561 | if op in BRANCHES and op != "s_branch": |
| 1567 | s.add(-1) | 1562 | s.add(cfg_structure.END) |
| 1568 | out_pcs[b] = frozenset(s) | 1563 | out_pcs[b] = frozenset(s) |
| 1564 | compact_out_pcs = { | ||
| 1565 | eff_idx[b]: frozenset(eff_idx[p] if p != cfg_structure.END else cfg_structure.END for p in pcs) | ||
| 1566 | for b, pcs in out_pcs.items() | ||
| 1567 | } | ||
| 1568 | compact_tree = cfg_structure.structure(eff_succ_compact, out_pcs=compact_out_pcs) | ||
| 1569 | if compact_tree is None: | ||
| 1570 | return None | ||
| 1571 | tree = _map_tree_ids(compact_tree, eff_blocks) | ||
| 1569 | tree = _unwrap_known_pc_guards(tree, out_pcs, eff_blocks[0]) | 1572 | tree = _unwrap_known_pc_guards(tree, out_pcs, eff_blocks[0]) |
| 1570 | 1573 | ||
| 1571 | # Precompute per-superblock instruction summaries (for dirty transfer, sync-free check, s_barrier, s_endpgm). | 1574 | # Precompute per-superblock instruction summaries (for dirty transfer, sync-free check, s_barrier, s_endpgm). |