Skip to content

Commit

Permalink
Teach the optimizer about _BINARY_OP_INPLACE_ADD_UNICODE
Browse files Browse the repository at this point in the history
  • Loading branch information
brandtbucher committed Oct 24, 2024
1 parent 34653bb commit f4d6b30
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Python/optimizer_bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,24 @@ dummy_func(void) {
}
}

op(_BINARY_OP_INPLACE_ADD_UNICODE, (left, right -- )) {
_Py_UopsSymbol *res;
if (sym_is_const(left) && sym_is_const(right) &&
sym_matches_type(left, &PyUnicode_Type) && sym_matches_type(right, &PyUnicode_Type)) {
PyObject *temp = PyUnicode_Concat(sym_get_const(left), sym_get_const(right));
if (temp == NULL) {
goto error;
}
res = sym_new_const(ctx, temp);
Py_DECREF(temp);
}
else {
res = sym_new_type(ctx, &PyUnicode_Type);
}
// _STORE_FAST:
GETLOCAL(this_instr->operand) = res;
}

op(_BINARY_SUBSCR_INIT_CALL, (container, sub -- new_frame: _Py_UOpsAbstractFrame *)) {
(void)container;
(void)sub;
Expand Down
19 changes: 19 additions & 0 deletions Python/optimizer_cases.c.h

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

0 comments on commit f4d6b30

Please sign in to comment.