Skip to content

Interaction of refcount elimination and constant propagation is complex to handle #142764

Description

@Fidget-Spinner

Feature or enhancement

Proposal:

With refcount elimination, ops may have more than one output. E.g.

op(_BINARY_OP_ADD_INT, (lhs, rhs -- res))

is now

op(_BINARY_OP_ADD_INT, (lhs, rhs -- res, l, r))

This introduces a problem in the optimizer --- REPLACE_OPCODE_IF_EVALUATES_PURE cannot deal with >1 output.

The solution is not too complex:
Emit the op as _SWAP_TWO_LOAD_CONST_INLINE_BORROW, with signature:

op(_SWAP_TWO_LOAD_CONST_INLINE_BORROW, (res/4, lhs, rhs -- res, l, r))

and add the res to REPLACE_OPCODE_IF_EVALUATES_PURE to tell it which results to write to and check.
So
REPLACE_OPCODE_IF_EVALUATES_PURE(lhs, rhs)
becomes
REPLACE_OPCODE_IF_EVALUATES_PURE(lhs, rhs, res)

Then we have everything we need and can reuse the current code.

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs

Activity

  1. added a commit that references this issue on Jan 9, 2026
  2. added a commit that references this issue on Jan 12, 2026
  3. added a commit that references this issue on Feb 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)topic-JITtype-featureA feature request or enhancement

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions