Skip to content

Commit 33d94ab

Browse files
authored
gh-134584: Eliminate redundant refcounting from _BINARY_OP_SUBSCR_LIST_INT (GH-142926)
1 parent f54d44d commit 33d94ab

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
@@ -2988,6 +2988,24 @@ class Obj:
29882988
for _ in range(TIER2_THRESHOLD+1):
29892989
obj.attr = EvilAttr(obj.__dict__)
29902990

2991+
def test_binary_subscr_list_int(self):
2992+
def testfunc(n):
2993+
l = [1]
2994+
x = 0
2995+
for _ in range(n):
2996+
y = l[0]
2997+
x += y
2998+
return x
2999+
3000+
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
3001+
self.assertEqual(res, TIER2_THRESHOLD)
3002+
self.assertIsNotNone(ex)
3003+
uops = get_opnames(ex)
3004+
3005+
self.assertIn("_BINARY_OP_SUBSCR_LIST_INT", uops)
3006+
self.assertNotIn("_POP_TOP", uops)
3007+
self.assertNotIn("_POP_TOP_INT", uops)
3008+
self.assertIn("_POP_TOP_NOP", uops)
29913009

29923010
def global_identity(x):
29933011
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
@@ -1417,6 +1417,12 @@ dummy_func(void) {
14171417
}
14181418
}
14191419

1420+
op(_BINARY_OP_SUBSCR_LIST_INT, (list_st, sub_st -- res, ls, ss)) {
1421+
res = sym_new_unknown(ctx);
1422+
ls = list_st;
1423+
ss = sub_st;
1424+
}
1425+
14201426

14211427
// END BYTECODES //
14221428

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)