summaryrefslogtreecommitdiffstats
path: root/Python/optimizer_cases.c.h
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2024-03-05 15:06:00 (GMT)
committerGitHub <noreply@github.com>2024-03-05 15:06:00 (GMT)
commit0c81ce13602b88fd59f23f701ed8dc377d74e76e (patch)
treedbcf462118f71fa97906409414099cdd2b8ca241 /Python/optimizer_cases.c.h
parentc91bdf86ef1cf9365b61a46aa2e51e5d1932b00a (diff)
downloadcpython-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_cases.c.h')
-rw-r--r--Python/optimizer_cases.c.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/Python/optimizer_cases.c.h b/Python/optimizer_cases.c.h
index f2c186a..6e65e2e 100644
--- a/Python/optimizer_cases.c.h
+++ b/Python/optimizer_cases.c.h
@@ -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;
}