diff options
author | Mark Shannon <mark@hotpy.org> | 2024-03-05 15:06:00 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-05 15:06:00 (GMT) |
commit | 0c81ce13602b88fd59f23f701ed8dc377d74e76e (patch) | |
tree | dbcf462118f71fa97906409414099cdd2b8ca241 /Python/optimizer_bytecodes.c | |
parent | c91bdf86ef1cf9365b61a46aa2e51e5d1932b00a (diff) | |
download | cpython-0c81ce13602b88fd59f23f701ed8dc377d74e76e.zip cpython-0c81ce13602b88fd59f23f701ed8dc377d74e76e.tar.gz cpython-0c81ce13602b88fd59f23f701ed8dc377d74e76e.tar.bz2 |
GH-115819: Eliminate Boolean guards when value is known (GH-116355)
Diffstat (limited to 'Python/optimizer_bytecodes.c')
-rw-r--r-- | Python/optimizer_bytecodes.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/Python/optimizer_bytecodes.c b/Python/optimizer_bytecodes.c index 2cf5427..ee67a2b 100644 --- a/Python/optimizer_bytecodes.c +++ b/Python/optimizer_bytecodes.c @@ -21,6 +21,7 @@ typedef struct _Py_UOpsAbstractFrame _Py_UOpsAbstractFrame; #define sym_new_const _Py_uop_sym_new_const #define sym_new_null _Py_uop_sym_new_null #define sym_matches_type _Py_uop_sym_matches_type +#define sym_has_type _Py_uop_sym_has_type #define sym_set_null _Py_uop_sym_set_null #define sym_set_non_null _Py_uop_sym_set_non_null #define sym_set_type _Py_uop_sym_set_type @@ -36,6 +37,8 @@ optimize_to_bool( _Py_UopsSymbol *value, _Py_UopsSymbol **result_ptr); +extern void +eliminate_pop_guard(_PyUOpInstruction *this_instr, bool exit) static int dummy_func(void) { @@ -557,7 +560,45 @@ dummy_func(void) { (void)iter; } + op(_GUARD_IS_TRUE_POP, (flag -- )) { + if (sym_is_const(flag)) { + PyObject *value = sym_get_const(flag); + assert(value != NULL); + eliminate_pop_guard(this_instr, value != Py_True); + } + } + + op(_GUARD_IS_FALSE_POP, (flag -- )) { + if (sym_is_const(flag)) { + PyObject *value = sym_get_const(flag); + assert(value != NULL); + eliminate_pop_guard(this_instr, value != Py_False); + } + } + + op(_GUARD_IS_NONE_POP, (flag -- )) { + if (sym_is_const(flag)) { + PyObject *value = sym_get_const(flag); + assert(value != NULL); + eliminate_pop_guard(this_instr, !Py_IsNone(value)); + } + else if (sym_has_type(flag)) { + assert(!sym_matches_type(flag, &_PyNone_Type)); + eliminate_pop_guard(this_instr, true); + } + } + op(_GUARD_IS_NOT_NONE_POP, (flag -- )) { + if (sym_is_const(flag)) { + PyObject *value = sym_get_const(flag); + assert(value != NULL); + eliminate_pop_guard(this_instr, Py_IsNone(value)); + } + else if (sym_has_type(flag)) { + assert(!sym_matches_type(flag, &_PyNone_Type)); + eliminate_pop_guard(this_instr, false); + } + } // END BYTECODES // |