diff options
author | Dennis Sweeney <36520290+sweeneyde@users.noreply.github.com> | 2022-03-25 16:13:19 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-25 16:13:19 (GMT) |
commit | cca43b7d64f47ea921d0f7a347ae1a839c5463c3 (patch) | |
tree | ed0908e033243be580acbee24140225ab5887ccf /Python | |
parent | d7163bb35d1ed46bde9affcd4eb267dfd0b703dd (diff) | |
download | cpython-cca43b7d64f47ea921d0f7a347ae1a839c5463c3.zip cpython-cca43b7d64f47ea921d0f7a347ae1a839c5463c3.tar.gz cpython-cca43b7d64f47ea921d0f7a347ae1a839c5463c3.tar.bz2 |
bpo-47053: Reduce deoptimization in BINARY_OP_INPLACE_ADD_UNICODE (GH-31318)
* Don't deopt if refcounts are too big
* Detect more at specialization time
Diffstat (limited to 'Python')
-rw-r--r-- | Python/ceval.c | 9 | ||||
-rw-r--r-- | Python/specialize.c | 6 |
2 files changed, 9 insertions, 6 deletions
diff --git a/Python/ceval.c b/Python/ceval.c index e1d961f..4824b19 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -2002,10 +2002,10 @@ handle_eval_breaker: PyObject *right = TOP(); DEOPT_IF(!PyUnicode_CheckExact(left), BINARY_OP); DEOPT_IF(Py_TYPE(right) != Py_TYPE(left), BINARY_OP); - DEOPT_IF(Py_REFCNT(left) != 2, BINARY_OP); _Py_CODEUNIT true_next = next_instr[INLINE_CACHE_ENTRIES_BINARY_OP]; int next_oparg = _Py_OPARG(true_next); - assert(_Py_OPCODE(true_next) == STORE_FAST); + assert(_Py_OPCODE(true_next) == STORE_FAST || + _Py_OPCODE(true_next) == STORE_FAST__LOAD_FAST); /* In the common case, there are 2 references to the value * stored in 'variable' when the v = v + ... is performed: one * on the value stack (in 'v') and one still stored in the @@ -2016,7 +2016,8 @@ handle_eval_breaker: DEOPT_IF(var != left, BINARY_OP); STAT_INC(BINARY_OP, hit); GETLOCAL(next_oparg) = NULL; - Py_DECREF(left); + assert(Py_REFCNT(left) >= 2); + Py_DECREF(left); // XXX never need to dealloc STACK_SHRINK(1); PyUnicode_Append(&TOP(), right); Py_DECREF(right); @@ -5378,7 +5379,7 @@ handle_eval_breaker: PyObject *lhs = SECOND(); PyObject *rhs = TOP(); next_instr--; - _Py_Specialize_BinaryOp(lhs, rhs, next_instr, oparg); + _Py_Specialize_BinaryOp(lhs, rhs, next_instr, oparg, &GETLOCAL(0)); DISPATCH(); } else { diff --git a/Python/specialize.c b/Python/specialize.c index ce091a2..720bc7f 100644 --- a/Python/specialize.c +++ b/Python/specialize.c @@ -1742,7 +1742,7 @@ binary_op_fail_kind(int oparg, PyObject *lhs, PyObject *rhs) void _Py_Specialize_BinaryOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr, - int oparg) + int oparg, PyObject **locals) { assert(_PyOpcode_Caches[BINARY_OP] == INLINE_CACHE_ENTRIES_BINARY_OP); _PyBinaryOpCache *cache = (_PyBinaryOpCache *)(instr + 1); @@ -1754,7 +1754,9 @@ _Py_Specialize_BinaryOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr, } if (PyUnicode_CheckExact(lhs)) { _Py_CODEUNIT next = instr[INLINE_CACHE_ENTRIES_BINARY_OP + 1]; - if (_Py_OPCODE(next) == STORE_FAST && Py_REFCNT(lhs) == 2) { + bool to_store = (_Py_OPCODE(next) == STORE_FAST || + _Py_OPCODE(next) == STORE_FAST__LOAD_FAST); + if (to_store && locals[_Py_OPARG(next)] == lhs) { _Py_SET_OPCODE(*instr, BINARY_OP_INPLACE_ADD_UNICODE); goto success; } |