Skip to content

Absorb redundant atom-only SSA ternaries#29544

Open
Kuhai9801 wants to merge 61 commits into
ProvableHQ:masterfrom
Kuhai9801:fix/29343-ternary-absorption-stacked
Open

Absorb redundant atom-only SSA ternaries#29544
Kuhai9801 wants to merge 61 commits into
ProvableHQ:masterfrom
Kuhai9801:fix/29343-ternary-absorption-stacked

Conversation

@Kuhai9801

@Kuhai9801 Kuhai9801 commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

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 SsaConstPropagation to:

  • track local bindings to atom-only ternaries
  • absorb true-branch and false-branch redundant nesting forms
  • require matching SSA conditions and matching retained arms
  • leave different conditions or different branch values unchanged
  • compare literal atoms as well as SSA path atoms

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_absorption
  • compiler/peephole/ternary_absorption
  • peephole unit coverage for atom operands and non-atom operands
  • compiler expectation updates for storage aggregate cases where non-atom generated-Aleo operands are no longer absorbed

Verification performed:

  • git diff --check
  • conflict-marker scan over changed files
  • merge simulation onto the SSA aggregate alias forwarding branch
  • CircleCI PR checks

Related PRs

Part of the #29343 optimizer cleanup series.

Related PRs:

@Kuhai9801 Kuhai9801 force-pushed the fix/29343-ternary-absorption-stacked branch from dc68e74 to 73d319b Compare June 26, 2026 12:32
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.

Collapse redundant Optional wrapping around storage vector access (option_lowering + ssa_const_propagation)

1 participant