Skip to content

Commit a6a6316

Browse files
committed
pythongh-134584: Eliminate redundant refcounting from _BINARY_OP_SUBSCR_LIST_INT (pythonGH-142926)
1 parent 8192cda commit a6a6316

9 files changed

Lines changed: 74 additions & 38 deletions

File tree

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: 3 additions & 3 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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3057,6 +3057,24 @@ class Obj:
30573057
for _ in range(TIER2_THRESHOLD+1):
30583058
obj.attr = EvilAttr(obj.__dict__)
30593059

3060+
def test_binary_subscr_list_int(self):
3061+
def testfunc(n):
3062+
l = [1]
3063+
x = 0
3064+
for _ in range(n):
3065+
y = l[0]
3066+
x += y
3067+
return x
3068+
3069+
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
3070+
self.assertEqual(res, TIER2_THRESHOLD)
3071+
self.assertIsNotNone(ex)
3072+
uops = get_opnames(ex)
3073+
3074+
self.assertIn("_BINARY_OP_SUBSCR_LIST_INT", uops)
3075+
self.assertNotIn("_POP_TOP", uops)
3076+
self.assertNotIn("_POP_TOP_INT", uops)
3077+
self.assertIn("_POP_TOP_NOP", uops)
30603078

30613079
def global_identity(x):
30623080
return x

Python/bytecodes.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -893,9 +893,9 @@ dummy_func(
893893
macro(STORE_SLICE) = _SPECIALIZE_STORE_SLICE + _STORE_SLICE;
894894

895895
macro(BINARY_OP_SUBSCR_LIST_INT) =
896-
_GUARD_TOS_INT + _GUARD_NOS_LIST + unused/5 + _BINARY_OP_SUBSCR_LIST_INT;
896+
_GUARD_TOS_INT + _GUARD_NOS_LIST + unused/5 + _BINARY_OP_SUBSCR_LIST_INT + _POP_TOP_INT + POP_TOP;
897897

898-
op(_BINARY_OP_SUBSCR_LIST_INT, (list_st, sub_st -- res)) {
898+
op(_BINARY_OP_SUBSCR_LIST_INT, (list_st, sub_st -- res, ls, ss)) {
899899
PyObject *sub = PyStackRef_AsPyObjectBorrow(sub_st);
900900
PyObject *list = PyStackRef_AsPyObjectBorrow(list_st);
901901

@@ -918,7 +918,9 @@ dummy_func(
918918
res = PyStackRef_FromPyObjectNew(res_o);
919919
#endif
920920
STAT_INC(BINARY_OP, hit);
921-
DECREF_INPUTS();
921+
ls = list_st;
922+
ss = sub_st;
923+
INPUTS_DEAD();
922924
}
923925

924926
macro(BINARY_OP_SUBSCR_LIST_SLICE) =

Python/executor_cases.c.h

Lines changed: 9 additions & 17 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: 18 additions & 10 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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,6 +1427,12 @@ dummy_func(void) {
14271427
}
14281428
}
14291429

1430+
op(_BINARY_OP_SUBSCR_LIST_INT, (list_st, sub_st -- res, ls, ss)) {
1431+
res = sym_new_unknown(ctx);
1432+
ls = list_st;
1433+
ss = sub_st;
1434+
}
1435+
14301436

14311437
// END BYTECODES //
14321438

Python/optimizer_cases.c.h

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

0 commit comments

Comments
 (0)