Skip to content

Commit 899c0e0

Browse files
Merge remote-tracking branch 'upstream/main' into decreF_elim_binop
2 parents c549ac6 + 059316a commit 899c0e0

File tree

10 files changed

+67
-16
lines changed

10 files changed

+67
-16
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
@@ -2557,6 +2557,23 @@ def testfunc(n):
25572557
self.assertNotIn("_GUARD_TOS_INT", uops)
25582558
self.assertNotIn("_GUARD_NOS_INT", uops)
25592559

2560+
def test_store_attr_instance_value(self):
2561+
def testfunc(n):
2562+
class C:
2563+
pass
2564+
c = C()
2565+
for i in range(n):
2566+
c.a = i
2567+
return c.a
2568+
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
2569+
self.assertEqual(res, TIER2_THRESHOLD - 1)
2570+
self.assertIsNotNone(ex)
2571+
uops = get_opnames(ex)
2572+
2573+
self.assertIn("_STORE_ATTR_INSTANCE_VALUE", uops)
2574+
self.assertNotIn("_POP_TOP", uops)
2575+
self.assertIn("_POP_TOP_NOP", uops)
2576+
25602577
def test_store_subscr_int(self):
25612578
def testfunc(n):
25622579
l = [0, 0, 0, 0]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Eliminate redundant refcounting from ``_STORE_ATTR_INSTANCE_VALUE``.

Python/bytecodes.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2575,7 +2575,7 @@ dummy_func(
25752575
}
25762576
}
25772577

2578-
op(_STORE_ATTR_INSTANCE_VALUE, (offset/1, value, owner --)) {
2578+
op(_STORE_ATTR_INSTANCE_VALUE, (offset/1, value, owner -- o)) {
25792579
PyObject *owner_o = PyStackRef_AsPyObjectBorrow(owner);
25802580

25812581
STAT_INC(STORE_ATTR, hit);
@@ -2589,15 +2589,17 @@ dummy_func(
25892589
_PyDictValues_AddToInsertionOrder(values, index);
25902590
}
25912591
UNLOCK_OBJECT(owner_o);
2592-
PyStackRef_CLOSE(owner);
2592+
o = owner;
2593+
DEAD(owner);
25932594
Py_XDECREF(old_value);
25942595
}
25952596

25962597
macro(STORE_ATTR_INSTANCE_VALUE) =
25972598
unused/1 +
25982599
_GUARD_TYPE_VERSION_AND_LOCK +
25992600
_GUARD_DORV_NO_DICT +
2600-
_STORE_ATTR_INSTANCE_VALUE;
2601+
_STORE_ATTR_INSTANCE_VALUE +
2602+
POP_TOP;
26012603

26022604
op(_STORE_ATTR_WITH_HINT, (hint/1, value, owner --)) {
26032605
PyObject *owner_o = PyStackRef_AsPyObjectBorrow(owner);

Python/executor_cases.c.h

Lines changed: 10 additions & 4 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: 13 additions & 2 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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ dummy_func(void) {
9999
GETLOCAL(oparg) = temp;
100100
}
101101

102+
op(_STORE_ATTR_INSTANCE_VALUE, (offset/1, value, owner -- o)) {
103+
(void)value;
104+
o = owner;
105+
}
106+
102107
op(_STORE_FAST, (value --)) {
103108
GETLOCAL(oparg) = value;
104109
}

Python/optimizer_cases.c.h

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