Skip to content

gh-144540: Add _MAKE_HEAP_SAFE uop to eliminate unnecessary refcount operations in RETURN_VALUE and YIELD_VALUE#144414

Open
cocolato wants to merge 4 commits intopython:mainfrom
cocolato:optimize/add_RETURN_VALUE_HEAP_SAFE
Open

gh-144540: Add _MAKE_HEAP_SAFE uop to eliminate unnecessary refcount operations in RETURN_VALUE and YIELD_VALUE#144414
cocolato wants to merge 4 commits intopython:mainfrom
cocolato:optimize/add_RETURN_VALUE_HEAP_SAFE

Conversation

@cocolato
Copy link
Contributor

@cocolato cocolato commented Feb 3, 2026

Split RETURN_VALUE and YIELD_VALUE into macro form with a new _MAKE_HEAP_SAFE micro-op,
so the tier2 optimizer can eliminate unnecessary PyStackRef_MakeHeapSafe() calls
when the value is already heap-safe (owned or immortal).

@markshannon markshannon changed the title gh-144388: Add new uop _RETURN_VALUE_HEAP_SAFE to avoid refcount operation gh-144540: Add new uop _RETURN_VALUE_HEAP_SAFE to avoid refcount operation Feb 6, 2026
@markshannon
Copy link
Member

@cocolato in future can you avoid referencing the meta-issue in PRs. Make a new issue if you need to. I've done that for this PR already.

@markshannon
Copy link
Member

The removal of the "heap safe" check can be done for any return and for yields as well.
If we split the instructions into micro-ops it makes the optimizations simpler and more effective.
#144540

@cocolato cocolato changed the title gh-144540: Add new uop _RETURN_VALUE_HEAP_SAFE to avoid refcount operation gh-144540: Split RETURN_VALUE/YIELD_VALUE into _MAKE_HEAP_SAFE + micro-ops Feb 6, 2026
@cocolato cocolato changed the title gh-144540: Split RETURN_VALUE/YIELD_VALUE into _MAKE_HEAP_SAFE + micro-ops Add uop to eliminate unnecessary refcount operations in RETURN_VALUE and YIELD_VALUE Feb 6, 2026
@cocolato cocolato changed the title Add uop to eliminate unnecessary refcount operations in RETURN_VALUE and YIELD_VALUE gh-144540: Add uop to eliminate unnecessary refcount operations in RETURN_VALUE and YIELD_VALUE Feb 6, 2026
@cocolato cocolato changed the title gh-144540: Add uop to eliminate unnecessary refcount operations in RETURN_VALUE and YIELD_VALUE gh-144540: Add _MAKE_HEAP_SAFE uop to eliminate unnecessary refcount operations in RETURN_VALUE and YIELD_VALUE Feb 6, 2026
@cocolato
Copy link
Contributor Author

cocolato commented Feb 6, 2026

@cocolato in future can you avoid referencing the meta-issue in PRs. Make a new issue if you need to. I've done that for this PR already.

Sorry about that, and thanks for letting me know! I've updated the code.

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.

2 participants