gh-146640: Optimize int operations by mutating uniquely-referenced operands in place (JIT only) (GH-146641)

This commit is contained in:
Pieter Eendebak 2026-04-03 17:23:04 +02:00 committed by GitHub
parent 80ab6d958a
commit 48317feec8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 2331 additions and 1262 deletions

View file

@ -309,21 +309,41 @@ dummy_func(void) {
}
op(_BINARY_OP_ADD_INT, (left, right -- res, l, r)) {
res = sym_new_compact_int(ctx);
if (PyJitRef_IsUnique(left)) {
REPLACE_OP(this_instr, _BINARY_OP_ADD_INT_INPLACE, 0, 0);
}
else if (PyJitRef_IsUnique(right)) {
REPLACE_OP(this_instr, _BINARY_OP_ADD_INT_INPLACE_RIGHT, 0, 0);
}
// Result may be a unique compact int or a cached small int
// at runtime. Mark as unique; inplace ops verify at runtime.
res = PyJitRef_MakeUnique(sym_new_compact_int(ctx));
l = left;
r = right;
REPLACE_OPCODE_IF_EVALUATES_PURE(left, right, res);
}
op(_BINARY_OP_SUBTRACT_INT, (left, right -- res, l, r)) {
res = sym_new_compact_int(ctx);
if (PyJitRef_IsUnique(left)) {
REPLACE_OP(this_instr, _BINARY_OP_SUBTRACT_INT_INPLACE, 0, 0);
}
else if (PyJitRef_IsUnique(right)) {
REPLACE_OP(this_instr, _BINARY_OP_SUBTRACT_INT_INPLACE_RIGHT, 0, 0);
}
res = PyJitRef_MakeUnique(sym_new_compact_int(ctx));
l = left;
r = right;
REPLACE_OPCODE_IF_EVALUATES_PURE(left, right, res);
}
op(_BINARY_OP_MULTIPLY_INT, (left, right -- res, l, r)) {
res = sym_new_compact_int(ctx);
if (PyJitRef_IsUnique(left)) {
REPLACE_OP(this_instr, _BINARY_OP_MULTIPLY_INT_INPLACE, 0, 0);
}
else if (PyJitRef_IsUnique(right)) {
REPLACE_OP(this_instr, _BINARY_OP_MULTIPLY_INT_INPLACE_RIGHT, 0, 0);
}
res = PyJitRef_MakeUnique(sym_new_compact_int(ctx));
l = left;
r = right;
REPLACE_OPCODE_IF_EVALUATES_PURE(left, right, res);