Skip to content

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

@Fidget-Spinner

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 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions