From b1e6958b82f380686e0f7a1d167617e4c09cc642 Mon Sep 17 00:00:00 2001 From: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Date: Fri, 23 Feb 2024 18:05:38 +0800 Subject: [PATCH 1/3] Improve method information in redundancy eliminator --- Python/tier2_redundancy_eliminator_bytecodes.c | 6 +++--- Python/tier2_redundancy_eliminator_cases.c.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Python/tier2_redundancy_eliminator_bytecodes.c b/Python/tier2_redundancy_eliminator_bytecodes.c index ef7b43d53539ce..e071ff85f95bef 100644 --- a/Python/tier2_redundancy_eliminator_bytecodes.c +++ b/Python/tier2_redundancy_eliminator_bytecodes.c @@ -297,17 +297,17 @@ dummy_func(void) { op(_LOAD_ATTR_METHOD_WITH_VALUES, (descr/4, owner -- attr, self if (1))) { OUT_OF_SPACE_IF_NULL(attr = sym_new_known_notnull(ctx)); - OUT_OF_SPACE_IF_NULL(self = sym_new_known_notnull(ctx)); + self = owner; } op(_LOAD_ATTR_METHOD_NO_DICT, (descr/4, owner -- attr, self if (1))) { OUT_OF_SPACE_IF_NULL(attr = sym_new_known_notnull(ctx)); - OUT_OF_SPACE_IF_NULL(self = sym_new_known_notnull(ctx)); + self = owner; } op(_LOAD_ATTR_METHOD_LAZY_DICT, (descr/4, owner -- attr, self if (1))) { OUT_OF_SPACE_IF_NULL(attr = sym_new_known_notnull(ctx)); - OUT_OF_SPACE_IF_NULL(self = sym_new_known_notnull(ctx)); + self = owner; } op(_INIT_CALL_BOUND_METHOD_EXACT_ARGS, (callable, unused, unused[oparg] -- func, self, unused[oparg])) { diff --git a/Python/tier2_redundancy_eliminator_cases.c.h b/Python/tier2_redundancy_eliminator_cases.c.h index ca9b5953d21012..613000af767a7e 100644 --- a/Python/tier2_redundancy_eliminator_cases.c.h +++ b/Python/tier2_redundancy_eliminator_cases.c.h @@ -1306,7 +1306,7 @@ owner = stack_pointer[-1]; PyObject *descr = (PyObject *)this_instr->operand; OUT_OF_SPACE_IF_NULL(attr = sym_new_known_notnull(ctx)); - OUT_OF_SPACE_IF_NULL(self = sym_new_known_notnull(ctx)); + self = owner; stack_pointer[-1] = attr; stack_pointer[0] = self; stack_pointer += 1; @@ -1320,7 +1320,7 @@ owner = stack_pointer[-1]; PyObject *descr = (PyObject *)this_instr->operand; OUT_OF_SPACE_IF_NULL(attr = sym_new_known_notnull(ctx)); - OUT_OF_SPACE_IF_NULL(self = sym_new_known_notnull(ctx)); + self = owner; stack_pointer[-1] = attr; stack_pointer[0] = self; stack_pointer += 1; @@ -1354,7 +1354,7 @@ owner = stack_pointer[-1]; PyObject *descr = (PyObject *)this_instr->operand; OUT_OF_SPACE_IF_NULL(attr = sym_new_known_notnull(ctx)); - OUT_OF_SPACE_IF_NULL(self = sym_new_known_notnull(ctx)); + self = owner; stack_pointer[-1] = attr; stack_pointer[0] = self; stack_pointer += 1; From 25c6b532c0a74d5e11430090813ddd34f94ebff4 Mon Sep 17 00:00:00 2001 From: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Date: Fri, 23 Feb 2024 18:15:48 +0800 Subject: [PATCH 2/3] Address review again --- Python/optimizer_analysis.c | 6 ------ Python/tier2_redundancy_eliminator_bytecodes.c | 6 +++++- Python/tier2_redundancy_eliminator_cases.c.h | 6 +++++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Python/optimizer_analysis.c b/Python/optimizer_analysis.c index 9503dcc74656cd..e7f75201357f4c 100644 --- a/Python/optimizer_analysis.c +++ b/Python/optimizer_analysis.c @@ -259,12 +259,6 @@ sym_is_known(_Py_UOpsSymType *sym) return sym_has_flag(sym, KNOWN); } -static inline bool -sym_is_not_null(_Py_UOpsSymType *sym) -{ - return (sym->flags & (IS_NULL | NOT_NULL)) == NOT_NULL; -} - static inline bool sym_is_null(_Py_UOpsSymType *sym) { diff --git a/Python/tier2_redundancy_eliminator_bytecodes.c b/Python/tier2_redundancy_eliminator_bytecodes.c index e071ff85f95bef..86a63f90828f1c 100644 --- a/Python/tier2_redundancy_eliminator_bytecodes.c +++ b/Python/tier2_redundancy_eliminator_bytecodes.c @@ -296,21 +296,25 @@ dummy_func(void) { } op(_LOAD_ATTR_METHOD_WITH_VALUES, (descr/4, owner -- attr, self if (1))) { + (void)descr; OUT_OF_SPACE_IF_NULL(attr = sym_new_known_notnull(ctx)); self = owner; } op(_LOAD_ATTR_METHOD_NO_DICT, (descr/4, owner -- attr, self if (1))) { + (void)descr; OUT_OF_SPACE_IF_NULL(attr = sym_new_known_notnull(ctx)); self = owner; } op(_LOAD_ATTR_METHOD_LAZY_DICT, (descr/4, owner -- attr, self if (1))) { + (void)descr; OUT_OF_SPACE_IF_NULL(attr = sym_new_known_notnull(ctx)); self = owner; } op(_INIT_CALL_BOUND_METHOD_EXACT_ARGS, (callable, unused, unused[oparg] -- func, self, unused[oparg])) { + (void)callable; OUT_OF_SPACE_IF_NULL(func = sym_new_known_notnull(ctx)); OUT_OF_SPACE_IF_NULL(self = sym_new_known_notnull(ctx)); } @@ -340,7 +344,7 @@ dummy_func(void) { assert(self_or_null != NULL); assert(args != NULL); - if (sym_is_not_null(self_or_null)) { + if (!sym_is_null(self_or_null)) { // Bound method fiddling, same as _INIT_CALL_PY_EXACT_ARGS in VM args--; argcount++; diff --git a/Python/tier2_redundancy_eliminator_cases.c.h b/Python/tier2_redundancy_eliminator_cases.c.h index 613000af767a7e..a66afd9670f792 100644 --- a/Python/tier2_redundancy_eliminator_cases.c.h +++ b/Python/tier2_redundancy_eliminator_cases.c.h @@ -1305,6 +1305,7 @@ _Py_UOpsSymType *self = NULL; owner = stack_pointer[-1]; PyObject *descr = (PyObject *)this_instr->operand; + (void)descr; OUT_OF_SPACE_IF_NULL(attr = sym_new_known_notnull(ctx)); self = owner; stack_pointer[-1] = attr; @@ -1319,6 +1320,7 @@ _Py_UOpsSymType *self = NULL; owner = stack_pointer[-1]; PyObject *descr = (PyObject *)this_instr->operand; + (void)descr; OUT_OF_SPACE_IF_NULL(attr = sym_new_known_notnull(ctx)); self = owner; stack_pointer[-1] = attr; @@ -1353,6 +1355,7 @@ _Py_UOpsSymType *self = NULL; owner = stack_pointer[-1]; PyObject *descr = (PyObject *)this_instr->operand; + (void)descr; OUT_OF_SPACE_IF_NULL(attr = sym_new_known_notnull(ctx)); self = owner; stack_pointer[-1] = attr; @@ -1380,6 +1383,7 @@ _Py_UOpsSymType *func; _Py_UOpsSymType *self; callable = stack_pointer[-2 - oparg]; + (void)callable; OUT_OF_SPACE_IF_NULL(func = sym_new_known_notnull(ctx)); OUT_OF_SPACE_IF_NULL(self = sym_new_known_notnull(ctx)); stack_pointer[-2 - oparg] = func; @@ -1424,7 +1428,7 @@ PyCodeObject *co = (PyCodeObject *)func->func_code; assert(self_or_null != NULL); assert(args != NULL); - if (sym_is_not_null(self_or_null)) { + if (!sym_is_null(self_or_null)) { // Bound method fiddling, same as _INIT_CALL_PY_EXACT_ARGS in VM args--; argcount++; From 7193651c54c00eb45838b97c6f01060f033a2ad0 Mon Sep 17 00:00:00 2001 From: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Date: Fri, 23 Feb 2024 19:13:29 +0800 Subject: [PATCH 3/3] revert --- Python/optimizer_analysis.c | 6 ++++++ Python/tier2_redundancy_eliminator_bytecodes.c | 2 +- Python/tier2_redundancy_eliminator_cases.c.h | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Python/optimizer_analysis.c b/Python/optimizer_analysis.c index e7f75201357f4c..9503dcc74656cd 100644 --- a/Python/optimizer_analysis.c +++ b/Python/optimizer_analysis.c @@ -259,6 +259,12 @@ sym_is_known(_Py_UOpsSymType *sym) return sym_has_flag(sym, KNOWN); } +static inline bool +sym_is_not_null(_Py_UOpsSymType *sym) +{ + return (sym->flags & (IS_NULL | NOT_NULL)) == NOT_NULL; +} + static inline bool sym_is_null(_Py_UOpsSymType *sym) { diff --git a/Python/tier2_redundancy_eliminator_bytecodes.c b/Python/tier2_redundancy_eliminator_bytecodes.c index 86a63f90828f1c..b9afd3089e1077 100644 --- a/Python/tier2_redundancy_eliminator_bytecodes.c +++ b/Python/tier2_redundancy_eliminator_bytecodes.c @@ -344,7 +344,7 @@ dummy_func(void) { assert(self_or_null != NULL); assert(args != NULL); - if (!sym_is_null(self_or_null)) { + if (sym_is_not_null(self_or_null)) { // Bound method fiddling, same as _INIT_CALL_PY_EXACT_ARGS in VM args--; argcount++; diff --git a/Python/tier2_redundancy_eliminator_cases.c.h b/Python/tier2_redundancy_eliminator_cases.c.h index a66afd9670f792..ca341e4dde5d93 100644 --- a/Python/tier2_redundancy_eliminator_cases.c.h +++ b/Python/tier2_redundancy_eliminator_cases.c.h @@ -1428,7 +1428,7 @@ PyCodeObject *co = (PyCodeObject *)func->func_code; assert(self_or_null != NULL); assert(args != NULL); - if (!sym_is_null(self_or_null)) { + if (sym_is_not_null(self_or_null)) { // Bound method fiddling, same as _INIT_CALL_PY_EXACT_ARGS in VM args--; argcount++;