Skip to content

Commit 3884cc2

Browse files
committed
Eliminate redundant refcounting in the JIT for BINARY_OP
1 parent acd784a commit 3884cc2

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

Python/bytecodes.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5119,7 +5119,7 @@ dummy_func(
51195119
assert(oparg <= NB_OPARG_LAST);
51205120
}
51215121

5122-
op(_BINARY_OP, (lhs, rhs -- res)) {
5122+
op(_BINARY_OP, (lhs, rhs -- res, l, r)) {
51235123
PyObject *lhs_o = PyStackRef_AsPyObjectBorrow(lhs);
51245124
PyObject *rhs_o = PyStackRef_AsPyObjectBorrow(rhs);
51255125

@@ -5129,10 +5129,13 @@ dummy_func(
51295129
ERROR_NO_POP();
51305130
}
51315131
res = PyStackRef_FromPyObjectSteal(res_o);
5132-
DECREF_INPUTS();
5132+
l = lhs;
5133+
r = rhs;
5134+
DEAD(lhs);
5135+
DEAD(rhs);
51335136
}
51345137

5135-
macro(BINARY_OP) = _SPECIALIZE_BINARY_OP + unused/4 + _BINARY_OP;
5138+
macro(BINARY_OP) = _SPECIALIZE_BINARY_OP + unused/4 + _BINARY_OP + POP_TOP + POP_TOP;
51365139

51375140
pure replicate(2:4) inst(SWAP, (bottom, unused[oparg-2], top --
51385141
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)