You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
LOAD_FAST_BORROW not being used even when safe to do so, if value is live at BB end. #133672
@markshannon I've created this PR to modify the optimization condition in Python/flowgraph.c. The goal is to allow LOAD_FAST to be optimized to LOAD_FAST_BORROW even when the reference is still on the stack at the end of a basic block (i.e., the REF_UNCONSUMED flag is set).
If I got this right, this should be safe as long as the reference is not killed (SUPPORT_KILLED flag isn't set) and not stored as a local (STORED_AS_LOCAL flag isn't set).
With these changes, y in your original example now correctly uses LOAD_FAST_BORROW:
I made a few mistakes with the previous PR, so I cleaned up the branch history and opened a replacement PR instead. The new PR should also address the failing tests from the earlier version.
Activity
markshannon commentedon May 8, 2025
@iritkatriel
@mpage
ljfp commentedon May 9, 2025
@markshannon I've created this PR to modify the optimization condition in
Python/flowgraph.c. The goal is to allowLOAD_FASTto be optimized toLOAD_FAST_BORROWeven when the reference is still on the stack at the end of a basic block (i.e., theREF_UNCONSUMEDflag is set).If I got this right, this should be safe as long as the reference is not killed (
SUPPORT_KILLEDflag isn't set) and not stored as a local (STORED_AS_LOCALflag isn't set).With these changes,
yin your original example now correctly usesLOAD_FAST_BORROW:Could you take a look when you have a moment and confirm if this aligns with what you had in mind?
pythongh-133672: Allow LOAD_FAST to be optimized to LOAD_FAST_BORROW
pythongh-133672: Allow LOAD_FAST to be optimized to LOAD_FAST_BORROW
pythongh-133672: Allow LOAD_FAST to be optimized to LOAD_FAST_BORROW
pythongh-133672: Allow LOAD_FAST to be optimized to LOAD_FAST_BORROW
pythongh-133672: Allow LOAD_FAST to be optimized to LOAD_FAST_BORROW
pythongh-133672: Allow LOAD_FAST to be optimized to LOAD_FAST_BORROW
ljfp commentedon Apr 26, 2026
@markshannon I opened a new PR for this in #148999.
I made a few mistakes with the previous PR, so I cleaned up the branch history and opened a replacement PR instead. The new PR should also address the failing tests from the earlier version.
pythongh-133672: Allow LOAD_FAST to be optimized to LOAD_FAST_BORROW