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/cfg_structure.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/cfg_structure.py')
| -rw-r--r-- | tools/cfg_structure.py | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/tools/cfg_structure.py b/tools/cfg_structure.py index 68522ec8b..9b7b41212 100644 --- a/tools/cfg_structure.py +++ b/tools/cfg_structure.py | |||
| @@ -80,7 +80,7 @@ def _dominators(rpo, preds): | |||
| 80 | return idom, pos | 80 | return idom, pos |
| 81 | 81 | ||
| 82 | 82 | ||
| 83 | def structure(succ): | 83 | def structure(succ, out_pcs=None): |
| 84 | rpo, back, preds = _order(succ) | 84 | rpo, back, preds = _order(succ) |
| 85 | idom, pos = _dominators(rpo, preds) | 85 | idom, pos = _dominators(rpo, preds) |
| 86 | 86 | ||
| @@ -158,7 +158,8 @@ def structure(succ): | |||
| 158 | out_list.append(("loop", x, lbody)) | 158 | out_list.append(("loop", x, lbody)) |
| 159 | else: | 159 | else: |
| 160 | out_list.append(("block", x)) | 160 | out_list.append(("block", x)) |
| 161 | if kind == "b" and len(below) == 1 and list(succ[x]) == [below[0][1]]: | 161 | if (kind == "b" and len(below) == 1 and list(succ[x]) == [below[0][1]] |
| 162 | and (out_pcs is None or set(out_pcs[x]) == {below[0][1]})): | ||
| 162 | stack.append(("emit", out_list, parent_list, below[0], depth)) | 163 | stack.append(("emit", out_list, parent_list, below[0], depth)) |
| 163 | else: | 164 | else: |
| 164 | hoist = (parent_list is not None and below | 165 | hoist = (parent_list is not None and below |