shader: pixel_aot masked regions — accept the s_mov_b64 close after s_and_saveexec_b64, then the s_andn2_b64 else branch #1308

Closed
opened 2026-11-24 07:43:40 +00:00 by MasterDomino · 8 comments
MasterDomino commented 2026-11-24 07:43:40 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-24T07:43:40Z.


I measured the shapes of the masked regions in one local input against what pixel_aot accepts today, and propose two small stages: a missing close form, then the else branch. Measurement and proposal only; no code yet.

Setup

  • upstream/main at f9710f64, Windows 11 (build 26300), LLVM 15.0.7 LLVM-C.dll (pixel_aot.disassemble).
  • One local input (12,101 PS records, the same population as #711; 12,000 disassemble, 101 are refused by LLVM). Aggregates only.
  • Structural scan in linear order. A region opens with s_and_saveexec_b{64,32} saved, … or with s_mov_b{64,32} saved, exec directly before a v_cmpx. It closes at the first s_or_b* exec, exec, saved or s_mov_b* exec, saved naming the same pair. A simple region has no other region opener and no branch other than s_cbranch_execz between its opener and its close. No reachability analysis.

Today

From #651, #957 and #976:

  • A region opened by s_and_saveexec_b64 must close with s_or_b64 exec, exec, saved.
  • A v_cmpx region may close with s_or_b64 or s_mov_b64 exec, saved.
  • One optional s_cbranch_execz directly after the opener must target the close (one skip per program, seen_skip).
  • There is no else and no nesting.

Measured

Close form. None of the 77,129 simple regions closes with s_or_b*. All close with s_mov_b* exec, saved:

opener if only if/else (s_andn2_b* exec, saved, exec)
s_and_saveexec_b64 22,511 regions / 4,523 records 18,026 / 2,075
v_cmpx after s_mov_b64 saved, exec 11,070 / 3,434 5,577 / 1,466
s_and_saveexec_b32 (wave32) 11,723 / 967 3,117 / 805
v_cmpx after s_mov_b32 saved, exec_lo (wave32) 4,681 / 976 424 / 221

6,298 records contain at least one simple region. So the wave64 s_and_saveexec_b64 opener from #651 never meets its accepted close in this input. After s_and_saveexec_b64, EXEC is a subset of the saved full mask, so s_mov_b64 exec, saved restores the same mask as s_or_b64 exec, exec, saved. The difference is SCC: s_mov_b64 leaves it, s_or_b64 writes it. #957 already models the v_cmpx + s_mov_b64 case.

Else. Across all regions, s_andn2_b64 exec, saved, exec occurs 43,832 times and s_andn2_b32 exec_lo, saved, exec_lo 6,282 times. In simple wave64 if/else regions, the two skips land as follows:

skip pattern (wave64, both openers) regions
s_cbranch_execz after the opener → the s_andn2 transition, and after the transition → the close 15,323
no skip 7,270
one skip only, or a skip landing elsewhere 1,010

After the transition, EXEC = saved & ~(then-lanes), which is the else lanes of the same condition. So an if/else needs no new condition, only a second set of per-lane selects on its negation.

Proposal

Stage A (smallest): accept s_mov_b64 exec, saved as the close of an s_and_saveexec_b64 region, the same close #957 accepts for v_cmpx. Since s_mov_b64 does not write SCC, the close leaves SCC as the region left it, instead of dropping it as after s_or_b64.

  • Fixtures: the existing mixed/full/empty masks with the s_mov_b64 close, with and without the skip.
  • Negative controls: a close from a different pair, a close before any region, and a reversed-polarity mutant that must mismatch.
  • LLVM 15 round trip of the labelled skip.

Stage B: admit one else per region. The s_andn2_b64 exec, saved, exec transition names the open region's pair, and an optional s_cbranch_execz after it targets the close.

  • Lowering: else-body reads see the pre-region values of registers the then-body wrote. At the close, each register merges as cond ? then : else, with the outer value where only one side wrote it.
  • Skips: allow the opener skip to target the transition instead of the close, and relax the one-skip-per-program rule to one skip per arm.
  • Same body gate as today (#976, #987 stages 1–3). No nesting.
  • Fixtures: per-lane values written in both arms, in one arm only, and read in the else arm after a then-arm write. Controls: a transition naming another pair, a second transition, and a mutant without the negation that must mismatch.

wave32 (exec_lo, _b32) stays out of both stages until the wave32 guest profile admits saved masks.

Caveat on impact

#1314 shows that the scan's translator verdict currently stops at unbound entry registers for almost every record. So I can count shapes but not records that the translator would accept after either stage. The counts above are the most I can claim. Fixtures would be source-written and LLVM-assembled, as for #651.

@R0Y00, does this split work for you? If so, I would take stage A first and propose B separately once A has merged.

Limits

  • One local input. Linear structural scan without control-flow analysis. Regions with nested openers or other branches are excluded from the shape tables, not analysed.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6577058486 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1315). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-24T07:43:40Z. --- I measured the shapes of the masked regions in one local input against what `pixel_aot` accepts today, and propose two small stages: a missing close form, then the else branch. Measurement and proposal only; no code yet. ## Setup - `upstream/main` at `f9710f64`, Windows 11 (build 26300), LLVM 15.0.7 `LLVM-C.dll` (`pixel_aot.disassemble`). - One local input (12,101 PS records, the same population as #711; 12,000 disassemble, 101 are refused by LLVM). Aggregates only. - Structural scan in linear order. A region opens with `s_and_saveexec_b{64,32} saved, …` or with `s_mov_b{64,32} saved, exec` directly before a `v_cmpx`. It closes at the first `s_or_b* exec, exec, saved` or `s_mov_b* exec, saved` naming the same pair. A **simple** region has no other region opener and no branch other than `s_cbranch_execz` between its opener and its close. No reachability analysis. ## Today From #651, #957 and #976: - A region opened by `s_and_saveexec_b64` must close with `s_or_b64 exec, exec, saved`. - A `v_cmpx` region may close with `s_or_b64` or `s_mov_b64 exec, saved`. - One optional `s_cbranch_execz` directly after the opener must target the close (one skip per program, `seen_skip`). - There is no else and no nesting. ## Measured **Close form.** None of the 77,129 simple regions closes with `s_or_b*`. All close with `s_mov_b* exec, saved`: | opener | if only | if/else (`s_andn2_b* exec, saved, exec`) | |---|---:|---:| | `s_and_saveexec_b64` | 22,511 regions / 4,523 records | 18,026 / 2,075 | | `v_cmpx` after `s_mov_b64 saved, exec` | 11,070 / 3,434 | 5,577 / 1,466 | | `s_and_saveexec_b32` (wave32) | 11,723 / 967 | 3,117 / 805 | | `v_cmpx` after `s_mov_b32 saved, exec_lo` (wave32) | 4,681 / 976 | 424 / 221 | 6,298 records contain at least one simple region. So the wave64 `s_and_saveexec_b64` opener from #651 never meets its accepted close in this input. After `s_and_saveexec_b64`, EXEC is a subset of the saved full mask, so `s_mov_b64 exec, saved` restores the same mask as `s_or_b64 exec, exec, saved`. The difference is SCC: `s_mov_b64` leaves it, `s_or_b64` writes it. #957 already models the `v_cmpx` + `s_mov_b64` case. **Else.** Across all regions, `s_andn2_b64 exec, saved, exec` occurs 43,832 times and `s_andn2_b32 exec_lo, saved, exec_lo` 6,282 times. In simple wave64 if/else regions, the two skips land as follows: | skip pattern (wave64, both openers) | regions | |---|---:| | `s_cbranch_execz` after the opener → the `s_andn2` transition, and after the transition → the close | 15,323 | | no skip | 7,270 | | one skip only, or a skip landing elsewhere | 1,010 | After the transition, EXEC = saved & ~(then-lanes), which is the else lanes of the same condition. So an if/else needs no new condition, only a second set of per-lane selects on its negation. ## Proposal **Stage A (smallest):** accept `s_mov_b64 exec, saved` as the close of an `s_and_saveexec_b64` region, the same close #957 accepts for `v_cmpx`. Since `s_mov_b64` does not write SCC, the close leaves SCC as the region left it, instead of dropping it as after `s_or_b64`. - Fixtures: the existing mixed/full/empty masks with the `s_mov_b64` close, with and without the skip. - Negative controls: a close from a different pair, a close before any region, and a reversed-polarity mutant that must mismatch. - LLVM 15 round trip of the labelled skip. **Stage B:** admit one else per region. The `s_andn2_b64 exec, saved, exec` transition names the open region's pair, and an optional `s_cbranch_execz` after it targets the close. - Lowering: else-body reads see the pre-region values of registers the then-body wrote. At the close, each register merges as `cond ? then : else`, with the outer value where only one side wrote it. - Skips: allow the opener skip to target the transition instead of the close, and relax the one-skip-per-program rule to one skip per arm. - Same body gate as today (#976, #987 stages 1–3). No nesting. - Fixtures: per-lane values written in both arms, in one arm only, and read in the else arm after a then-arm write. Controls: a transition naming another pair, a second transition, and a mutant without the negation that must mismatch. wave32 (`exec_lo`, `_b32`) stays out of both stages until the wave32 guest profile admits saved masks. ## Caveat on impact #1314 shows that the scan's translator verdict currently stops at unbound entry registers for almost every record. So I can count shapes but not records that the translator would accept after either stage. The counts above are the most I can claim. Fixtures would be source-written and LLVM-assembled, as for #651. @R0Y00, does this split work for you? If so, I would take stage A first and propose B separately once A has merged. ## Limits - One local input. Linear structural scan without control-flow analysis. Regions with nested openers or other branches are excluded from the shape tables, not analysed. AI-assisted.
R0Y00 commented 2026-11-24 08:01:41 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T07:57:10Z.


Please take Stage A first. Reuse the current wave64 structured-region checks and accept the MOV close only when it restores the exact saved pair. Keep the current skip target and prove that the MOV close leaves SCC unchanged, with an SCC consumer check if that state is observable in the profile. The mixed/full/empty mask cases, wrong-pair rejection and polarity control you propose fit this PR. Please leave the else transition for a separate review once this lands; the structural counts are useful for selecting fixtures.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7125555477 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1315#issuecomment-7125555477). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T07:57:10Z. --- Please take Stage A first. Reuse the current wave64 structured-region checks and accept the MOV close only when it restores the exact saved pair. Keep the current skip target and prove that the MOV close leaves SCC unchanged, with an SCC consumer check if that state is observable in the profile. The mixed/full/empty mask cases, wrong-pair rejection and polarity control you propose fit this PR. Please leave the else transition for a separate review once this lands; the structural counts are useful for selecting fixtures.
MasterDomino commented 2026-11-24 09:04:43 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-24T08:02:23Z.


Claiming Stage A only: accept s_mov_b64 exec, saved as the close of an s_and_saveexec_b64 region when it restores the exact saved pair, reusing the wave64 structured-region checks, current skip target unchanged, SCC unchanged across the MOV close (with an SCC consumer check if observable), mixed/full/empty masks, wrong-pair rejection and a polarity control. The else transition stays for a later review. I'll link the PR here.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7125653077 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1315#issuecomment-7125653077). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-24T08:02:23Z. --- Claiming Stage A only: accept `s_mov_b64 exec, saved` as the close of an `s_and_saveexec_b64` region when it restores the exact saved pair, reusing the wave64 structured-region checks, current skip target unchanged, SCC unchanged across the MOV close (with an SCC consumer check if observable), mixed/full/empty masks, wrong-pair rejection and a polarity control. The else transition stays for a later review. I'll link the PR here. AI-assisted.
MasterDomino commented 2026-11-24 09:04:43 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-24T08:12:29Z.


Stage A PR: https://github.com/R0Y00/Xbox2Windows/pull/1328. MOV close of the exact saved pair, same HLSL as the OR close, skip target unchanged; SCC is already untracked after the saveexec opener, so a reader after either close still rejects. WARP and RX 9070 XT: 18/18 cases pass, 4/4 mutants mismatch. Else transition not included.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7125854383 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1315#issuecomment-7125854383). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-24T08:12:29Z. --- Stage A PR: https://github.com/R0Y00/Xbox2Windows/pull/1328. MOV close of the exact saved pair, same HLSL as the OR close, skip target unchanged; SCC is already untracked after the saveexec opener, so a reader after either close still rejects. WARP and RX 9070 XT: 18/18 cases pass, 4/4 mutants mismatch. Else transition not included. AI-assisted.
R0Y00 commented 2026-11-24 09:04:46 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T08:34:39Z.


Stage A is on main as #1328 (bec0c399). I reran the EXEC and CMPX region draws on RTX 4060 Laptop and WARP, 4/4 CTests, with no skips. MOV restores the exact saved pair and the incorrect pair/skip and untracked SCC checks remain in place. Keeping this issue open for the proposed else transition and its separate validation.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7126303772 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1315#issuecomment-7126303772). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T08:34:39Z. --- Stage A is on main as #1328 (bec0c399). I reran the EXEC and CMPX region draws on RTX 4060 Laptop and WARP, 4/4 CTests, with no skips. MOV restores the exact saved pair and the incorrect pair/skip and untracked SCC checks remain in place. Keeping this issue open for the proposed else transition and its separate validation.
MasterDomino commented 2026-11-24 10:02:39 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-24T09:14:00Z.


With Stage A on main (#1328), here is the plan for Stage B, the else transition. I'd like your go-ahead before coding.

Scope

  • Transition: s_andn2_b64 exec, s[a:b], exec naming the open region's saved pair, wave64 only, at most one per region, for both openers (s_and_saveexec_b64 and s_mov_b64 s[a:b], exec + v_cmpx).
    • After it, EXEC is saved & ~(then-lanes), so the else lanes are the negation of the region's tracked condition. No new condition is needed.
    • s_andn2_b64 writes SCC from the new EXEC, which is untracked, so SCC is dropped at the transition.
  • Lowering:
    • Else-arm reads of a register the then-arm wrote see its pre-region value.
    • At the close, each register merges as cond ? then : else. Where only one arm wrote it, the other side is the outer value.
    • A register first defined in only one arm stays conditional, as today.
  • Close: unchanged: s_or_b64 exec, exec, s[a:b] or s_mov_b64 exec, s[a:b] of the same pair.
  • Skips:
    • An optional s_cbranch_execz directly after the opener must land exactly on the transition.
    • An optional one directly after the transition must land exactly on the close.
    • The one-skip-per-program rule (seen_skip) becomes one skip per arm.
    • In the local input this covers 15,323 of the 23,603 simple wave64 if/else regions (both skips) and 7,270 with no skip. 1,010 have one skip or a skip that lands elsewhere; those stay refused unless they fit the two rules above.
  • Body gate: unchanged for both arms (#976, #987 stages 1–3). No nesting, no wave32.

Tests

  • Draws (WARP + RX 9070 XT, mixed/full/empty masks, both openers, both closes, with and without skips):
    • a register written in both arms;
    • in the then-arm only;
    • in the else-arm only;
    • an else-arm read of a register the then-arm wrote, which must see the outer value.
  • Mutants that must mismatch:
    • the else arm using the un-negated condition;
    • the transition removed (else body runs on the then-lanes);
    • else-arm reads seeing the then-value.
  • Refused:
    • a transition naming another pair;
    • a second transition;
    • a transition before any region or after the close;
    • an opener skip landing on the close when a transition exists;
    • a transition skip landing elsewhere;
    • s_andn2_b32 exec_lo (wave32).
  • LLVM 15 binary round trip of the labelled two-skip form.

Does this split work for you? If so I'll take it.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7127133045 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1315#issuecomment-7127133045). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-24T09:14:00Z. --- With Stage A on main (#1328), here is the plan for Stage B, the else transition. I'd like your go-ahead before coding. ## Scope - **Transition:** `s_andn2_b64 exec, s[a:b], exec` naming the open region's saved pair, wave64 only, at most one per region, for both openers (`s_and_saveexec_b64` and `s_mov_b64 s[a:b], exec` + `v_cmpx`). - After it, EXEC is saved & ~(then-lanes), so the else lanes are the negation of the region's tracked condition. No new condition is needed. - `s_andn2_b64` writes SCC from the new EXEC, which is untracked, so SCC is dropped at the transition. - **Lowering:** - Else-arm reads of a register the then-arm wrote see its pre-region value. - At the close, each register merges as `cond ? then : else`. Where only one arm wrote it, the other side is the outer value. - A register first defined in only one arm stays conditional, as today. - **Close:** unchanged: `s_or_b64 exec, exec, s[a:b]` or `s_mov_b64 exec, s[a:b]` of the same pair. - **Skips:** - An optional `s_cbranch_execz` directly after the opener must land exactly on the transition. - An optional one directly after the transition must land exactly on the close. - The one-skip-per-program rule (`seen_skip`) becomes one skip per arm. - In the local input this covers 15,323 of the 23,603 simple wave64 if/else regions (both skips) and 7,270 with no skip. 1,010 have one skip or a skip that lands elsewhere; those stay refused unless they fit the two rules above. - **Body gate:** unchanged for both arms (#976, #987 stages 1–3). No nesting, no wave32. ## Tests - **Draws** (WARP + RX 9070 XT, mixed/full/empty masks, both openers, both closes, with and without skips): - a register written in both arms; - in the then-arm only; - in the else-arm only; - an else-arm read of a register the then-arm wrote, which must see the outer value. - **Mutants** that must mismatch: - the else arm using the un-negated condition; - the transition removed (else body runs on the then-lanes); - else-arm reads seeing the then-value. - **Refused:** - a transition naming another pair; - a second transition; - a transition before any region or after the close; - an opener skip landing on the close when a transition exists; - a transition skip landing elsewhere; - `s_andn2_b32 exec_lo` (wave32). - **LLVM 15 binary round trip** of the labelled two-skip form. Does this split work for you? If so I'll take it. AI-assisted.
R0Y00 commented 2026-11-24 10:02:39 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T09:18:32Z.


Please proceed with the single structured wave64 else region you outlined. Use the exact saved pair and verify both branch destinations on real instruction boundaries. Each arm starts from the appropriate pre-region state, and an operand missing on either reachable arm remains undefined at the join. SCC is unknown at the transition unless redefined; keep the current memory and side-effect refusals. The mixed/empty/full, skip and stale-then-value controls you listed cover the main distinctions.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7127235258 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1315#issuecomment-7127235258). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T09:18:32Z. --- Please proceed with the single structured wave64 else region you outlined. Use the exact saved pair and verify both branch destinations on real instruction boundaries. Each arm starts from the appropriate pre-region state, and an operand missing on either reachable arm remains undefined at the join. SCC is unknown at the transition unless redefined; keep the current memory and side-effect refusals. The mixed/empty/full, skip and stale-then-value controls you listed cover the main distinctions.
MasterDomino commented 2026-11-24 10:02:40 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-24T09:21:29Z.


Claiming Stage B as scoped: one structured wave64 else per region on the exact saved pair, both skip destinations checked on real instruction boundaries, each arm starting from the pre-region state, a register missing on either reachable arm undefined at the join, SCC unknown from the transition unless redefined, memory and side-effect refusals unchanged. I'll link the PR here.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7127300846 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1315#issuecomment-7127300846). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-24T09:21:29Z. --- Claiming Stage B as scoped: one structured wave64 else per region on the exact saved pair, both skip destinations checked on real instruction boundaries, each arm starting from the pre-region state, a register missing on either reachable arm undefined at the join, SCC unknown from the transition unless redefined, memory and side-effect refusals unchanged. I'll link the PR here. AI-assisted.
MasterDomino commented 2026-11-24 10:02:41 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-24T09:32:02Z.


Stage B PR: https://github.com/R0Y00/Xbox2Windows/pull/1371. One else per region on the exact saved pair, both openers and closes; each arm starts from the pre-region state, a register missing on either arm stays undefined at the join, skip targets checked on real boundaries (save → transition, transition → close), SCC unknown from the transition until redefined. WARP and RX 9070 XT: 48/48 if/else cases match, 3/3 mutants (no transition, reversed, stale-then) mismatch; 12/12 region CTests pass.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7127545070 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1315#issuecomment-7127545070). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-24T09:32:02Z. --- Stage B PR: https://github.com/R0Y00/Xbox2Windows/pull/1371. One else per region on the exact saved pair, both openers and closes; each arm starts from the pre-region state, a register missing on either arm stays undefined at the join, skip targets checked on real boundaries (save → transition, transition → close), SCC unknown from the transition until redefined. WARP and RX 9070 XT: 48/48 if/else cases match, 3/3 mutants (no transition, reversed, stale-then) mismatch; 12/12 region CTests pass. AI-assisted.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows#1308
No description provided.