8000 GH-130415: Use boolean guards to narrow types to values in the JIT by brandtbucher · Pull Request #130659 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-130415: Use boolean guards to narrow types to values in the JIT #130659

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 13 commits into from
Mar 2, 2025
Prev Previous commit
Next Next commit
Merge branch 'main' into jit-narrow-to-bool-bool
  • Loading branch information
brandtbucher committed Mar 2, 2025
commit 07697ed5f090101428ab1d69c5442e2a3afeb16a
20 changes: 0 additions & 20 deletions Python/optimizer_analysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,26 +136,6 @@ incorrect_keys(_PyUOpInstruction *inst, PyObject *obj)
return 0;
}
static int
check_next_uop(_PyUOpInstruction *buffer, int size, int pc, uint16_t expected)
{
if (pc + 1 >= size) {
DPRINTF(1, "Cannot rewrite %s at pc %d: buffer too small\n",
_PyOpcode_uop_name[buffer[pc].opcode], pc);
return 0;
}
uint16_t next_opcode = buffer[pc + 1].opcode;
if (next_opcode != expected) {
DPRINTF(1,
"Cannot rewrite %s at pc %d: unexpected next opcode %s, "
"expected %s\n",
_PyOpcode_uop_name[buffer[pc].opcode], pc,
_PyOpcode_uop_name[next_opcode], _PyOpcode_uop_name[expected]);
return 0;
}
return 1;
}

/* Returns 1 if successfully optimized
* 0 if the trace is not suitable for optimization (yet)
* -1 if there was an error. */
Expand Down
38 changes: 5 additions & 33 deletions Python/optimizer_bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,11 +525,11 @@ dummy_func(void) {

op(_ 8000 LOAD_ATTR_MODULE, (dict_version/2, owner, index/1 -- attr)) {
(void)dict_version;
mod_keys = sym_new_not_null(ctx);
(void)index;
attr = NULL;
if (sym_is_const(ctx, owner)) {
PyObject *cnst = sym_get_const(ctx, owner);
if (PyModule_CheckExact(cnst)) {
PyModuleObject *mod = (PyModuleObject *)cnst;
PyModuleObject *mod = (PyModuleObject *)sym_get_const(ctx, owner);
if (PyModule_CheckExact(mod)) {
PyObject *dict = mod->md_dict;
uint64_t watched_mutations = get_mutations(dict);
if (watched_mutations < _Py_MAX_ALLOWED_GLOBALS_MODIFICATIONS) {
Expand Down Expand Up @@ -560,35 +560,7 @@ dummy_func(void) {
}
}

op(_LOAD_ATTR_MODULE_FROM_KEYS, (index/1, owner, mod_keys -- attr)) {
(void)index;
attr = NULL;
if (this_instr[-1].opcode == _NOP) {
// Preceding _CHECK_ATTR_MODULE_PUSH_KEYS was removed: mod is const and dict is watched.
assert(sym_is_const(ctx, owner));
PyModuleObject *mod = (PyModuleObject *)sym_get_const(ctx, owner);
assert(PyModule_CheckExact(mod));
PyObject *dict = mod->md_dict;
PyObject *res = convert_global_to_const(this_instr, dict);
if (res != NULL) {
this_instr[-1].opcode = _POP_TOP;
attr = sym_new_const(ctx, res);
}
else {
this_instr->opcode = _LOAD_ATTR_MODULE;
}
}
if (attr == NULL) {
/* No conversion made. We don't know what `attr` is. */
attr = sym_new_not_null(ctx);
}
}

op(_CHECK_ATTR_WITH_HINT, (owner -- owner, dict)) {
dict = sym_new_not_null(ctx);
}

op(_LOAD_ATTR_WITH_HINT, (hint/1, owner, dict -- attr)) {
op(_LOAD_ATTR_WITH_HINT, (hint/1, owner -- attr)) {
attr = sym_new_not_null(ctx);
(void)hint;
}
Expand Down
41 changes: 4 additions & 37 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