Absorb redundant atom-only SSA ternaries#29544
Open
Kuhai9801 wants to merge 61 commits into
Open
Conversation
This was referenced Jun 20, 2026
This reverts commit 8f8b063.
dc68e74 to
73d319b
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.
Motivation
Closes #29343.
Builds on the SSA const propagation alias-forwarding change.
After SSA and earlier simplification, nested ternaries can remain in the shape:
let tmp = cond ? a : b; return cond ? tmp : b;or the symmetric false-branch form. When both ternaries use the same SSA condition and the tracked arms are atom-only, the inner temporary can be absorbed without dropping fallible work.
This PR extends
SsaConstPropagationto:It also restricts generated-Aleo redundant ternary absorption to the same safety boundary by tracking prior ternaries only when the condition and arms are registers or literals. That prevents the peephole pass from substituting member-access, array-access, tuple, or raw-name operands from an earlier ternary into a later one.
Test Plan
Added/updated regression coverage:
ssa_const_propagation/nested_ternary_absorptioncompiler/peephole/ternary_absorptionVerification performed:
git diff --checkRelated PRs
Part of the #29343 optimizer cleanup series.
Related PRs: