Skip to content

fix(kyty): fold constants through reachable shader phi inputs - #335

Merged
simnJS merged 2 commits into
simnJS:AnyKytyfrom
smecherucarbarou:pr/kyty-phi-reachability
Nov 26, 2026
Merged

simnJS merged 2 commits into
simnJS:AnyKytyfrom
smecherucarbarou:pr/kyty-phi-reachability

Conversation

@smecherucarbarou

Copy link
Copy Markdown
Contributor

What

Improve constant propagation by folding cyclic Phi nodes when all reachable incoming values agree on a constant.

This addresses cases where scalar registers are saved into VGPR lanes, temporarily reused, and restored across loops.

The implementation preserves genuinely reachable runtime values, conflicting constants, undef inputs, and cycles without a constant seed.

This is a preparatory change for a follow-up addressing #330.

Tested

Windows build 26300, Intel Core i7-10700, NVIDIA RTX 5060 Ti 8 GB, driver 621.24.

  • Both new regressions failed on 688dbf145d8 and passed with the patch.
  • All 11 focused regression tests passed.
  • The synthetic Vulkan sampler test returned the expected value of 1.0 in all 32 lanes.
  • Khronos Vulkan validation 1.4.363 reported zero VUID errors.
  • git diff --check passed.

Performance

Nine matched offline runs per build on the recovered compute shader:

Measurement Baseline Patched
Constant propagation 179.1 ms 195.4 ms
Time to resource tracking 304.1 ms 328.4 ms

Both builds still reproduce the original resource-tracking failure from #330. A separate predicate-correlation correction addresses that failure and will be submitted in a follow-up PR.

Tests were performed on the original implementation commit 2f4b5dfa1d. The submitted commit aa5a5ac0be was cherry-picked onto upstream 90a48455d2, with patch equivalence verified through git range-diff. Tests have not been rerun on the transplanted commit.

Checklist

  • Based on AnyKyty
  • One topic per PR
  • Generic behavior, not specific to one title
  • Regression coverage included
  • No unrelated compatibility patches
  • No proprietary game assets or shader bytecode included
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA RTX 5060 Ti, driver 621.24
  • AI-assisted: yes (OpenAI Codex, GPT-6.2)

@simnJS simnJS left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nested-loop cases cover the key distinctions in this fold. The sampler fixture compiles for a 32-lane host subgroup, but the guard only checks the maximum. Please require a native 32-lane subgroup or the ability to request one on compute. A usable Vulkan device without that capability should report a subgroup skip even when Vulkan is required. Please keep the GPU dispatch out of the sanitizer CPU selection, rerun the focused tests and validation on this head, and include a compile-time comparison on an unaffected shader alongside the reported case.

@smecherucarbarou

Copy link
Copy Markdown
Contributor Author

Thanks for the review! Addressed in 323a8be842.

  • The sampler fixture now requires native subgroup size 32 or explicit size-32 compute subgroup support.
  • Unsupported subgroup configurations return CTest skip code 77, even with ANYPS5_REQUIRE_VULKAN=1. Missing required Vulkan still fails.
  • The GPU dispatch is excluded from sanitizer CPU selection, while all seven focused CPU recompiler tests remain selected.

All 11 focused tests passed on the updated PR head, with zero Vulkan validation errors. The API trace confirmed requiredSubgroupSize = 32, and all 32 lanes returned the expected sample.

Native subgroup, unsupported subgroup, and unavailable Vulkan paths were also checked separately.

Performance results over 31 matched runs per build:

Shader Measurement Baseline PR Change
Reported shader Constant propagation 170.019 ms 165.809 ms -2.48%
Reported shader Time to resource tracking 296.584 ms 288.767 ms -2.64%
Unaffected control Constant propagation 9.401 ms 9.666 ms +2.82%
Unaffected control Complete compilation 41.998 ms 42.331 ms +0.79%

The unaffected control (0xa329f206873d2f47) was selected by median bytecode size among 145 Wave32 compute shaders before timing. Both builds emitted byte-identical, valid SPIR-V.

The original reported shader still stops at the same resource-tracking error on this PR, as expected. Predicate correlation remains a separate follow-up.

Sanitizer test selection was verified with ctest -N; the full sanitizer suite was not run.

AI-assisted: yes.

@simnJS simnJS left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed this revision and validated it together with the other changes in the integration branch. The Linux, Windows, sanitizer, and offline checks passed on the exact candidate.

@simnJS
simnJS merged commit 9c3dd1a into simnJS:AnyKyty Nov 26, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants