8000 GH-131798: Allow the JIT to remove more `int`/`float`/`str` guards by brandtbucher · Pull Request #131800 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-131798: Allow the JIT to remove more int/float/str guards #131800

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 1, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Catch up with main
  • Loading branch information
brandtbucher committed Apr 1, 2025
commit c6bc3559e5a6cc71bff0747379ea9f61ec40d1f6
6 changes: 3 additions & 3 deletions Include/internal/pycore_uop_ids.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions Include/internal/pycore_uop_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 6 additions & 11 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,12 @@ dummy_func(
res = PyStackRef_False;
}

op(_GUARD_NOS_UNICODE, (nos, tos -- nos, tos)) {
(void)tos;
PyObject *o = PyStackRef_AsPyObjectBorrow(nos);
EXIT_IF(!PyUnicode_CheckExact(o));
}

op(_GUARD_TOS_UNICODE, (value -- value)) {
PyObject *value_o = PyStackRef_AsPyObjectBorrow(value);
EXIT_IF(!PyUnicode_CheckExact(value_o));
Expand Down Expand Up @@ -695,17 +701,6 @@ dummy_func(
macro(BINARY_OP_SUBTRACT_FLOAT) =
_GUARD_TOS_FLOAT + _GUARD_NOS_FLOAT + unused/5 + _BINARY_OP_SUBTRACT_FLOAT;

op(_GUARD_NOS_UNICODE, (nos, tos -- nos, tos)) {
(void)tos;
PyObject *o = PyStackRef_AsPyObjectBorrow(nos);
EXIT_IF(!PyUnicode_CheckExact(o));
}

op(_GUARD_TOS_UNICODE, (tos -- tos)) {
PyObject *o = PyStackRef_AsPyObjectBorrow(tos);
EXIT_IF(!PyUnicode_CheckExact(o));
}

pure op(_BINARY_OP_ADD_UNICODE, (left, right -- res)) {
PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
PyObject *right_o = PyStackRef_AsPyObjectBorrow(right);
Expand Down
39 changes: 14 additions & 25 deletions Python/executor_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 18 additions & 12 deletions Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 7 additions & 14 deletions Python/optimizer_bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,6 @@ dummy_func(void) {
sym_set_type(nos, &PyFloat_Type);
}

op(_GUARD_TOS_UNICODE, (tos -- tos)) {
if (sym_matches_type(tos, &PyUnicode_Type)) {
REPLACE_OP(this_instr, _NOP, 0, 0);
}
sym_set_type(tos, &PyUnicode_Type);
}

op(_GUARD_NOS_UNICODE, (nos, unused -- nos, unused)) {
if (sym_matches_type(nos, &PyUnicode_Type)) {
REPLACE_OP(this_instr, _NOP, 0, 0);
}
sym_set_type(nos, &PyUnicode_Type);
}

op(_BINARY_OP, (left, right -- res)) {
bool lhs_int = sym_matches_type(left, &PyLong_Type);
bool rhs_int = sym_matches_type(right, &PyLong_Type);
Expand Down Expand Up @@ -410,6 +396,13 @@ dummy_func(void) {
}
}

op(_GUARD_NOS_UNICODE, (nos, unused -- nos, unused)) {
if (sym_matches_type(nos, &PyUnicode_Type)) {
REPLACE_OP(this_instr, _NOP, 0, 0);
}
sym_set_type(nos, &PyUnicode_Type);
}

op(_GUARD_TOS_UNICODE, (value -- value)) {
if (sym_matches_type(value, &PyUnicode_Type)) {
REPLACE_OP(this_instr, _NOP, 0, 0);
Expand Down
30 changes: 10 additions & 20 deletions Python/optimizer_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

You are viewing a condensed version of this merge commit. You can view the full changes here.
0