Skip to content

Commit 2625e09

Browse files
committed
gh-134584: Eliminate redundant refcounting from _STORE_SUBSCR_LIST_INT
1 parent d3ef5ba commit 2625e09

File tree

8 files changed

+73
-21
lines changed

8 files changed

+73
-21
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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2470,6 +2470,23 @@ def testfunc(n):
24702470
self.assertNotIn("_GUARD_TOS_INT", uops)
24712471
self.assertNotIn("_GUARD_NOS_INT", uops)
24722472

2473+
def test_store_subscr_int(self):
2474+
def testfunc(n):
2475+
l = [0, 0, 0, 0]
2476+
for _ in range(n):
2477+
l[0] = 1
2478+
l[1] = 2
2479+
l[2] = 3
2480+
l[3] = 4
2481+
return sum(l)
2482+
2483+
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
2484+
self.assertEqual(res, 10)
2485+
self.assertIsNotNone(ex)
2486+
uops = get_opnames(ex)
2487+
self.assertIn("_POP_TOP_INT", uops)
2488+
self.assertNotIn("_POP_TOP_NOP", uops)
2489+
24732490
def test_attr_promotion_failure(self):
24742491
# We're not testing for any specific uops here, just
24752492
# testing it doesn't crash.

Python/bytecodes.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,9 +1126,9 @@ dummy_func(
11261126
macro(STORE_SUBSCR) = _SPECIALIZE_STORE_SUBSCR + _STORE_SUBSCR;
11271127

11281128
macro(STORE_SUBSCR_LIST_INT) =
1129-
_GUARD_TOS_INT + _GUARD_NOS_LIST + unused/1 + _STORE_SUBSCR_LIST_INT;
1129+
_GUARD_TOS_INT + _GUARD_NOS_LIST + unused/1 + _STORE_SUBSCR_LIST_INT + POP_TOP + _POP_TOP_INT;
11301130

1131-
op(_STORE_SUBSCR_LIST_INT, (value, list_st, sub_st -- )) {
1131+
op(_STORE_SUBSCR_LIST_INT, (value, list_st, sub_st -- ss, ls)) {
11321132
PyObject *sub = PyStackRef_AsPyObjectBorrow(sub_st);
11331133
PyObject *list = PyStackRef_AsPyObjectBorrow(list_st);
11341134

@@ -1151,9 +1151,9 @@ dummy_func(
11511151
PyStackRef_AsPyObjectSteal(value));
11521152
assert(old_value != NULL);
11531153
UNLOCK_OBJECT(list); // unlock before decrefs!
1154-
PyStackRef_CLOSE_SPECIALIZED(sub_st, _PyLong_ExactDealloc);
1155-
DEAD(sub_st);
1156-
PyStackRef_CLOSE(list_st);
1154+
INPUTS_DEAD();
1155+
ss = sub_st;
1156+
ls = list_st;
11571157
Py_DECREF(old_value);
11581158
}
11591159

Python/executor_cases.c.h

Lines changed: 14 additions & 6 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: 24 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/optimizer_cases.c.h

Lines changed: 8 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)