Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Lib/test/test_capi/test_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3858,6 +3858,20 @@ def testfunc(n):
self.assertIn("_POP_TOP_NOP", uops)
self.assertLessEqual(count_ops(ex, "_POP_TOP"), 2)

def test_iter_check_list(self):
def testfunc(n):
x = 0
for _ in range(n):
l = [1]
for num in l: # unguarded
x += num
return x
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
self.assertEqual(res, TIER2_THRESHOLD)
uops = get_opnames(ex)

self.assertIn("_BUILD_LIST", uops)
self.assertNotIn("_ITER_CHECK_LIST", uops)

def test_143026(self):
# https://github.com/python/cpython/issues/143026
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Optimize ``_ITER_CHECK_RANGE`` and ``_ITER_CHECK_LIST`` in the JIT
14 changes: 14 additions & 0 deletions Python/optimizer_bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,20 @@ dummy_func(void) {
sym_set_type(iter, &PyTuple_Type);
}

op(_ITER_CHECK_LIST, (iter, null_or_index -- iter, null_or_index)) {
if (sym_matches_type(iter, &PyList_Type)) {
ADD_OP(_NOP, 0, 0);
}
sym_set_type(iter, &PyList_Type);
}

op(_ITER_CHECK_RANGE, (iter, null_or_index -- iter, null_or_index)) {
if (sym_matches_type(iter, &PyRange_Type)) {
ADD_OP(_NOP, 0, 0);
}
sym_set_type(iter, &PyRange_Type);
}

op(_ITER_NEXT_RANGE, (iter, null_or_index -- iter, null_or_index, next)) {
next = sym_new_type(ctx, &PyLong_Type);
}
Expand Down
12 changes: 12 additions & 0 deletions Python/optimizer_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading