Skip to content

Commit 876afee

Browse files
brandtbucherpull[bot]
authored andcommitted
GH-125912: Teach the JIT's optimizer about _BINARY_OP_INPLACE_ADD_UNICODE (GH-125935)
1 parent 2e30049 commit 876afee

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

Python/optimizer_bytecodes.c

+18
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,24 @@ dummy_func(void) {
331331
}
332332
}
333333

334+
op(_BINARY_OP_INPLACE_ADD_UNICODE, (left, right -- )) {
335+
_Py_UopsSymbol *res;
336+
if (sym_is_const(left) && sym_is_const(right) &&
337+
sym_matches_type(left, &PyUnicode_Type) && sym_matches_type(right, &PyUnicode_Type)) {
338+
PyObject *temp = PyUnicode_Concat(sym_get_const(left), sym_get_const(right));
339+
if (temp == NULL) {
340+
goto error;
341+
}
342+
res = sym_new_const(ctx, temp);
343+
Py_DECREF(temp);
344+
}
345+
else {
346+
res = sym_new_type(ctx, &PyUnicode_Type);
347+
}
348+
// _STORE_FAST:
349+
GETLOCAL(this_instr->operand) = res;
350+
}
351+
334352
op(_BINARY_SUBSCR_INIT_CALL, (container, sub -- new_frame: _Py_UOpsAbstractFrame *)) {
335353
(void)container;
336354
(void)sub;

Python/optimizer_cases.c.h

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)