Repository navigation
Conversation
blishko
force-pushed
the
ssa-cfg-permute-optimal-swaps
branch
from
November 12, 2026 15:04
c7fd775 to
d499cd4
Compare
blishko
force-pushed
the
ssa-cfg-permute-optimal-swaps
branch
2 times, most recently
from
November 13, 2026 14:09
1ce1cf6 to
1f5d893
Compare
blishko
marked this pull request as ready for review
November 13, 2026 14:10
blishko
force-pushed
the
ssa-cfg-permute-optimal-swaps
branch
from
November 13, 2026 14:11
1f5d893 to
1b1387c
Compare
blishko
force-pushed
the
ssa-cfg-permute-optimal-swaps
branch
from
November 13, 2026 14:32
1b1387c to
940932f
Compare
clonker
previously approved these changes
Nov 13, 2026
These tests only need to permute the source stack. They demonstrate that we are currently not optimal in these scenarios.
When implementing the actual permutation using swaps, we can take better advantage of identical values. Positions with equal values are interchangeable: we can exchange destinations of two positions holding equal values. We can take advantage of this in two ways, implemented as preprocessing of the permutation: - Minimize the support of the permutation by fixing positions that would end up with identical value. This decreases the number of elements that have to move. - Join cycles holding identical values to decrease the number of swaps. By swapping destination of two positions in different cycles holding identical values we effectively join two cycles into one. This decreases number of swaps by one for every join performed. Suggested by Opus 5.5 in the formalized version of the algorithm.
When preprocessing permutation to minimize cycles without top we are searching for same-value slots in different cycles. Previous implementation was worst-case qubic. For the new version we observe that once we find two non-fixed same-value indices `a` and `b`, we know that `a` and `b` will be in the same cycle: Either they already were, or we swap them and merge their cycles. We don't need to continue searching indices after `b` for the same `a`, we can directly continue with the next `a`. If there are more indices with the same value, they will be examined when `a` because the previous `b`. This means that for every `a` `sameCycle` will be called at most once, making the whole check quadratic in the worst case. (Though average case should be much better.)
blishko
force-pushed
the
ssa-cfg-permute-optimal-swaps
branch
from
November 14, 2026 21:22
885c794 to
961b00e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When implementing the actual permutation using swaps, we can take better
advantage of identical values.
Positions with equal values are interchangeable: we can exchange
destinations of two positions holding equal values.
We can take advantage of this in two ways, implemented as preprocessing
of the permutation:
end up with identical value. This decreases the number of elements
that have to move.
By swapping destination of two positions in different cycles holding
identical values we effectively join two cycles into one. This
decreases number of swaps by one for every join performed.
AI Disclosure
Suggested by Opus 5.5 in the formalized version of the algorithm.