From 344ee459b5711ee322bc300db4a4b03347130136 Mon Sep 17 00:00:00 2001 From: sweeneyde Date: Fri, 1 Apr 2022 14:14:41 -0400 Subject: [PATCH 1/2] Let PRECALL_NO_KW_LIST_APPEND do its own POP_TOP --- Python/ceval.c | 7 +++---- Python/specialize.c | 4 +++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Python/ceval.c b/Python/ceval.c index 43080f8db04226..210ae335185233 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -5038,15 +5038,14 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int PyObject *list = SECOND(); DEOPT_IF(!PyList_Check(list), PRECALL); STAT_INC(PRECALL, hit); - SKIP_CALL(); + // PRECALL + CALL + POP_TOP + JUMPBY(INLINE_CACHE_ENTRIES_PRECALL + 1 + INLINE_CACHE_ENTRIES_CALL + 1); PyObject *arg = POP(); if (_PyList_AppendTakeRef((PyListObject *)list, arg) < 0) { goto error; } + STACK_SHRINK(2); Py_DECREF(list); - STACK_SHRINK(1); - Py_INCREF(Py_None); - SET_TOP(Py_None); Py_DECREF(callable); NOTRACE_DISPATCH(); } diff --git a/Python/specialize.c b/Python/specialize.c index 08c69041e78b01..4d5666c1805fc8 100644 --- a/Python/specialize.c +++ b/Python/specialize.c @@ -1435,7 +1435,9 @@ specialize_method_descriptor(PyMethodDescrObject *descr, _Py_CODEUNIT *instr, } PyInterpreterState *interp = _PyInterpreterState_GET(); PyObject *list_append = interp->callable_cache.list_append; - if ((PyObject *)descr == list_append && oparg == 1) { + _Py_CODEUNIT next = instr[INLINE_CACHE_ENTRIES_BINARY_OP + 1]; + bool pop = (_Py_OPCODE(next) == POP_TOP); + if ((PyObject *)descr == list_append && oparg == 1 && pop) { _Py_SET_OPCODE(*instr, PRECALL_NO_KW_LIST_APPEND); return 0; } From e0adb6ab82c2d7a7d923c66302605d787ad58fe9 Mon Sep 17 00:00:00 2001 From: sweeneyde Date: Fri, 1 Apr 2022 16:43:17 -0400 Subject: [PATCH 2/2] Fix a copy/paste error --- Python/ceval.c | 1 + Python/specialize.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Python/ceval.c b/Python/ceval.c index 210ae335185233..57e6f0411379fe 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -5040,6 +5040,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int STAT_INC(PRECALL, hit); // PRECALL + CALL + POP_TOP JUMPBY(INLINE_CACHE_ENTRIES_PRECALL + 1 + INLINE_CACHE_ENTRIES_CALL + 1); + assert(next_instr[-1] == POP_TOP); PyObject *arg = POP(); if (_PyList_AppendTakeRef((PyListObject *)list, arg) < 0) { goto error; diff --git a/Python/specialize.c b/Python/specialize.c index 4d5666c1805fc8..36b05026489cfd 100644 --- a/Python/specialize.c +++ b/Python/specialize.c @@ -1435,7 +1435,8 @@ specialize_method_descriptor(PyMethodDescrObject *descr, _Py_CODEUNIT *instr, } PyInterpreterState *interp = _PyInterpreterState_GET(); PyObject *list_append = interp->callable_cache.list_append; - _Py_CODEUNIT next = instr[INLINE_CACHE_ENTRIES_BINARY_OP + 1]; + _Py_CODEUNIT next = instr[INLINE_CACHE_ENTRIES_PRECALL + 1 + + INLINE_CACHE_ENTRIES_CALL + 1]; bool pop = (_Py_OPCODE(next) == POP_TOP); if ((PyObject *)descr == list_append && oparg == 1 && pop) { _Py_SET_OPCODE(*instr, PRECALL_NO_KW_LIST_APPEND);