GH-130415: Optimize constant comparison in JIT builds (GH-131489)

This commit is contained in:
Savannah Ostrowski 2025-03-21 11:23:12 -07:00 committed by GitHub
parent 0de5e0c544
commit b92ee14b80
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 142 additions and 35 deletions

View file

@ -446,7 +446,25 @@ dummy_func(void) {
}
op(_COMPARE_OP_INT, (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));
assert(_Py_IsImmortal(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_FLOAT, (left, right -- res)) {