8948 commits in all time Dec 26, 2025 06:12 – Mar 26, 2026 06:12 UTC
docs: add missing env vars to README and create .env.example
Git Commit 86482f44 Branch release/ak-v4 Document 2/36 ++ 6 --
achidlow puya
feat: add ordering op canonicalization to GVN
Recognize that a<b and b>a (and <=/>= variants, including bytes
comparisons) are equivalent by canonicalizing operand VNs in the
expression key. When the first operand VN is larger, swap operands
and mirror the predicate (< ↔ >, <= ↔ >=).

This follows the same approach as LLVM GVN and GCC's SCC-VN: sort
operand VNs and adjust the comparison predicate to match.

comparison_swaps test case: 78 → 54 bytes (-31%), 45 → 29 ops (-36%)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Git Commit 48d7604e Branch gvn Document 24/88 ++ 441 --
achidlow puya
chore: compile all
Git Commit e5c26f8f Branch gvn Document 25/671 ++ 635 --
achidlow puya
feat: extend GVN to eliminate redundant pure subroutine calls
InvokeSubroutine with target.pure and identical argument VNs now
receives the same value number, eliminating duplicate calls.
Catches redundant _puya_lib.bytes_.is_substring calls across
three test contracts.

Net impact: -72 bytes / -51 ops at O1.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Git Commit 161ea5f9 Branch gvn Document 70/830 ++ 2,542 --
achidlow puya
feat: add SCC-based phi congruence analysis to GVN
After hash-based numbering, build a phi dependency graph and find SCCs.
Within each non-trivial SCC, check if all phis have the same set of
external (non-SCC) argument VNs. If so, they're all congruent and can
be merged.

Catches patterns like phi(a,y)/phi(b,x) where a==b that hash-based
GVN misses due to back-edge conservatism. No impact on current test
suite (no such patterns exist), but zero-cost when not triggered.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Git Commit 1755db5e Branch gvn Document 1/78 ++ 3 --
achidlow puya
fix: improve GVN test coverage to 99%
- Fix phi_congruence test to exercise GVN redundant phi path (lines
  279-288) by using commutative operand order (a|b vs b|a) so the
  frontend keeps them as separate registers but GVN canonicalises them
  to the same VN
- Convert unreachable defensive guards to raise InternalError (arity
  mismatch, replacement cycle, multi-external-VN SCC, missing VN
  representative) — these are excluded from coverage via .coveragerc

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Git Commit 14c2050d Branch gvn Document 25/279 ++ 277 --
achidlow puya
test: add comparison_swaps test case for GVN ordering-op canonicalization
Test contract with inline=False subroutines that assert both directions
of each ordering comparison (a<b then b>a, a<=b then b>=a) for both
uint64 and BigUInt types. The redundant converse comparisons should be
eliminated once GVN learns to canonicalize swapped predicates.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Git Commit 43dc5f78 Branch gvn Document 53/4,510 ++ 0 --
achidlow puya
feat: add negation-aware comparison numbering to GVN
Recognize that !(a < b) has the same value as (a >= b) by tracking
which VNs were produced by comparison ops.  When GVN processes a !
intrinsic whose operand was a comparison, it returns the inverse
comparison's expression key instead, so the normal hash lookup
naturally matches any existing computation of the inverse.

Inverse pairs: < ↔ >=, > ↔ <=, == ↔ != (and b-prefixed variants).

Double negation (!(!x)) works automatically since !(comparison)
produces an inverse comparison key which is itself tracked.

negated_comparisons test case: 107 → 65 bytes (-39%), 71 → 41 ops (-42%)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Git Commit 54d2c065 Branch gvn Document 25/965 ++ 1,285 --
achidlow puya
test: add negated_comparisons test case for GVN inverse comparison numbering
Test contract with inline=False subroutines that assert a comparison
and the negation of its inverse (e.g. assert a < b, assert not (a >= b))
for all 6 inverse pairs, for both uint64 and BigUInt types.  The
negated assertions should be eliminated once GVN learns to recognise
!(comparison) as the inverse comparison.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Git Commit b7c6af1e Branch gvn Document 53/5,624 ++ 0 --
achidlow puya
refactor: simplify GVN replacement chain handling
Replace _resolve_transitive chain resolution with a validation assert.
Both the hash-based pass and SCC pass always replace with VN
representatives, which are never themselves replacement targets, so
chains cannot form. Asserting this invariant (via InternalError) is
safer than silently resolving — a chain would indicate a bug in the
replacement logic.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Git Commit ebed9c95 Branch gvn Document 1/9 ++ 14 --
achidlow puya
feat: add GVN-PRE infrastructure with recursive materialisation
Add Partial Redundancy Elimination module (gvn_pre.py) integrated into
the GVN pass. Flow: number -> PRE insert -> re-number -> eliminate.

Key components:
- ANTIC_IN/AVAIL_OUT dataflow analysis
- Recursive materialisation: when operands aren't available at the
  insertion point, recursively insert the expressions that produce them
- Dominance-aware leader lookup via idom tree
- Safety filter: only non-trapping ops can be inserted on new paths
- Critical edge splitting before insertion

Refactors GVN to separate _number_values from elimination so PRE can
hook between them.

Currently produces net regressions due to phi/split-block overhead
exceeding savings on cheap single-instruction ops. Needs filtering
to skip expressions where hoisting overhead exceeds the benefit.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Git Commit 718ac33f Branch gvn Document 2/524 ++ 4 --
achidlow puya
feat: add SCC-based phi congruence analysis to GVN
After hash-based numbering, build a phi dependency graph and find SCCs.
Within each non-trivial SCC, check if all phis have the same set of
external (non-SCC) argument VNs. If so, they're all congruent and can
be merged.

Catches patterns like phi(a,y)/phi(b,x) where a==b that hash-based
GVN misses due to back-edge conservatism.

Adds test_cases/phi_congruence with contracts exercising cross-assignment
loops (SCC size 2), triple rotation cycles (SCC size 3), and a
redundant phi pattern.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Git Commit 32d635c6 Branch gvn Document 54/7,449 ++ 1 --
achidlow puya
chore: disable GVN-PRE pending better insertion heuristics
PRE produces net regressions on current test suite: phi/stack overhead
exceeds savings for the cheap expressions that pass the safety filter.
Also fixes oscillation bugs (infinite optimizer loop from PRE insert
then GVN eliminate cycling).

Infrastructure remains in gvn_pre.py for future work. Key remaining
issues:
- Need heuristics to skip insertions where overhead > benefit
- Need robust no-op detection to prevent optimizer loop oscillation
- Critical edge splitting interacts poorly with the fixed-point loop

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Git Commit 787353a5 Branch gvn Document 2/17 ++ 32 --
achidlow puya
make test actually cover the case
Git Commit 69a2f9e0 Branch gvn Document 1/12 ++ 11 --
achidlow puya
feat: extend GVN to number pure zero-arg intrinsics
Remove the `and args` guard so GVN numbers immediate-only pure ops
like txn, txna, arg, etc. These are deterministic within a transaction
and frequently duplicated after inlining.

Net impact: -1177 bytes / -773 ops at O1 across the test suite.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Git Commit aa657d77 Branch gvn Document 300/101,488 ++ 142,728 --
achidlow puya
feat: extend GVN to handle multi-target assignments
Operations like addw and decode_bytes return multiple values. GVN now
numbers these by storing all target registers in the expression table,
enabling elimination of duplicate multi-return ops.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Git Commit d5661446 Branch gvn Document 118/2,557 ++ 3,001 --
achidlow puya
refactor: simplify GVN internals
- Remove unused get_register_vn method
- Replace save/restore full-dict-copy scoping with delta-based
  push_scope/pop_scope (tracks only keys added per scope)
- Extract _try_replace helper to unify replacement logic (4 call sites)
- Extract _index_vns helper for shared ExtractValue/ReplaceValue pattern
- Add _ScopeDelta attrs class and _Snapshot TypeAlias to eliminate
  repeated tuple type annotations

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Git Commit 38ba4d4d Branch gvn Document 1/95 ++ 93 --
achidlow puya
chore: compile all
Git Commit 448c11da Branch gvn Document 300/15,167 ++ 17,031 --
achidlow puya
disable CSE but retain redundant assert removal
Git Commit 88c79b54 Branch gvn Document 1/1 ++ 1 --
achidlow puya
chore: compile all
Git Commit d0d7e58c Branch gvn Document 300/21,013 ++ 6,459 --
achidlow puya
feat: add Global Value Numbering (GVN) optimization pass
Hash-based GVN that assigns canonical value numbers to SSA definitions
and eliminates redundant computations across the dominator tree.
Complements the existing CSE pass by catching deeper equivalences
(value identity through operand VNs, commutative reorderings,
redundant phis).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Git Commit ea070067 Branch gvn Document 2/433 ++ 0 --
gabrielkuettel devportal
fix: resolve deprecated API usage warnings in components
Git Commit 48866b75 Branch release/ak-v4 Document 3/11 ++ 20 --
gabrielkuettel devportal
fix: prefix unused parameters to resolve ts6133 warnings
Git Commit 695a5174 Branch release/ak-v4 Document 4/15 ++ 22 --
achidlow puya
chore: compile all
Git Commit 001737b3 Branch gvn Document 249/5,374 ++ 5,599 --
achidlow puya
eliminate repeated ArrayLength nodes when the argument is a stack value
Git Commit fbbd4db4 Branch gvn Document 1/10 ++ 1 --