Shaders: intersect compare bounds with existing range bounds in Ranges::edge_hi #2491

Open
github-bot wants to merge 1 commit from github-bot/gh-2491 into main AGit
Owner

@⁠reeledMarek on GitHub · 2026-11-25 14:48 UTC · original
reeledMarek:fix/shader-range-unbounded-compare → main · +42 −1 · 1 files · 1 commits · open

Problem

In crates/victory-shader/src/range.rs, Ranges::compare_bound() computes:

let h = self.operand_hi(inst, other);
Some(if below { h.saturating_sub(1) } else { h })

When other is unbounded (h == u32::MAX) and below is true (e.g. a < unknown or !(a >= unknown)), compare_bound() returns Some(u32::MAX - 1) instead of None.

In Ranges::edge_hi(), best then becomes u32::MAX - 1 != u32::MAX, so the fallback if best == u32::MAX { self.hi(a) } else { best } skips self.hi(a) and discards any tighter upper bound already proven on a (for example s0 = s2 & 3), causing relative moves (v_movrel*) to lose their proven index bound and fall back to the full VGPR range.

Fix

  • Return None from Ranges::compare_bound() when h == u32::MAX (unbounded compare operand).
  • Added synthetic regression test range::tests::compare_against_unbounded_operand_preserves_existing_bound covering both s_cmp_lt_u32 (taken edge) and s_cmp_ge_u32 (not-taken edge).

Verification

  • cargo test -p victory-shader --locked (145 passed, 0 failed)
  • cargo test -p xtask --locked (repository_passes_policy passed)
  • cargo clippy -p victory-shader --all-targets --locked --target x86_64-pc-windows-msvc -- -D warnings (0 warnings)
**@⁠reeledMarek** on GitHub · 2026-11-25 14:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/2491) `reeledMarek:fix/shader-range-unbounded-compare` → `main` · +42 −1 · 1 files · 1 commits · open ### Problem In `crates/victory-shader/src/range.rs`, `Ranges::compare_bound()` computes: ```rust let h = self.operand_hi(inst, other); Some(if below { h.saturating_sub(1) } else { h }) ``` When `other` is unbounded (`h == u32::MAX`) and `below` is `true` (e.g. `a < unknown` or `!(a >= unknown)`), `compare_bound()` returns `Some(u32::MAX - 1)` instead of `None`. In `Ranges::edge_hi()`, `best` then becomes `u32::MAX - 1 != u32::MAX`, so the fallback `if best == u32::MAX { self.hi(a) } else { best }` skips `self.hi(a)` and discards any tighter upper bound already proven on `a` (for example `s0 = s2 & 3`), causing relative moves (`v_movrel*`) to lose their proven index bound and fall back to the full VGPR range. ### Fix - Return `None` from `Ranges::compare_bound()` when `h == u32::MAX` (unbounded compare operand). - Added synthetic regression test `range::tests::compare_against_unbounded_operand_preserves_existing_bound` covering both `s_cmp_lt_u32` (taken edge) and `s_cmp_ge_u32` (not-taken edge). ### Verification - `cargo test -p victory-shader --locked` (145 passed, 0 failed) - `cargo test -p xtask --locked` (`repository_passes_policy` passed) - `cargo clippy -p victory-shader --all-targets --locked --target x86_64-pc-windows-msvc -- -D warnings` (0 warnings)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:07:20 +00:00
Author
Owner

@⁠cloph-dsp on GitHub · 2026-11-25 15:41 UTC · original

Independent local validation for PR #2491 (Windows, Rust 1.100.0/MSVC, head 98b0e07, no game data): cargo test --locked -p victory-shader --lib -> 249 passed, 0 failed, 3 ignored, exit 0; git diff --check clean. CPU-only regression run; synthetic compare-range scenario not replayed. AI-assisted (Hy4 flash). GPU/driver N/A for CPU tests.

**@⁠cloph-dsp** on GitHub · 2026-11-25 15:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/2491#issuecomment-7167238635) Independent local validation for PR #2491 (Windows, Rust 1.100.0/MSVC, head 98b0e07, no game data): `cargo test --locked -p victory-shader --lib` -> 249 passed, 0 failed, 3 ignored, exit 0; `git diff --check` clean. CPU-only regression run; synthetic compare-range scenario not replayed. AI-assisted (Hy4 flash). GPU/driver N/A for CPU tests.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 15:59 UTC · original · edited 2026-11-25 20:21 UTC

Automated triage for the maintainers.

Merge candidate. Ranges::edge_hi (crates/victory-shader/src/range.rs) now returns best.min(self.hi(a)) instead of falling back to self.hi(a) only when no compare fact was found. self.hi(a) bounds a on every edge, so taking the minimum is always sound. A compare against an unbounded or looser operand can no longer hide a tighter bound already proven on a, and v_movrel* indexing keeps its narrow VGPR range. The new test checks s_cmp_lt_u32 (taken edge) and s_cmp_ge_u32 (not-taken edge) against both an unbounded s3 and s3 = s4 & 255, with s0 = s2 & 3. I checked the instruction encodings by hand. The looser case would read far more than v8–v11 on main.

Reply to the author: this is the change the last triage asked for, including the bounded-but-looser test case. One small thing: the PR description still describes the earlier compare_bound change, so it's worth updating before merge.

CI: check passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 15:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/2491#issuecomment-7167500611) · edited 2026-11-25 20:21 UTC <!-- victory-triage v1 head=b7d4f762918c358ae5043debc40e4f664a80317a verdict=merge-candidate at=2026-11-25T20:18:54Z --> Automated triage for the maintainers. **Merge candidate.** `Ranges::edge_hi` (`crates/victory-shader/src/range.rs`) now returns `best.min(self.hi(a))` instead of falling back to `self.hi(a)` only when no compare fact was found. `self.hi(a)` bounds `a` on every edge, so taking the minimum is always sound. A compare against an unbounded or looser operand can no longer hide a tighter bound already proven on `a`, and `v_movrel*` indexing keeps its narrow VGPR range. The new test checks `s_cmp_lt_u32` (taken edge) and `s_cmp_ge_u32` (not-taken edge) against both an unbounded `s3` and `s3 = s4 & 255`, with `s0 = s2 & 3`. I checked the instruction encodings by hand. The looser case would read far more than v8–v11 on `main`. Reply to the author: this is the change the last triage asked for, including the bounded-but-looser test case. One small thing: the PR description still describes the earlier `compare_bound` change, so it's worth updating before merge. CI: `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠reeledMarek on GitHub · 2026-11-25 20:05 UTC · original

Updated to address the triage feedback:

  • Replaced the u32::MAX sentinel check in Ranges::edge_hi with best.min(self.hi(a)) and removed the h == u32::MAX special case in compare_bound, so both unbounded and bounded-but-looser compare operands preserve tighter existing bounds.
  • Expanded the unit test to cover both unbounded s3 and bounded-but-looser s3 = s4 & 255 compared against s0 = s2 & 3.
**@⁠reeledMarek** on GitHub · 2026-11-25 20:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/2491#issuecomment-7173173847) Updated to address the triage feedback: - Replaced the `u32::MAX` sentinel check in `Ranges::edge_hi` with `best.min(self.hi(a))` and removed the `h == u32::MAX` special case in `compare_bound`, so both unbounded and bounded-but-looser compare operands preserve tighter existing bounds. - Expanded the unit test to cover both unbounded `s3` and bounded-but-looser `s3 = s4 & 255` compared against `s0 = s2 & 3`.
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 15:08 UTC · original · reviewed

Independent verification on Windows, VICTORY_D3D12_WARP=1 (WARP only, no hardware GPU touched). Tested commit 98c0e07d45b914276940cacf216cdf8a2163ec15 (clean detached checkout).

  • cargo test -p victory-shader --locked --lib compare_against_unbounded — 1 passed, 0 failed, 0 ignored.
  • Mutation check: with the new h == u32::MAX early return disabled, the test fails, so it guards the change.
  • cargo test -p victory-shader --locked --lib — 248 passed, 0 failed, 3 ignored (the ignored ones are pre-existing).

Code read: before this change, an unbounded operand (u32::MAX) gave Some(u32::MAX - 1) for lt/ge-false. That is a Some, so it bypassed the existing self.hi(a) bound in edge_hi. Returning None falls back to the tighter bound. The only precision lost is a ge-false or lt compare against a literal 0xFFFFFFFF, which gave MAX-1 before. That is conservative and not meaningful. The test covers both polarities (lt/scc1 and ge/scc0). No problems found.

AI-assisted (Claude Code / Claude Sonnet 5.5)

**@⁠oni-swr** on GitHub · 2026-11-25 15:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/2491#pullrequestreview-6060181872) · **reviewed** Independent verification on Windows, `VICTORY_D3D12_WARP=1` (WARP only, no hardware GPU touched). Tested commit `98c0e07d45b914276940cacf216cdf8a2163ec15` (clean detached checkout). - `cargo test -p victory-shader --locked --lib compare_against_unbounded` — 1 passed, 0 failed, 0 ignored. - Mutation check: with the new `h == u32::MAX` early return disabled, the test fails, so it guards the change. - `cargo test -p victory-shader --locked --lib` — 248 passed, 0 failed, 3 ignored (the ignored ones are pre-existing). Code read: before this change, an unbounded operand (`u32::MAX`) gave `Some(u32::MAX - 1)` for `lt`/`ge`-false. That is a `Some`, so it bypassed the existing `self.hi(a)` bound in `edge_hi`. Returning `None` falls back to the tighter bound. The only precision lost is a `ge`-false or `lt` compare against a literal `0xFFFFFFFF`, which gave `MAX-1` before. That is conservative and not meaningful. The test covers both polarities (`lt`/scc1 and `ge`/scc0). No problems found. AI-assisted (Claude Code / Claude Sonnet 5.5)
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 18:42 UTC · original · approved these changes

Verified b7d4f762918c358ae5043debc40e4f664a80317a merged onto main (63bcca43) on Windows 11 x64:

  • best.min(self.hi(a)) in Ranges::edge_hi (crates/victory-shader/src/range.rs:212) soundly intersects existing upper bounds with proven unsigned compare facts across all predicates (lt/le/gt/ge/eq), operand orders, and saturating arithmetic, without letting looser or unbounded compare operands mask tighter bounds.
  • rustfmt --edition 2024 --check crates/victory-shader/src/range.rs: clean (exit 0).
  • cargo test -p xtask --locked policy::tests::repository_passes_policy: 1 passed (asset policy: 191 files ok).
  • cargo clippy --locked -p victory-shader --all-targets -- -D warnings: clean.
  • cargo test --locked -p victory-shader --lib range::: 4 passed, 0 failed (compare_against_looser_or_unbounded_operand_preserves_existing_bound passes).

Minor doc note: worth updating the PR description to match the edge_hi best.min(self.hi(a)) change. Ready to merge.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 18:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/2491#pullrequestreview-6079109651) · **approved these changes** Verified `b7d4f762918c358ae5043debc40e4f664a80317a` merged onto `main` (`63bcca43`) on Windows 11 x64: - `best.min(self.hi(a))` in `Ranges::edge_hi` (`crates/victory-shader/src/range.rs:212`) soundly intersects existing upper bounds with proven unsigned compare facts across all predicates (`lt`/`le`/`gt`/`ge`/`eq`), operand orders, and saturating arithmetic, without letting looser or unbounded compare operands mask tighter bounds. - `rustfmt --edition 2024 --check crates/victory-shader/src/range.rs`: clean (exit 0). - `cargo test -p xtask --locked policy::tests::repository_passes_policy`: `1 passed` (`asset policy: 191 files ok`). - `cargo clippy --locked -p victory-shader --all-targets -- -D warnings`: clean. - `cargo test --locked -p victory-shader --lib range::`: `4 passed, 0 failed` (`compare_against_looser_or_unbounded_operand_preserves_existing_bound` passes). Minor doc note: worth updating the PR description to match the `edge_hi` `best.min(self.hi(a))` change. Ready to merge.
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 19:51 UTC · original · approved these changes

LGTM — verified on Windows against origin/main (63bcca4).

  • Intersecting compare bounds with existing hi bounds in Ranges::edge_hi preserves tighter outer bounds when nested comparisons yield a looser bound.
  • cargo test -p victory-shader --lib range:: -- --test-threads=1: all passed.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 19:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/2491#pullrequestreview-6079793329) · **approved these changes** LGTM — verified on Windows against `origin/main` (`63bcca4`). - Intersecting compare bounds with existing `hi` bounds in `Ranges::edge_hi` preserves tighter outer bounds when nested comparisons yield a looser bound. - `cargo test -p victory-shader --lib range:: -- --test-threads=1`: all passed. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2491/head:github-bot/gh-2491'
git switch 'github-bot/gh-2491'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2491'
git switch 'github-bot/gh-2491'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2491'
git switch 'github-bot/gh-2491'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2491'
git switch 'main'
git merge --squash 'github-bot/gh-2491'
git switch 'main'
git merge --ff-only 'github-bot/gh-2491'
git switch 'main'
git merge 'github-bot/gh-2491'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2491
No description provided.