gh-134584: Eliminate redundant refcounting from IS_OP (GH-143171)

Eliminate redundant refcounting from IS_OP
This commit is contained in:
Hai Zhu 2025-12-27 04:30:02 +08:00 committed by GitHub
parent b3f2d80569
commit a1c6308346
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 1061 additions and 919 deletions

View file

@ -2779,10 +2779,14 @@ dummy_func(
// It's always a bool, so we don't care about oparg & 16.
}
inst(IS_OP, (left, right -- b)) {
macro(IS_OP) = _IS_OP + POP_TOP + POP_TOP;
op(_IS_OP, (left, right -- b, l, r)) {
int res = Py_Is(PyStackRef_AsPyObjectBorrow(left), PyStackRef_AsPyObjectBorrow(right)) ^ oparg;
DECREF_INPUTS();
b = res ? PyStackRef_True : PyStackRef_False;
l = left;
r = right;
INPUTS_DEAD();
}
family(CONTAINS_OP, INLINE_CACHE_ENTRIES_CONTAINS_OP) = {

View file

@ -9087,34 +9087,78 @@
break;
}
case _IS_OP_r21: {
case _IS_OP_r03: {
CHECK_CURRENT_CACHED_VALUES(0);
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
_PyStackRef right;
_PyStackRef left;
_PyStackRef b;
_PyStackRef l;
_PyStackRef r;
oparg = CURRENT_OPARG();
right = stack_pointer[-1];
left = stack_pointer[-2];
int res = Py_Is(PyStackRef_AsPyObjectBorrow(left), PyStackRef_AsPyObjectBorrow(right)) ^ oparg;
b = res ? PyStackRef_True : PyStackRef_False;
l = left;
r = right;
_tos_cache2 = r;
_tos_cache1 = l;
_tos_cache0 = b;
SET_CURRENT_CACHED_VALUES(3);
stack_pointer += -2;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
break;
}
case _IS_OP_r13: {
CHECK_CURRENT_CACHED_VALUES(1);
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
_PyStackRef right;
_PyStackRef left;
_PyStackRef b;
_PyStackRef l;
_PyStackRef r;
_PyStackRef _stack_item_0 = _tos_cache0;
oparg = CURRENT_OPARG();
right = _stack_item_0;
left = stack_pointer[-1];
int res = Py_Is(PyStackRef_AsPyObjectBorrow(left), PyStackRef_AsPyObjectBorrow(right)) ^ oparg;
b = res ? PyStackRef_True : PyStackRef_False;
l = left;
r = right;
_tos_cache2 = r;
_tos_cache1 = l;
_tos_cache0 = b;
SET_CURRENT_CACHED_VALUES(3);
stack_pointer += -1;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
break;
}
case _IS_OP_r23: {
CHECK_CURRENT_CACHED_VALUES(2);
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
_PyStackRef right;
_PyStackRef left;
_PyStackRef b;
_PyStackRef l;
_PyStackRef r;
_PyStackRef _stack_item_0 = _tos_cache0;
_PyStackRef _stack_item_1 = _tos_cache1;
oparg = CURRENT_OPARG();
right = _stack_item_1;
left = _stack_item_0;
int res = Py_Is(PyStackRef_AsPyObjectBorrow(left), PyStackRef_AsPyObjectBorrow(right)) ^ oparg;
_PyFrame_SetStackPointer(frame, stack_pointer);
_PyStackRef tmp = right;
right = PyStackRef_NULL;
stack_pointer[0] = left;
stack_pointer[1] = right;
PyStackRef_CLOSE(tmp);
tmp = left;
left = PyStackRef_NULL;
stack_pointer[0] = left;
PyStackRef_CLOSE(tmp);
stack_pointer = _PyFrame_GetStackPointer(frame);
b = res ? PyStackRef_True : PyStackRef_False;
l = left;
r = right;
_tos_cache2 = r;
_tos_cache1 = l;
_tos_cache0 = b;
_tos_cache1 = PyStackRef_ZERO_BITS;
_tos_cache2 = PyStackRef_ZERO_BITS;
SET_CURRENT_CACHED_VALUES(1);
SET_CURRENT_CACHED_VALUES(3);
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
break;
}

View file

@ -7192,25 +7192,36 @@
_PyStackRef left;
_PyStackRef right;
_PyStackRef b;
right = stack_pointer[-1];
left = stack_pointer[-2];
int res = Py_Is(PyStackRef_AsPyObjectBorrow(left), PyStackRef_AsPyObjectBorrow(right)) ^ oparg;
_PyFrame_SetStackPointer(frame, stack_pointer);
_PyStackRef tmp = right;
right = PyStackRef_NULL;
stack_pointer[-1] = right;
PyStackRef_CLOSE(tmp);
tmp = left;
left = PyStackRef_NULL;
stack_pointer[-2] = left;
PyStackRef_CLOSE(tmp);
stack_pointer = _PyFrame_GetStackPointer(frame);
stack_pointer += -2;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
b = res ? PyStackRef_True : PyStackRef_False;
stack_pointer[0] = b;
stack_pointer += 1;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
_PyStackRef l;
_PyStackRef r;
_PyStackRef value;
// _IS_OP
{
right = stack_pointer[-1];
left = stack_pointer[-2];
int res = Py_Is(PyStackRef_AsPyObjectBorrow(left), PyStackRef_AsPyObjectBorrow(right)) ^ oparg;
b = res ? PyStackRef_True : PyStackRef_False;
l = left;
r = right;
}
// _POP_TOP
{
value = r;
stack_pointer[-2] = b;
stack_pointer[-1] = l;
_PyFrame_SetStackPointer(frame, stack_pointer);
PyStackRef_XCLOSE(value);
stack_pointer = _PyFrame_GetStackPointer(frame);
}
// _POP_TOP
{
value = l;
stack_pointer += -1;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
_PyFrame_SetStackPointer(frame, stack_pointer);
PyStackRef_XCLOSE(value);
stack_pointer = _PyFrame_GetStackPointer(frame);
}
DISPATCH();
}

View file

@ -478,8 +478,10 @@ dummy_func(void) {
r = right;
}
op(_IS_OP, (left, right -- b)) {
op(_IS_OP, (left, right -- b, l, r)) {
b = sym_new_type(ctx, &PyBool_Type);
l = left;
r = right;
}
op(_CONTAINS_OP, (left, right -- b)) {

View file

@ -1875,11 +1875,21 @@
}
case _IS_OP: {
JitOptRef right;
JitOptRef left;
JitOptRef b;
JitOptRef l;
JitOptRef r;
right = stack_pointer[-1];
left = stack_pointer[-2];
b = sym_new_type(ctx, &PyBool_Type);
CHECK_STACK_BOUNDS(-1);
l = left;
r = right;
CHECK_STACK_BOUNDS(1);
stack_pointer[-2] = b;
stack_pointer += -1;
stack_pointer[-1] = l;
stack_pointer[0] = r;
stack_pointer += 1;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
break;
}