Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

GH-130415: Use POP_TWO_LOAD_CONST_INLINE_BORROW #134241

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
Loading
from
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Optimize constant comparison for _COMPARE_OP_FLOAT, _COMPARE_OP_STR, _BINARY_OP in JIT builds
50 changes: 48 additions & 2 deletions 50 Python/optimizer_bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,20 @@ dummy_func(void) {
else {
res = sym_new_type(ctx, &PyFloat_Type);
}

if (sym_is_const(ctx, lhs) && sym_is_const(ctx, rhs)) {
PyObject *temp = PyObject_RichCompare(sym_get_const(ctx, lhs),
sym_get_const(ctx, rhs),
oparg >> 5);
if (temp == NULL) {
goto error;
}
assert(PyBool_Check(temp));
assert(_Py_IsImmortal(temp));
REPLACE_OP(this_instr, _POP_TWO_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)temp);
res = sym_new_const(ctx, temp);
Py_DECREF(temp);
}
}

op(_BINARY_OP_ADD_INT, (left, right -- res)) {
Expand Down Expand Up @@ -486,11 +500,43 @@ dummy_func(void) {
}

op(_COMPARE_OP_FLOAT, (left, right -- res)) {
res = sym_new_type(ctx, &PyBool_Type);
if (sym_is_const(ctx, left) && sym_is_const(ctx, right)) {
assert(PyLong_CheckExact(sym_get_const(ctx, left)));
assert(PyLong_CheckExact(sym_get_const(ctx, right)));
PyObject *tmp = PyObject_RichCompare(sym_get_const(ctx, left),
sym_get_const(ctx, right),
oparg >> 5);
if (tmp == NULL) {
goto error;
}
assert(PyBool_Check(tmp));
REPLACE_OP(this_instr, _POP_TWO_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)tmp);
res = sym_new_const(ctx, tmp);
Py_DECREF(tmp);
}
else {
res = sym_new_type(ctx, &PyBool_Type);
}
}

op(_COMPARE_OP_STR, (left, right -- res)) {
res = sym_new_type(ctx, &PyBool_Type);
if (sym_is_const(ctx, left) && sym_is_const(ctx, right)) {
assert(PyLong_CheckExact(sym_get_const(ctx, left)));
assert(PyLong_CheckExact(sym_get_const(ctx, right)));
PyObject *tmp = PyObject_RichCompare(sym_get_const(ctx, left),
sym_get_const(ctx, right),
oparg >> 5);
if (tmp == NULL) {
goto error;
}
assert(PyBool_Check(tmp));
REPLACE_OP(this_instr, _POP_TWO_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)tmp);
res = sym_new_const(ctx, tmp);
Py_DECREF(tmp);
}
else {
res = sym_new_type(ctx, &PyBool_Type);
}
}

op(_IS_OP, (left, right -- b)) {
Expand Down
77 changes: 69 additions & 8 deletions 77 Python/optimizer_cases.c.h

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

Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.