Skip to content

Commit 8b1ded5

Browse files
committed
Eliminate redundant refcounting from _BINARY_OP_SUBSCR_LIST_INT
1 parent 8b64dd8 commit 8b1ded5

File tree

9 files changed

+74
-38
lines changed

9 files changed

+74
-38
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: 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
@@ -2972,6 +2972,24 @@ class Obj:
29722972
for _ in range(TIER2_THRESHOLD+1):
29732973
obj.attr = EvilAttr(obj.__dict__)
29742974

2975+
def test_binary_subscr_list_int(self):
2976+
def testfunc(n):
2977+
l = [1]
2978+
x = 0
2979+
for _ in range(n):
2980+
y = l[0]
2981+
x += y
2982+
return x
2983+
2984+
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
2985+
self.assertEqual(res, TIER2_THRESHOLD)
2986+
self.assertIsNotNone(ex)
2987+
uops = get_opnames(ex)
2988+
2989+
self.assertIn("_BINARY_OP_SUBSCR_LIST_INT", uops)
2990+
self.assertNotIn("_POP_TOP", uops)
2991+
self.assertNotIn("_POP_TOP_INT", uops)
2992+
self.assertIn("_POP_TOP_NOP", uops)
29752993

29762994
def global_identity(x):
29772995
return x

Python/bytecodes.c

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

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

896-
op(_BINARY_OP_SUBSCR_LIST_INT, (list_st, sub_st -- res)) {
896+
op(_BINARY_OP_SUBSCR_LIST_INT, (list_st, sub_st -- res, ls, ss)) {
897897
PyObject *sub = PyStackRef_AsPyObjectBorrow(sub_st);
898898
PyObject *list = PyStackRef_AsPyObjectBorrow(list_st);
899899

@@ -916,7 +916,9 @@ dummy_func(
916916
res = PyStackRef_FromPyObjectNew(res_o);
917917
#endif
918918
STAT_INC(BINARY_OP, hit);
919-
DECREF_INPUTS();
919+
ls = list_st;
920+
ss = sub_st;
921+
INPUTS_DEAD();
920922
}
921923

922924
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
@@ -1409,6 +1409,12 @@ dummy_func(void) {
14091409
}
14101410
}
14111411

1412+
op(_BINARY_OP_SUBSCR_LIST_INT, (list_st, sub_st -- res, ls, ss)) {
1413+
res = sym_new_unknown(ctx);
1414+
ls = list_st;
1415+
ss = sub_st;
1416+
}
1417+
14121418

14131419
// END BYTECODES //
14141420

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)