FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

GH-131798: Optimize `_GUARD_TOS_SLICE` by Sacul0457 · Pull Request #144470 · python/cpython · GitHub

Repository navigation

Merged
17 changes: 17 additions & 0 deletions Lib/test/test_capi/test_opt.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2030,6 +2030,23 @@ def f(n):
self.assertNotIn("_GUARD_NOS_TUPLE", uops)
self.assertIn("_BINARY_OP_SUBSCR_TUPLE_INT", uops)

def test_remove_guard_for_known_type_slice(self):
def f(n):
x = 0
for _ in range(n):
l = [1, 2, 3]
slice_obj = slice(0, 1)
x += l[slice_obj][0] # guarded
x += l[slice_obj][0] # unguarded
return x
res, ex = self._run_with_optimizer(f, TIER2_THRESHOLD)
self.assertEqual(res, TIER2_THRESHOLD * 2)
uops = get_opnames(ex)

count = count_ops(ex, "_GUARD_TOS_SLICE")
self.assertEqual(count, 1)
self.assertIn("_BINARY_OP_SUBSCR_LIST_INT", uops)

def test_remove_guard_for_tuple_bounds_check(self):
def f(n):
x = 0
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Optimise ``_GUARD_TOS_SLICE`` in the JIT.
7 changes: 7 additions & 0 deletions Python/optimizer_bytecodes.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1417,6 +1417,13 @@ dummy_func(void) {
}
}

op(_GUARD_TOS_SLICE, (tos -- tos)) {
if (sym_matches_type(tos, &PySlice_Type)) {
ADD_OP(_NOP, 0, 0);
}
sym_set_type(tos, &PySlice_Type);
}

op(_GUARD_NOS_NULL, (null, unused -- null, unused)) {
if (sym_is_null(null)) {
ADD_OP(_NOP, 0, 0);
Expand Down
6 changes: 6 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

Back | FazBrowse Home | New Git URL