Commit Graph

9 Commits

Author SHA1 Message Date
4f958ab44b Merge origin/main into #2093 (carry prep)
tools/spirv_opt.py: both pinned_ids (main) and the SROA parameters (PR); main's id_type Result Type check kept after the PR's const_type check on null-zero loads; main's OpUndef/OpSpecConstant* const_type kept. tests/test_spirv_opt.py: both sets of new tests.

Co-authored-by: JARVIX <273200855+jarvixaiassistant-glitch@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 09:41:13 +01:00
00ed210a19 spirv_opt: scalar-replace surviving static Function arrays (SROA)
Split non-escaped, statically indexed Function-scope arrays (such as
%vgpr[256] and %sgpr[128] when no dynamic v_movrel*/s_movrel* indexing
exists) into per-slot scalar OpVariables for only the live slots
referenced after dominator-tree forwarding and DCE, eliminating the
monolithic array allocas and their static OpAccessChains.

Preserves arrays with dynamic indices, whole-array loads/stores,
escapes, decorations, non-null initializers, or negative/out-of-bounds
static indices; canonicalizes signed/unsigned constant indices with
equal value and rewrites multi-index OpAccessChains cleanly.
2026-11-28 09:12:41 +00:00
d9a6e2a58c test_spirv_opt: use OpShiftLeftLogical instead of invalid mixed-type OpBitFieldUExtract in fixture 2026-11-25 01:24:24 +01:00
fad7435bcd spirv_opt: enforce Result Type match on int/load folding and pin OpDecorateId operands from DCE 2026-11-25 00:40:43 +01:00
85d2fb7a1a spirv_opt: --passes below 1 is a usage error, not a silent no-op
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-23 20:56:09 +01:00
32a50c949e spirv_opt: enforce strict dominance for OpPhi folding and track OpDecorateId/String/GroupDecorate (#6557)
Squash-merged after diff review of PR #6557
2026-11-23 12:45:21 -06:00
4016daf669 spirv_opt: exclude Volatile and mixed-depth Function vars from local memory opts
Addresses standalone memory-aliasing review findings on PR #2298 (@duudiis):
- Signed/unsigned integer index canonicalization (%uint 0 vs %int 0) is already handled
  by keying static OpAccessChain slots on const_int_val[i][1]; now also require every
  static slot index to be in const_int_val (treating unparsed constants as dynamic).
- Mark any Function-scope variable touched by a Volatile OpLoad or OpStore as escaped
  so volatile accesses never observe stale forwarded values or killed prior stores.
- Mark any Function-scope variable accessed at mixed aggregate/subobject slot depths
  (e.g. both whole-array and element pointers) as escaped to prevent partial-overlap
  aliasing.
- Add regression tests for all four cases in tests/test_spirv_opt.py.
2026-11-22 21:21:05 +01:00
cf9b0e5920 spirv_opt: upgrade to dominator-tree CSE, single-pred/read-only forwarding, int folding, and trivial OpPhi
Upgrades tools/spirv_opt.py from strictly intra-block peephole optimization to a
sound dominator-tree + CFG optimizer (still stdlib-only, O(N) iterative DFS with
undo-logged scoped tables):
- Dominator-tree preorder CSE for OpAccessChain, pure ALU / GLSL.std.450 ops (with
  commutative operand canonicalization), and immutable Input / PushConstant OpLoads.
- Whole-function read-only Function-scope variable propagation (e.g. %active across
  all blocks when never stored, and never-stored static slots of zero-init arrays)
  plus single-predecessor CFG slot forwarding (e.g. %entry -> %blk0 and if/else arms).
- Integer/bit constant folding (into existing module constants) and algebraic
  identities, OpCompositeExtract(OpCompositeConstruct) folding, bool-mask OpSelect
  unwrapping, double OpLogicalNot cancellation, and canonicalized integer slot keys.
- Trivial OpPhi simplification (identical or self-referential incoming values) and
  dead Function-scope OpVariable elimination.

Verification:
- tests/test_spirv_opt.py: 8/8 OK (spirv-val Vulkan 1.2 + semantic wave execution)
- 295/295 runtime/test/shaders modules (202 native + 93 --wave64-emulate) pass
  spirv-val Vulkan 1.2: -37.8% lines (454,593 -> 282,810) and -38.2% binary words
  (2,101,639 -> 1,299,235), up to -85.2% on ps_vcmpx_forms (6,138 -> 910 lines).
- Full tests/semantic/ sweep (2,567 tests) with OPT_SPIRV=True: 0 execution/value
  mismatches (only 116 raw-SPIR-V text/regex/sabotage-anchor assertions).
2026-11-22 21:21:05 +01:00
267f2e00b0 spirv_opt: sound basic-block SPIR-V peephole optimizer (#884) 2026-11-22 21:21:04 +01:00