gh-152215: Add uop peepholes for folded stack shuffles and adjacent guards#153035
Open
cocolato wants to merge 3 commits into
Open
gh-152215: Add uop peepholes for folded stack shuffles and adjacent guards#153035cocolato wants to merge 3 commits into
cocolato wants to merge 3 commits into
Conversation
cocolato
requested review from
Fidget-Spinner,
markshannon,
savannahostrowski and
tomasr8
as code owners
July 4, 2026 16:11
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.
This PR adds some small peephole helper functions to the cleanup phase of the
uop optimizer.It splits the existing
push/popcleanup operations into a helper function andadds a specific helper function for the stack reordering operations left over
from constant folding.
It also adds a helper that combines matching adjacent
TOSandNOSguardswith the same side exit.
On AArch64, this allows two float guards to reuse the loaded
_PyFloat_Typepointer, removing these instructions from the secondguard:
This reduces the stencil from 12 instructions (48 bytes) to 10 instructions
(40 bytes).
A generic stack simulator could perform more peephole optimizations, but for
now there don’t seem to be many examples that could be optimized, and it would
increase maintenance costs.