gh-133672: Allow LOAD_FAST to be optimized to LOAD_FAST_BORROW#148999
Open
ljfp wants to merge 1 commit intopython:mainfrom
Open
gh-133672: Allow LOAD_FAST to be optimized to LOAD_FAST_BORROW#148999ljfp wants to merge 1 commit intopython:mainfrom
ljfp wants to merge 1 commit intopython:mainfrom
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
The
LOAD_FAST_BORROWinstruction loads a borrowed reference onto the operand stack, which is a performance optimization that avoids unnecessary reference counting operations.Previously, we were only applying this optimization when the reference was consumed within the same basic block. If the value was still on the stack at the end of a basic block (indicated by the
REF_UNCONSUMEDflag), we wouldn't perform the optimization.However, there are cases where it's safe to use
LOAD_FAST_BORROWeven when the value is still on the stack at the end of a basic block. The optimization is safe as long as every successor path preserves the supporting reference in the frame until the borrowed reference is consumed, including paths through exception handlers.This fix allows us to optimize more cases, which seems to be particularly important for the virtual iterators implementation (PR #132555) where the iterable for a loop is often live at basic block end.
Fixes gh-133672.
Supersedes gh-133721.