Skip to content

Commit c9261a8

Browse files
committed
gh-148604: change ADD_OP(_POP_TOP, ...) to optimize_pop_top in optimizer_bytecodes.c
1 parent c7e9919 commit c9261a8

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

Lib/test/test_capi/test_opt.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3453,6 +3453,10 @@ def f(n):
34533453
self.assertEqual(res, TIER2_THRESHOLD)
34543454
uops = get_opnames(ex)
34553455
self.assertNotIn("_LOAD_SPECIAL", uops)
3456+
# __enter__/__exit__ produce 2 _POP_TOP_NOP
3457+
# x += 1 produces 2 _POP_TOP_NOP
3458+
# __exit__()'s None return produces 1 _POP_TOP_NOP
3459+
self.assertGreaterEqual(count_ops(ex, "_POP_TOP_NOP"), 5)
34563460

34573461
def test_store_fast_refcount_elimination(self):
34583462
def foo(x):

Python/optimizer_bytecodes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1902,7 +1902,7 @@ dummy_func(void) {
19021902
ADD_OP(immortal ? _LOAD_CONST_INLINE_BORROW : _LOAD_CONST_INLINE,
19031903
0, (uintptr_t)descr);
19041904
ADD_OP(_SWAP, 3, 0);
1905-
ADD_OP(_POP_TOP, 0, 0);
1905+
optimize_pop_top(ctx, this_instr, method_and_self[0]);
19061906
if ((type->tp_flags & Py_TPFLAGS_IMMUTABLETYPE) == 0) {
19071907
PyType_Watch(TYPE_WATCHER_ID, (PyObject *)type);
19081908
_Py_BloomFilter_Add(dependencies, type);

Python/optimizer_cases.c.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.

0 commit comments

Comments
 (0)