Skip to content

Commit 2032b6d

Browse files
committed
Eliminate redundant refcounting in the JIT for BINARY_OP
1 parent 63cc125 commit 2032b6d

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

Python/bytecodes.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5113,7 +5113,7 @@ dummy_func(
51135113
assert(oparg <= NB_OPARG_LAST);
51145114
}
51155115

5116-
op(_BINARY_OP, (lhs, rhs -- res)) {
5116+
op(_BINARY_OP, (lhs, rhs -- res, l, r)) {
51175117
PyObject *lhs_o = PyStackRef_AsPyObjectBorrow(lhs);
51185118
PyObject *rhs_o = PyStackRef_AsPyObjectBorrow(rhs);
51195119

@@ -5123,10 +5123,13 @@ dummy_func(
51235123
ERROR_NO_POP();
51245124
}
51255125
res = PyStackRef_FromPyObjectSteal(res_o);
5126-
DECREF_INPUTS();
5126+
l = lhs;
5127+
r = rhs;
5128+
DEAD(lhs);
5129+
DEAD(rhs);
51275130
}
51285131

5129-
macro(BINARY_OP) = _SPECIALIZE_BINARY_OP + unused/4 + _BINARY_OP;
5132+
macro(BINARY_OP) = _SPECIALIZE_BINARY_OP + unused/4 + _BINARY_OP + POP_TOP + POP_TOP;
51305133

51315134
pure replicate(2:4) inst(SWAP, (bottom, unused[oparg-2], top --
51325135
bottom, unused[oparg-2], top)) {

Python/optimizer_bytecodes.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,10 @@ dummy_func(void) {
210210
sym_set_type(left, &PyFloat_Type);
211211
}
212212

213-
op(_BINARY_OP, (lhs, rhs -- res)) {
213+
op(_BINARY_OP, (lhs, rhs -- res, l, r)) {
214214
REPLACE_OPCODE_IF_EVALUATES_PURE(lhs, rhs, res);
215+
l = lhs;
216+
r = rhs;
215217
bool lhs_int = sym_matches_type(lhs, &PyLong_Type);
216218
bool rhs_int = sym_matches_type(rhs, &PyLong_Type);
217219
bool lhs_float = sym_matches_type(lhs, &PyFloat_Type);

0 commit comments

Comments
 (0)