mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
GH-115819: Eliminate Boolean guards when value is known (GH-116355)
This commit is contained in:
parent
c91bdf86ef
commit
0c81ce1360
6 changed files with 102 additions and 2 deletions
36
Python/optimizer_cases.c.h
generated
36
Python/optimizer_cases.c.h
generated
|
@ -1803,21 +1803,57 @@
|
|||
/* _INSTRUMENTED_POP_JUMP_IF_NOT_NONE is not a viable micro-op for tier 2 */
|
||||
|
||||
case _GUARD_IS_TRUE_POP: {
|
||||
_Py_UopsSymbol *flag;
|
||||
flag = stack_pointer[-1];
|
||||
if (sym_is_const(flag)) {
|
||||
PyObject *value = sym_get_const(flag);
|
||||
assert(value != NULL);
|
||||
eliminate_pop_guard(this_instr, value != Py_True);
|
||||
}
|
||||
stack_pointer += -1;
|
||||
break;
|
||||
}
|
||||
|
||||
case _GUARD_IS_FALSE_POP: {
|
||||
_Py_UopsSymbol *flag;
|
||||
flag = stack_pointer[-1];
|
||||
if (sym_is_const(flag)) {
|
||||
PyObject *value = sym_get_const(flag);
|
||||
assert(value != NULL);
|
||||
eliminate_pop_guard(this_instr, value != Py_False);
|
||||
}
|
||||
stack_pointer += -1;
|
||||
break;
|
||||
}
|
||||
|
||||
case _GUARD_IS_NONE_POP: {
|
||||
_Py_UopsSymbol *flag;
|
||||
flag = stack_pointer[-1];
|
||||
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);
|
||||
}
|
||||
stack_pointer += -1;
|
||||
break;
|
||||
}
|
||||
|
||||
case _GUARD_IS_NOT_NONE_POP: {
|
||||
_Py_UopsSymbol *flag;
|
||||
flag = stack_pointer[-1];
|
||||
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);
|
||||
}
|
||||
stack_pointer += -1;
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue