Skip to content

Commit 0f6d542

Browse files
Remove refcount for BINARY_OP_SUBSCR_STR_INT
1 parent 8c87bcd commit 0f6d542

File tree

9 files changed

+73
-29
lines changed

9 files changed

+73
-29
lines changed

Include/internal/pycore_opcode_metadata.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_uop_ids.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_uop_metadata.h

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/test/test_capi/test_opt.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1877,6 +1877,26 @@ def testfunc(n):
18771877
self.assertNotIn("_GUARD_TOS_UNICODE", uops)
18781878
self.assertIn("_BINARY_OP_ADD_UNICODE", uops)
18791879

1880+
def test_binary_op_subscr_str_int(self):
1881+
def testfunc(n):
1882+
x = 0
1883+
s = "hello"
1884+
for _ in range(n):
1885+
c = s[1] # _BINARY_OP_SUBSCR_STR_INT
1886+
if c == 'e':
1887+
x += 1
1888+
return x
1889+
1890+
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
1891+
self.assertEqual(res, TIER2_THRESHOLD)
1892+
self.assertIsNotNone(ex)
1893+
uops = get_opnames(ex)
1894+
self.assertIn("_BINARY_OP_SUBSCR_STR_INT", uops)
1895+
self.assertIn("_COMPARE_OP_STR", uops)
1896+
self.assertIn("_POP_TOP_NOP", uops)
1897+
self.assertNotIn("_POP_TOP", uops)
1898+
self.assertNotIn("_POP_TOP_INT", uops)
1899+
18801900
def test_call_type_1_guards_removed(self):
18811901
def testfunc(n):
18821902
x = 0

Python/bytecodes.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -937,9 +937,9 @@ dummy_func(
937937
}
938938

939939
macro(BINARY_OP_SUBSCR_STR_INT) =
940-
_GUARD_TOS_INT + _GUARD_NOS_UNICODE + unused/5 + _BINARY_OP_SUBSCR_STR_INT;
940+
_GUARD_TOS_INT + _GUARD_NOS_UNICODE + unused/5 + _BINARY_OP_SUBSCR_STR_INT + POP_TOP + _POP_TOP_INT;
941941

942-
op(_BINARY_OP_SUBSCR_STR_INT, (str_st, sub_st -- res)) {
942+
op(_BINARY_OP_SUBSCR_STR_INT, (str_st, sub_st -- res, s, i)) {
943943
PyObject *sub = PyStackRef_AsPyObjectBorrow(sub_st);
944944
PyObject *str = PyStackRef_AsPyObjectBorrow(str_st);
945945

@@ -954,9 +954,9 @@ dummy_func(
954954
assert(c < 128);
955955
STAT_INC(BINARY_OP, hit);
956956
PyObject *res_o = (PyObject*)&_Py_SINGLETON(strings).ascii[c];
957-
PyStackRef_CLOSE_SPECIALIZED(sub_st, _PyLong_ExactDealloc);
958-
DEAD(sub_st);
959-
PyStackRef_CLOSE(str_st);
957+
INPUTS_DEAD();
958+
s = str_st;
959+
i = sub_st;
960960
res = PyStackRef_FromPyObjectBorrow(res_o);
961961
}
962962

Python/executor_cases.c.h

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/generated_cases.c.h

Lines changed: 19 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/optimizer_bytecodes.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,10 @@ dummy_func(void) {
322322
ctx->done = true;
323323
}
324324

325-
op(_BINARY_OP_SUBSCR_STR_INT, (str_st, sub_st -- res)) {
325+
op(_BINARY_OP_SUBSCR_STR_INT, (str_st, sub_st -- res, s, i)) {
326326
res = sym_new_type(ctx, &PyUnicode_Type);
327+
s = str_st;
328+
i = sub_st;
327329
}
328330

329331
op(_BINARY_OP_SUBSCR_TUPLE_INT, (tuple_st, sub_st -- res)) {

Python/optimizer_cases.c.h

Lines changed: 12 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)