mirror of
https://github.com/python/cpython.git
synced 2025-12-31 04:23:37 +00:00
gh-131798: Remove bounds check when indexing into tuples with a constant index (#137607)
* Remove bounds check when indexing into tuples with a constant index * Add news entry * fixup after rebase
This commit is contained in:
parent
c3febba73b
commit
713684de53
10 changed files with 1232 additions and 940 deletions
2
Include/internal/pycore_opcode_metadata.h
generated
2
Include/internal/pycore_opcode_metadata.h
generated
|
|
@ -1341,7 +1341,7 @@ _PyOpcode_macro_expansion[256] = {
|
|||
[BINARY_OP_SUBSCR_LIST_INT] = { .nuops = 5, .uops = { { _GUARD_TOS_INT, OPARG_SIMPLE, 0 }, { _GUARD_NOS_LIST, OPARG_SIMPLE, 0 }, { _BINARY_OP_SUBSCR_LIST_INT, OPARG_SIMPLE, 5 }, { _POP_TOP_INT, OPARG_SIMPLE, 5 }, { _POP_TOP, OPARG_SIMPLE, 5 } } },
|
||||
[BINARY_OP_SUBSCR_LIST_SLICE] = { .nuops = 3, .uops = { { _GUARD_TOS_SLICE, OPARG_SIMPLE, 0 }, { _GUARD_NOS_LIST, OPARG_SIMPLE, 0 }, { _BINARY_OP_SUBSCR_LIST_SLICE, OPARG_SIMPLE, 5 } } },
|
||||
[BINARY_OP_SUBSCR_STR_INT] = { .nuops = 5, .uops = { { _GUARD_TOS_INT, OPARG_SIMPLE, 0 }, { _GUARD_NOS_UNICODE, OPARG_SIMPLE, 0 }, { _BINARY_OP_SUBSCR_STR_INT, OPARG_SIMPLE, 5 }, { _POP_TOP_INT, OPARG_SIMPLE, 5 }, { _POP_TOP, OPARG_SIMPLE, 5 } } },
|
||||
[BINARY_OP_SUBSCR_TUPLE_INT] = { .nuops = 5, .uops = { { _GUARD_TOS_INT, OPARG_SIMPLE, 0 }, { _GUARD_NOS_TUPLE, OPARG_SIMPLE, 0 }, { _BINARY_OP_SUBSCR_TUPLE_INT, OPARG_SIMPLE, 5 }, { _POP_TOP_INT, OPARG_SIMPLE, 5 }, { _POP_TOP, OPARG_SIMPLE, 5 } } },
|
||||
[BINARY_OP_SUBSCR_TUPLE_INT] = { .nuops = 6, .uops = { { _GUARD_TOS_INT, OPARG_SIMPLE, 0 }, { _GUARD_NOS_TUPLE, OPARG_SIMPLE, 0 }, { _GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS, OPARG_SIMPLE, 0 }, { _BINARY_OP_SUBSCR_TUPLE_INT, OPARG_SIMPLE, 5 }, { _POP_TOP_INT, OPARG_SIMPLE, 5 }, { _POP_TOP, OPARG_SIMPLE, 5 } } },
|
||||
[BINARY_OP_SUBTRACT_FLOAT] = { .nuops = 5, .uops = { { _GUARD_TOS_FLOAT, OPARG_SIMPLE, 0 }, { _GUARD_NOS_FLOAT, OPARG_SIMPLE, 0 }, { _BINARY_OP_SUBTRACT_FLOAT, OPARG_SIMPLE, 5 }, { _POP_TOP_FLOAT, OPARG_SIMPLE, 5 }, { _POP_TOP_FLOAT, OPARG_SIMPLE, 5 } } },
|
||||
[BINARY_OP_SUBTRACT_INT] = { .nuops = 5, .uops = { { _GUARD_TOS_INT, OPARG_SIMPLE, 0 }, { _GUARD_NOS_INT, OPARG_SIMPLE, 0 }, { _BINARY_OP_SUBTRACT_INT, OPARG_SIMPLE, 5 }, { _POP_TOP_INT, OPARG_SIMPLE, 5 }, { _POP_TOP_INT, OPARG_SIMPLE, 5 } } },
|
||||
[BINARY_SLICE] = { .nuops = 1, .uops = { { _BINARY_SLICE, OPARG_SIMPLE, 0 } } },
|
||||
|
|
|
|||
1859
Include/internal/pycore_uop_ids.h
generated
1859
Include/internal/pycore_uop_ids.h
generated
File diff suppressed because it is too large
Load diff
35
Include/internal/pycore_uop_metadata.h
generated
35
Include/internal/pycore_uop_metadata.h
generated
|
|
@ -122,7 +122,8 @@ const uint32_t _PyUop_Flags[MAX_UOP_ID+1] = {
|
|||
[_BINARY_OP_SUBSCR_STR_INT] = HAS_DEOPT_FLAG,
|
||||
[_GUARD_NOS_TUPLE] = HAS_EXIT_FLAG,
|
||||
[_GUARD_TOS_TUPLE] = HAS_EXIT_FLAG,
|
||||
[_BINARY_OP_SUBSCR_TUPLE_INT] = HAS_DEOPT_FLAG,
|
||||
[_GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS] = HAS_DEOPT_FLAG,
|
||||
[_BINARY_OP_SUBSCR_TUPLE_INT] = 0,
|
||||
[_GUARD_NOS_DICT] = HAS_EXIT_FLAG,
|
||||
[_GUARD_TOS_DICT] = HAS_EXIT_FLAG,
|
||||
[_BINARY_OP_SUBSCR_DICT] = HAS_ERROR_FLAG | HAS_ESCAPES_FLAG,
|
||||
|
|
@ -1150,11 +1151,20 @@ const _PyUopCachingInfo _PyUop_Caching[MAX_UOP_ID+1] = {
|
|||
{ 3, 3, _GUARD_TOS_TUPLE_r33 },
|
||||
},
|
||||
},
|
||||
[_BINARY_OP_SUBSCR_TUPLE_INT] = {
|
||||
.best = { 2, 2, 2, 2 },
|
||||
[_GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS] = {
|
||||
.best = { 0, 1, 2, 3 },
|
||||
.entries = {
|
||||
{ -1, -1, -1 },
|
||||
{ -1, -1, -1 },
|
||||
{ 2, 0, _GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS_r02 },
|
||||
{ 2, 1, _GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS_r12 },
|
||||
{ 2, 2, _GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS_r22 },
|
||||
{ 3, 3, _GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS_r33 },
|
||||
},
|
||||
},
|
||||
[_BINARY_OP_SUBSCR_TUPLE_INT] = {
|
||||
.best = { 0, 1, 2, 2 },
|
||||
.entries = {
|
||||
{ 3, 0, _BINARY_OP_SUBSCR_TUPLE_INT_r03 },
|
||||
{ 3, 1, _BINARY_OP_SUBSCR_TUPLE_INT_r13 },
|
||||
{ 3, 2, _BINARY_OP_SUBSCR_TUPLE_INT_r23 },
|
||||
{ -1, -1, -1 },
|
||||
},
|
||||
|
|
@ -3453,6 +3463,12 @@ const uint16_t _PyUop_Uncached[MAX_UOP_REGS_ID+1] = {
|
|||
[_GUARD_TOS_TUPLE_r11] = _GUARD_TOS_TUPLE,
|
||||
[_GUARD_TOS_TUPLE_r22] = _GUARD_TOS_TUPLE,
|
||||
[_GUARD_TOS_TUPLE_r33] = _GUARD_TOS_TUPLE,
|
||||
[_GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS_r02] = _GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS,
|
||||
[_GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS_r12] = _GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS,
|
||||
[_GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS_r22] = _GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS,
|
||||
[_GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS_r33] = _GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS,
|
||||
[_BINARY_OP_SUBSCR_TUPLE_INT_r03] = _BINARY_OP_SUBSCR_TUPLE_INT,
|
||||
[_BINARY_OP_SUBSCR_TUPLE_INT_r13] = _BINARY_OP_SUBSCR_TUPLE_INT,
|
||||
[_BINARY_OP_SUBSCR_TUPLE_INT_r23] = _BINARY_OP_SUBSCR_TUPLE_INT,
|
||||
[_GUARD_NOS_DICT_r02] = _GUARD_NOS_DICT,
|
||||
[_GUARD_NOS_DICT_r12] = _GUARD_NOS_DICT,
|
||||
|
|
@ -3970,6 +3986,8 @@ const char *const _PyOpcode_uop_name[MAX_UOP_REGS_ID+1] = {
|
|||
[_BINARY_OP_SUBSCR_STR_INT] = "_BINARY_OP_SUBSCR_STR_INT",
|
||||
[_BINARY_OP_SUBSCR_STR_INT_r23] = "_BINARY_OP_SUBSCR_STR_INT_r23",
|
||||
[_BINARY_OP_SUBSCR_TUPLE_INT] = "_BINARY_OP_SUBSCR_TUPLE_INT",
|
||||
[_BINARY_OP_SUBSCR_TUPLE_INT_r03] = "_BINARY_OP_SUBSCR_TUPLE_INT_r03",
|
||||
[_BINARY_OP_SUBSCR_TUPLE_INT_r13] = "_BINARY_OP_SUBSCR_TUPLE_INT_r13",
|
||||
[_BINARY_OP_SUBSCR_TUPLE_INT_r23] = "_BINARY_OP_SUBSCR_TUPLE_INT_r23",
|
||||
[_BINARY_OP_SUBTRACT_FLOAT] = "_BINARY_OP_SUBTRACT_FLOAT",
|
||||
[_BINARY_OP_SUBTRACT_FLOAT_r03] = "_BINARY_OP_SUBTRACT_FLOAT_r03",
|
||||
|
|
@ -4223,6 +4241,11 @@ const char *const _PyOpcode_uop_name[MAX_UOP_REGS_ID+1] = {
|
|||
[_GET_YIELD_FROM_ITER_r11] = "_GET_YIELD_FROM_ITER_r11",
|
||||
[_GUARD_BINARY_OP_EXTEND] = "_GUARD_BINARY_OP_EXTEND",
|
||||
[_GUARD_BINARY_OP_EXTEND_r22] = "_GUARD_BINARY_OP_EXTEND_r22",
|
||||
[_GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS] = "_GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS",
|
||||
[_GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS_r02] = "_GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS_r02",
|
||||
[_GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS_r12] = "_GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS_r12",
|
||||
[_GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS_r22] = "_GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS_r22",
|
||||
[_GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS_r33] = "_GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS_r33",
|
||||
[_GUARD_CALLABLE_ISINSTANCE] = "_GUARD_CALLABLE_ISINSTANCE",
|
||||
[_GUARD_CALLABLE_ISINSTANCE_r03] = "_GUARD_CALLABLE_ISINSTANCE_r03",
|
||||
[_GUARD_CALLABLE_ISINSTANCE_r13] = "_GUARD_CALLABLE_ISINSTANCE_r13",
|
||||
|
|
@ -5103,6 +5126,8 @@ int _PyUop_num_popped(int opcode, int oparg)
|
|||
return 0;
|
||||
case _GUARD_TOS_TUPLE:
|
||||
return 0;
|
||||
case _GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS:
|
||||
return 0;
|
||||
case _BINARY_OP_SUBSCR_TUPLE_INT:
|
||||
return 2;
|
||||
case _GUARD_NOS_DICT:
|
||||
|
|
|
|||
|
|
@ -1859,6 +1859,21 @@ def f(n):
|
|||
self.assertNotIn("_GUARD_NOS_TUPLE", uops)
|
||||
self.assertIn("_BINARY_OP_SUBSCR_TUPLE_INT", uops)
|
||||
|
||||
def test_remove_guard_for_tuple_bounds_check(self):
|
||||
def f(n):
|
||||
x = 0
|
||||
for _ in range(n):
|
||||
t = (1, 2, 3)
|
||||
x += t[0]
|
||||
return x
|
||||
|
||||
res, ex = self._run_with_optimizer(f, TIER2_THRESHOLD)
|
||||
self.assertEqual(res, TIER2_THRESHOLD)
|
||||
self.assertIsNotNone(ex)
|
||||
uops = get_opnames(ex)
|
||||
self.assertNotIn("_GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS", uops)
|
||||
self.assertIn("_BINARY_OP_SUBSCR_TUPLE_INT", uops)
|
||||
|
||||
def test_binary_subcsr_str_int_narrows_to_str(self):
|
||||
def testfunc(n):
|
||||
x = []
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
Remove bounds check when indexing into tuples with a constant index.
|
||||
|
|
@ -968,9 +968,16 @@ dummy_func(
|
|||
}
|
||||
|
||||
macro(BINARY_OP_SUBSCR_TUPLE_INT) =
|
||||
_GUARD_TOS_INT + _GUARD_NOS_TUPLE + unused/5 + _BINARY_OP_SUBSCR_TUPLE_INT + _POP_TOP_INT + POP_TOP;
|
||||
_GUARD_TOS_INT +
|
||||
_GUARD_NOS_TUPLE +
|
||||
_GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS +
|
||||
unused/5 +
|
||||
_BINARY_OP_SUBSCR_TUPLE_INT +
|
||||
_POP_TOP_INT +
|
||||
POP_TOP;
|
||||
|
||||
op(_BINARY_OP_SUBSCR_TUPLE_INT, (tuple_st, sub_st -- res, ts, ss)) {
|
||||
// A guard that checks that the tuple subscript is within bounds
|
||||
op(_GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS, (tuple_st, sub_st -- tuple_st, sub_st)) {
|
||||
PyObject *sub = PyStackRef_AsPyObjectBorrow(sub_st);
|
||||
PyObject *tuple = PyStackRef_AsPyObjectBorrow(tuple_st);
|
||||
|
||||
|
|
@ -981,7 +988,17 @@ dummy_func(
|
|||
DEOPT_IF(!_PyLong_IsNonNegativeCompact((PyLongObject *)sub));
|
||||
Py_ssize_t index = ((PyLongObject*)sub)->long_value.ob_digit[0];
|
||||
DEOPT_IF(index >= PyTuple_GET_SIZE(tuple));
|
||||
}
|
||||
|
||||
op(_BINARY_OP_SUBSCR_TUPLE_INT, (tuple_st, sub_st -- res, ts, ss)) {
|
||||
PyObject *sub = PyStackRef_AsPyObjectBorrow(sub_st);
|
||||
PyObject *tuple = PyStackRef_AsPyObjectBorrow(tuple_st);
|
||||
|
||||
assert(PyLong_CheckExact(sub));
|
||||
assert(PyTuple_CheckExact(tuple));
|
||||
|
||||
STAT_INC(BINARY_OP, hit);
|
||||
Py_ssize_t index = ((PyLongObject*)sub)->long_value.ob_digit[0];
|
||||
PyObject *res_o = PyTuple_GET_ITEM(tuple, index);
|
||||
assert(res_o != NULL);
|
||||
res = PyStackRef_FromPyObjectNew(res_o);
|
||||
|
|
|
|||
196
Python/executor_cases.c.h
generated
196
Python/executor_cases.c.h
generated
|
|
@ -4891,14 +4891,76 @@
|
|||
break;
|
||||
}
|
||||
|
||||
case _BINARY_OP_SUBSCR_TUPLE_INT_r23: {
|
||||
case _GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS_r02: {
|
||||
CHECK_CURRENT_CACHED_VALUES(0);
|
||||
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
|
||||
_PyStackRef sub_st;
|
||||
_PyStackRef tuple_st;
|
||||
sub_st = stack_pointer[-1];
|
||||
tuple_st = stack_pointer[-2];
|
||||
PyObject *sub = PyStackRef_AsPyObjectBorrow(sub_st);
|
||||
PyObject *tuple = PyStackRef_AsPyObjectBorrow(tuple_st);
|
||||
assert(PyLong_CheckExact(sub));
|
||||
assert(PyTuple_CheckExact(tuple));
|
||||
if (!_PyLong_IsNonNegativeCompact((PyLongObject *)sub)) {
|
||||
UOP_STAT_INC(uopcode, miss);
|
||||
SET_CURRENT_CACHED_VALUES(0);
|
||||
JUMP_TO_JUMP_TARGET();
|
||||
}
|
||||
Py_ssize_t index = ((PyLongObject*)sub)->long_value.ob_digit[0];
|
||||
if (index >= PyTuple_GET_SIZE(tuple)) {
|
||||
UOP_STAT_INC(uopcode, miss);
|
||||
SET_CURRENT_CACHED_VALUES(0);
|
||||
JUMP_TO_JUMP_TARGET();
|
||||
}
|
||||
_tos_cache1 = sub_st;
|
||||
_tos_cache0 = tuple_st;
|
||||
SET_CURRENT_CACHED_VALUES(2);
|
||||
stack_pointer += -2;
|
||||
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
|
||||
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
|
||||
break;
|
||||
}
|
||||
|
||||
case _GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS_r12: {
|
||||
CHECK_CURRENT_CACHED_VALUES(1);
|
||||
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
|
||||
_PyStackRef sub_st;
|
||||
_PyStackRef tuple_st;
|
||||
_PyStackRef _stack_item_0 = _tos_cache0;
|
||||
sub_st = _stack_item_0;
|
||||
tuple_st = stack_pointer[-1];
|
||||
PyObject *sub = PyStackRef_AsPyObjectBorrow(sub_st);
|
||||
PyObject *tuple = PyStackRef_AsPyObjectBorrow(tuple_st);
|
||||
assert(PyLong_CheckExact(sub));
|
||||
assert(PyTuple_CheckExact(tuple));
|
||||
if (!_PyLong_IsNonNegativeCompact((PyLongObject *)sub)) {
|
||||
UOP_STAT_INC(uopcode, miss);
|
||||
_tos_cache0 = sub_st;
|
||||
SET_CURRENT_CACHED_VALUES(1);
|
||||
JUMP_TO_JUMP_TARGET();
|
||||
}
|
||||
Py_ssize_t index = ((PyLongObject*)sub)->long_value.ob_digit[0];
|
||||
if (index >= PyTuple_GET_SIZE(tuple)) {
|
||||
UOP_STAT_INC(uopcode, miss);
|
||||
_tos_cache0 = sub_st;
|
||||
SET_CURRENT_CACHED_VALUES(1);
|
||||
JUMP_TO_JUMP_TARGET();
|
||||
}
|
||||
_tos_cache1 = sub_st;
|
||||
_tos_cache0 = tuple_st;
|
||||
SET_CURRENT_CACHED_VALUES(2);
|
||||
stack_pointer += -1;
|
||||
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
|
||||
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
|
||||
break;
|
||||
}
|
||||
|
||||
case _GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS_r22: {
|
||||
CHECK_CURRENT_CACHED_VALUES(2);
|
||||
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
|
||||
_PyStackRef sub_st;
|
||||
_PyStackRef tuple_st;
|
||||
_PyStackRef res;
|
||||
_PyStackRef ts;
|
||||
_PyStackRef ss;
|
||||
_PyStackRef _stack_item_0 = _tos_cache0;
|
||||
_PyStackRef _stack_item_1 = _tos_cache1;
|
||||
sub_st = _stack_item_1;
|
||||
|
|
@ -4922,7 +4984,133 @@
|
|||
SET_CURRENT_CACHED_VALUES(2);
|
||||
JUMP_TO_JUMP_TARGET();
|
||||
}
|
||||
_tos_cache1 = sub_st;
|
||||
_tos_cache0 = tuple_st;
|
||||
SET_CURRENT_CACHED_VALUES(2);
|
||||
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
|
||||
break;
|
||||
}
|
||||
|
||||
case _GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS_r33: {
|
||||
CHECK_CURRENT_CACHED_VALUES(3);
|
||||
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
|
||||
_PyStackRef sub_st;
|
||||
_PyStackRef tuple_st;
|
||||
_PyStackRef _stack_item_0 = _tos_cache0;
|
||||
_PyStackRef _stack_item_1 = _tos_cache1;
|
||||
_PyStackRef _stack_item_2 = _tos_cache2;
|
||||
sub_st = _stack_item_2;
|
||||
tuple_st = _stack_item_1;
|
||||
PyObject *sub = PyStackRef_AsPyObjectBorrow(sub_st);
|
||||
PyObject *tuple = PyStackRef_AsPyObjectBorrow(tuple_st);
|
||||
assert(PyLong_CheckExact(sub));
|
||||
assert(PyTuple_CheckExact(tuple));
|
||||
if (!_PyLong_IsNonNegativeCompact((PyLongObject *)sub)) {
|
||||
UOP_STAT_INC(uopcode, miss);
|
||||
_tos_cache2 = sub_st;
|
||||
_tos_cache1 = tuple_st;
|
||||
_tos_cache0 = _stack_item_0;
|
||||
SET_CURRENT_CACHED_VALUES(3);
|
||||
JUMP_TO_JUMP_TARGET();
|
||||
}
|
||||
Py_ssize_t index = ((PyLongObject*)sub)->long_value.ob_digit[0];
|
||||
if (index >= PyTuple_GET_SIZE(tuple)) {
|
||||
UOP_STAT_INC(uopcode, miss);
|
||||
_tos_cache2 = sub_st;
|
||||
_tos_cache1 = tuple_st;
|
||||
_tos_cache0 = _stack_item_0;
|
||||
SET_CURRENT_CACHED_VALUES(3);
|
||||
JUMP_TO_JUMP_TARGET();
|
||||
}
|
||||
_tos_cache2 = sub_st;
|
||||
_tos_cache1 = tuple_st;
|
||||
_tos_cache0 = _stack_item_0;
|
||||
SET_CURRENT_CACHED_VALUES(3);
|
||||
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
|
||||
break;
|
||||
}
|
||||
|
||||
case _BINARY_OP_SUBSCR_TUPLE_INT_r03: {
|
||||
CHECK_CURRENT_CACHED_VALUES(0);
|
||||
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
|
||||
_PyStackRef sub_st;
|
||||
_PyStackRef tuple_st;
|
||||
_PyStackRef res;
|
||||
_PyStackRef ts;
|
||||
_PyStackRef ss;
|
||||
sub_st = stack_pointer[-1];
|
||||
tuple_st = stack_pointer[-2];
|
||||
PyObject *sub = PyStackRef_AsPyObjectBorrow(sub_st);
|
||||
PyObject *tuple = PyStackRef_AsPyObjectBorrow(tuple_st);
|
||||
assert(PyLong_CheckExact(sub));
|
||||
assert(PyTuple_CheckExact(tuple));
|
||||
STAT_INC(BINARY_OP, hit);
|
||||
Py_ssize_t index = ((PyLongObject*)sub)->long_value.ob_digit[0];
|
||||
PyObject *res_o = PyTuple_GET_ITEM(tuple, index);
|
||||
assert(res_o != NULL);
|
||||
res = PyStackRef_FromPyObjectNew(res_o);
|
||||
ts = tuple_st;
|
||||
ss = sub_st;
|
||||
_tos_cache2 = ss;
|
||||
_tos_cache1 = ts;
|
||||
_tos_cache0 = res;
|
||||
SET_CURRENT_CACHED_VALUES(3);
|
||||
stack_pointer += -2;
|
||||
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
|
||||
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
|
||||
break;
|
||||
}
|
||||
|
||||
case _BINARY_OP_SUBSCR_TUPLE_INT_r13: {
|
||||
CHECK_CURRENT_CACHED_VALUES(1);
|
||||
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
|
||||
_PyStackRef sub_st;
|
||||
_PyStackRef tuple_st;
|
||||
_PyStackRef res;
|
||||
_PyStackRef ts;
|
||||
_PyStackRef ss;
|
||||
_PyStackRef _stack_item_0 = _tos_cache0;
|
||||
sub_st = _stack_item_0;
|
||||
tuple_st = stack_pointer[-1];
|
||||
PyObject *sub = PyStackRef_AsPyObjectBorrow(sub_st);
|
||||
PyObject *tuple = PyStackRef_AsPyObjectBorrow(tuple_st);
|
||||
assert(PyLong_CheckExact(sub));
|
||||
assert(PyTuple_CheckExact(tuple));
|
||||
STAT_INC(BINARY_OP, hit);
|
||||
Py_ssize_t index = ((PyLongObject*)sub)->long_value.ob_digit[0];
|
||||
PyObject *res_o = PyTuple_GET_ITEM(tuple, index);
|
||||
assert(res_o != NULL);
|
||||
res = PyStackRef_FromPyObjectNew(res_o);
|
||||
ts = tuple_st;
|
||||
ss = sub_st;
|
||||
_tos_cache2 = ss;
|
||||
_tos_cache1 = ts;
|
||||
_tos_cache0 = res;
|
||||
SET_CURRENT_CACHED_VALUES(3);
|
||||
stack_pointer += -1;
|
||||
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
|
||||
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
|
||||
break;
|
||||
}
|
||||
|
||||
case _BINARY_OP_SUBSCR_TUPLE_INT_r23: {
|
||||
CHECK_CURRENT_CACHED_VALUES(2);
|
||||
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
|
||||
_PyStackRef sub_st;
|
||||
_PyStackRef tuple_st;
|
||||
_PyStackRef res;
|
||||
_PyStackRef ts;
|
||||
_PyStackRef ss;
|
||||
_PyStackRef _stack_item_0 = _tos_cache0;
|
||||
_PyStackRef _stack_item_1 = _tos_cache1;
|
||||
sub_st = _stack_item_1;
|
||||
tuple_st = _stack_item_0;
|
||||
PyObject *sub = PyStackRef_AsPyObjectBorrow(sub_st);
|
||||
PyObject *tuple = PyStackRef_AsPyObjectBorrow(tuple_st);
|
||||
assert(PyLong_CheckExact(sub));
|
||||
assert(PyTuple_CheckExact(tuple));
|
||||
STAT_INC(BINARY_OP, hit);
|
||||
Py_ssize_t index = ((PyLongObject*)sub)->long_value.ob_digit[0];
|
||||
PyObject *res_o = PyTuple_GET_ITEM(tuple, index);
|
||||
assert(res_o != NULL);
|
||||
res = PyStackRef_FromPyObjectNew(res_o);
|
||||
|
|
|
|||
12
Python/generated_cases.c.h
generated
12
Python/generated_cases.c.h
generated
|
|
@ -1042,8 +1042,7 @@
|
|||
JUMP_TO_PREDICTED(BINARY_OP);
|
||||
}
|
||||
}
|
||||
/* Skip 5 cache entries */
|
||||
// _BINARY_OP_SUBSCR_TUPLE_INT
|
||||
// _GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS
|
||||
{
|
||||
sub_st = value;
|
||||
tuple_st = nos;
|
||||
|
|
@ -1062,7 +1061,16 @@
|
|||
assert(_PyOpcode_Deopt[opcode] == (BINARY_OP));
|
||||
JUMP_TO_PREDICTED(BINARY_OP);
|
||||
}
|
||||
}
|
||||
/* Skip 5 cache entries */
|
||||
// _BINARY_OP_SUBSCR_TUPLE_INT
|
||||
{
|
||||
PyObject *sub = PyStackRef_AsPyObjectBorrow(sub_st);
|
||||
PyObject *tuple = PyStackRef_AsPyObjectBorrow(tuple_st);
|
||||
assert(PyLong_CheckExact(sub));
|
||||
assert(PyTuple_CheckExact(tuple));
|
||||
STAT_INC(BINARY_OP, hit);
|
||||
Py_ssize_t index = ((PyLongObject*)sub)->long_value.ob_digit[0];
|
||||
PyObject *res_o = PyTuple_GET_ITEM(tuple, index);
|
||||
assert(res_o != NULL);
|
||||
res = PyStackRef_FromPyObjectNew(res_o);
|
||||
|
|
|
|||
|
|
@ -332,6 +332,19 @@ dummy_func(void) {
|
|||
i = sub_st;
|
||||
}
|
||||
|
||||
op(_GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS, (tuple_st, sub_st -- tuple_st, sub_st)) {
|
||||
assert(sym_matches_type(tuple_st, &PyTuple_Type));
|
||||
if (sym_is_const(ctx, sub_st)) {
|
||||
assert(PyLong_CheckExact(sym_get_const(ctx, sub_st)));
|
||||
long index = PyLong_AsLong(sym_get_const(ctx, sub_st));
|
||||
assert(index >= 0);
|
||||
int tuple_length = sym_tuple_length(tuple_st);
|
||||
if (tuple_length != -1 && index < tuple_length) {
|
||||
REPLACE_OP(this_instr, _NOP, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
op(_BINARY_OP_SUBSCR_TUPLE_INT, (tuple_st, sub_st -- res, ts, ss)) {
|
||||
assert(sym_matches_type(tuple_st, &PyTuple_Type));
|
||||
if (sym_is_const(ctx, sub_st)) {
|
||||
|
|
|
|||
18
Python/optimizer_cases.c.h
generated
18
Python/optimizer_cases.c.h
generated
|
|
@ -799,6 +799,24 @@
|
|||
break;
|
||||
}
|
||||
|
||||
case _GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS: {
|
||||
JitOptRef sub_st;
|
||||
JitOptRef tuple_st;
|
||||
sub_st = stack_pointer[-1];
|
||||
tuple_st = stack_pointer[-2];
|
||||
assert(sym_matches_type(tuple_st, &PyTuple_Type));
|
||||
if (sym_is_const(ctx, sub_st)) {
|
||||
assert(PyLong_CheckExact(sym_get_const(ctx, sub_st)));
|
||||
long index = PyLong_AsLong(sym_get_const(ctx, sub_st));
|
||||
assert(index >= 0);
|
||||
int tuple_length = sym_tuple_length(tuple_st);
|
||||
if (tuple_length != -1 && index < tuple_length) {
|
||||
REPLACE_OP(this_instr, _NOP, 0, 0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case _BINARY_OP_SUBSCR_TUPLE_INT: {
|
||||
JitOptRef sub_st;
|
||||
JitOptRef tuple_st;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue