Skip to content

Commit a1cf3a8

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

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

Lib/test/test_capi/test_opt.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2642,6 +2642,9 @@ def testfunc(n):
26422642
uops = get_opnames(ex)
26432643
# When the result of type(...) is known, _CALL_TYPE_1 is decomposed.
26442644
self.assertNotIn("_CALL_TYPE_1", uops)
2645+
# _CALL_TYPE_1 produces 2 _POP_TOP_NOP (callable and null)
2646+
# type(42) is int produces 4 _POP_TOP_NOP
2647+
self.assertGreaterEqual(count_ops(ex, "_POP_TOP_NOP"), 6)
26452648

26462649
def test_call_type_1_result_is_const(self):
26472650
def testfunc(n):

Python/optimizer_bytecodes.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,13 +1480,13 @@ dummy_func(void) {
14801480
next = sym_new_type(ctx, &PyLong_Type);
14811481
}
14821482

1483-
op(_CALL_TYPE_1, (unused, unused, arg -- res, a)) {
1483+
op(_CALL_TYPE_1, (callable, null, arg -- res, a)) {
14841484
PyObject* type = (PyObject *)sym_get_type(arg);
14851485
if (type) {
14861486
res = sym_new_const(ctx, type);
14871487
ADD_OP(_SWAP, 3, 0);
1488-
ADD_OP(_POP_TOP, 0, 0);
1489-
ADD_OP(_POP_TOP, 0, 0);
1488+
optimize_pop_top(ctx, this_instr, callable);
1489+
optimize_pop_top(ctx, this_instr, null);
14901490
ADD_OP(_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)type);
14911491
ADD_OP(_SWAP, 2, 0);
14921492
}
@@ -1509,7 +1509,7 @@ dummy_func(void) {
15091509
a = arg;
15101510
}
15111511

1512-
op(_CALL_ISINSTANCE, (unused, unused, instance, cls -- res)) {
1512+
op(_CALL_ISINSTANCE, (callable, null, instance, cls -- res)) {
15131513
// the result is always a bool, but sometimes we can
15141514
// narrow it down to True or False
15151515
res = sym_new_type(ctx, &PyBool_Type);
@@ -1525,10 +1525,10 @@ dummy_func(void) {
15251525
out = Py_True;
15261526
}
15271527
sym_set_const(res, out);
1528-
ADD_OP(_POP_TOP, 0, 0);
1529-
ADD_OP(_POP_TOP, 0, 0);
1530-
ADD_OP(_POP_TOP_NOP, 0, 0);
1531-
ADD_OP(_POP_TOP, 0, 0);
1528+
optimize_pop_top(ctx, this_instr, cls);
1529+
optimize_pop_top(ctx, this_instr, instance);
1530+
optimize_pop_top(ctx, this_instr, null);
1531+
optimize_pop_top(ctx, this_instr, callable);
15321532
ADD_OP(_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)out);
15331533
}
15341534
}

Python/optimizer_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.

0 commit comments

Comments
 (0)