Skip to content

SSA CFG populate spill set in target size heuristic#16599

Open
clonker wants to merge 4 commits intodevelopfrom
ssa-cfg-avoid-spilling
Open

SSA CFG populate spill set in target size heuristic#16599
clonker wants to merge 4 commits intodevelopfrom
ssa-cfg-avoid-spilling

Conversation

@clonker
Copy link
Copy Markdown
Member

@clonker clonker commented Apr 15, 2026

In a next step, the heuristic should get the currently existing spill set as initial state.

  • add SpilledVariables type (map of SSACFG::ValueId → slot) and thread it through the SSA stack abstraction via Stack::setSpilledVariables / spilledVariables().
  • Stack::canBeFreelyGenerated becomes non-static and treats spilled values as freely materializable alongside literals, junk, and call return labels
  • teach StackShuffler to honor the spill set
    • Target constructor accepts the spill set and excludes spilled values from minCount and the liveOut tail count
    • requiredInTail returns false for spilled values (rematerializable)
    • relax the "liveOut fits into target" assertion when a spill set is wired up
    • skip deep swap/dup failures when the target slot can be freely generated
  • findOptimalTargetSize now iteratively retries shuffle, adding the StackTooDeep culprit to a local spill set each round; cost function penalizes spills with +1000 per spilled variable
  • extend StackShufflerTest with allowSpilling / initialSpilledSet parser keys, a pre-pass to compute the spill set, reporting of spilled values in the trace, and tail-set assertions that skip spilled IDs
  • few more shuffler tests related to spilling

depends a little bit on #16598 to deal with some emerging cycles. could theoretically also be stand-alone.

@clonker clonker added has dependencies The PR depends on other PRs that must be merged first experimental labels Apr 15, 2026
@clonker clonker force-pushed the ssa-cfg-avoid-spilling branch from ec931b8 to 96ce5c5 Compare April 16, 2026 06:57
@clonker clonker changed the base branch from improve-ssa-shuffler-fix-args-region to develop April 16, 2026 06:57
@clonker clonker marked this pull request as ready for review April 16, 2026 06:59
@clonker clonker requested a review from blishko April 16, 2026 06:59
@clonker clonker removed the has dependencies The PR depends on other PRs that must be merged first label Apr 16, 2026
Comment on lines +39 to +41
// (target)| v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16 v17 v18 v19 v20 |
// Status: MaxIterationsReached
// Spilled: {v1, v2, v4, v20}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#16598 solves this

clonker added 4 commits April 16, 2026 11:38
- allNecessarySlotsReachableOrFinal takes spill set into account
- target min counts / required in tail checks exclude spilled variables
@clonker clonker force-pushed the ssa-cfg-avoid-spilling branch from 96ce5c5 to 4d4f87d Compare April 16, 2026 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant