Skip to content

gh-100239: Propagate type info through _BINARY_OP_EXTEND in tier 2#148146

Open
eendebakpt wants to merge 1 commit intopython:mainfrom
eendebakpt:binary_op_extend_types
Open

gh-100239: Propagate type info through _BINARY_OP_EXTEND in tier 2#148146
eendebakpt wants to merge 1 commit intopython:mainfrom
eendebakpt:binary_op_extend_types

Conversation

@eendebakpt
Copy link
Copy Markdown
Contributor

@eendebakpt eendebakpt commented Apr 5, 2026

Adds 2 new fields to _PyBinaryOpSpecializationDescr:

  • result_type: the static type of the result (or NULL).
  • result_unique: whether the action always returns a freshly allocated object (not aliased to either operand).

The tier 2 optimizer now narrows the result of _BINARY_OP_EXTEND symbol's type via sym_new_type(d->result_type) and wraps it in PyJitRef_MakeUnique when the result_unique field is set, enabling downstream tier2 optimizations. A test verifies that (2 + x) * y with x, y floats uses _BINARY_OP_MULTIPLY_FLOAT_INPLACE and elides _GUARD_NOS_FLOAT. With these changes the calculation of (2 + x) * y is now 35% faster.

The changes have been factored out of #128956.

Adds two new fields to _PyBinaryOpSpecializationDescr:

- result_type: the static type of the result (or NULL if unknown).
- result_unique: nonzero iff `action` always returns a freshly
  allocated object (not aliased to either operand).

The tier 2 optimizer now narrows the result symbol's type via
sym_new_type(d->result_type) and wraps it in PyJitRef_MakeUnique when
d->result_unique is set. This lets downstream ops elide their
operand-type guards and pick inplace variants. For example,
(2 + x) * y with x, y floats now compiles to
_BINARY_OP_MULTIPLY_FLOAT_INPLACE with _GUARD_NOS_FLOAT eliminated.

All existing descriptors populate both fields: long-long bitwise ops
produce unique PyLong results, and float/long mixed arithmetic
produces unique PyFloat results.

A test verifies the inplace-multiply case end-to-end.
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.

1 participant