Skip to content

Commit 3997442

Browse files
committed
gh-148211: decompose [_POP_TWO/_INSERT_2]_LOAD_CONST_INLINE_BORROW in JIT
1 parent 70b86e7 commit 3997442

File tree

8 files changed

+1150
-1417
lines changed

8 files changed

+1150
-1417
lines changed

Include/internal/pycore_uop_ids.h

Lines changed: 1087 additions & 1097 deletions
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: 0 additions & 64 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: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,7 +1643,7 @@ def testfunc(n):
16431643
self.assertIsNotNone(ex)
16441644
uops = get_opnames(ex)
16451645
self.assertNotIn("_BINARY_OP_ADD_INT", uops)
1646-
self.assertNotIn("_POP_TWO_LOAD_CONST_INLINE_BORROW", uops)
1646+
self.assertNotIn("_POP_TWO", uops)
16471647
self.assertNotIn("_GUARD_NOS_INT", uops)
16481648
self.assertNotIn("_GUARD_TOS_INT", uops)
16491649

@@ -1808,7 +1808,6 @@ def testfunc(n):
18081808
self.assertIsNotNone(ex)
18091809
uops = get_opnames(ex)
18101810
self.assertNotIn("_UNARY_NEGATIVE", uops)
1811-
self.assertNotIn("_POP_TOP_LOAD_CONST_INLINE_BORROW", uops)
18121811

18131812
def test_unary_not_pop_top_load_const_inline_borrow(self):
18141813
def testfunc(n):
@@ -1827,9 +1826,9 @@ def testfunc(n):
18271826
self.assertNotIn("_UNARY_NOT", uops)
18281827
# TODO (gh-143723): After refactoring TO_BOOL_INT to eliminate redundant
18291828
# refcounts, 'not a' is now constant-folded and currently lowered to
1830-
# _POP_TOP_LOAD_CONST_INLINE_BORROW. Re-enable once constant folding
1831-
# avoids this fused pop+const uop.
1832-
# self.assertNotIn("_POP_TOP_LOAD_CONST_INLINE_BORROW", uops)
1829+
# _POP_TOP + _LOAD_CONST_INLINE_BORROW. Re-enable once constant folding
1830+
# avoids emitting these.
1831+
# self.assertNotIn("_LOAD_CONST_INLINE_BORROW", uops)
18331832

18341833
def test_unary_invert_insert_1_load_const_inline_borrow(self):
18351834
def testfunc(n):
@@ -1863,7 +1862,7 @@ def testfunc(n):
18631862
self.assertIsNotNone(ex)
18641863
uops = get_opnames(ex)
18651864
self.assertNotIn("_COMPARE_OP", uops)
1866-
self.assertNotIn("_POP_TWO_LOAD_CONST_INLINE_BORROW", uops)
1865+
self.assertNotIn("_POP_TWO", uops)
18671866

18681867
def test_compare_op_int_insert_two_load_const_inline_borrow(self):
18691868
def testfunc(n):
@@ -1880,7 +1879,7 @@ def testfunc(n):
18801879
self.assertIsNotNone(ex)
18811880
uops = get_opnames(ex)
18821881
self.assertNotIn("_COMPARE_OP_INT", uops)
1883-
self.assertIn("_INSERT_2_LOAD_CONST_INLINE_BORROW", uops)
1882+
self.assertIn("_LOAD_CONST_INLINE_BORROW", uops)
18841883

18851884
def test_compare_op_str_insert_two_load_const_inline_borrow(self):
18861885
def testfunc(n):
@@ -1897,7 +1896,7 @@ def testfunc(n):
18971896
self.assertIsNotNone(ex)
18981897
uops = get_opnames(ex)
18991898
self.assertNotIn("_COMPARE_OP_STR", uops)
1900-
self.assertIn("_INSERT_2_LOAD_CONST_INLINE_BORROW", uops)
1899+
self.assertIn("_LOAD_CONST_INLINE_BORROW", uops)
19011900

19021901
def test_compare_op_float_insert_two_load_const_inline_borrow(self):
19031902
def testfunc(n):
@@ -1914,7 +1913,7 @@ def testfunc(n):
19141913
self.assertIsNotNone(ex)
19151914
uops = get_opnames(ex)
19161915
self.assertNotIn("_COMPARE_OP_FLOAT", uops)
1917-
self.assertIn("_INSERT_2_LOAD_CONST_INLINE_BORROW", uops)
1916+
self.assertIn("_LOAD_CONST_INLINE_BORROW", uops)
19181917

19191918
def test_contains_op_pop_two_load_const_inline_borrow(self):
19201919
def testfunc(n):
@@ -1931,7 +1930,7 @@ def testfunc(n):
19311930
self.assertIsNotNone(ex)
19321931
uops = get_opnames(ex)
19331932
self.assertNotIn("_CONTAINS_OP", uops)
1934-
self.assertNotIn("_POP_TWO_LOAD_CONST_INLINE_BORROW", uops)
1933+
self.assertNotIn("_POP_TWO", uops)
19351934

19361935
def test_to_bool_bool_contains_op_set(self):
19371936
"""
@@ -2173,7 +2172,7 @@ def f(n):
21732172
uops = get_opnames(ex)
21742173
self.assertNotIn("_GUARD_TOS_ANY_SET", uops)
21752174
# _CONTAINS_OP_SET is constant-folded away for frozenset literals
2176-
self.assertIn("_INSERT_2_LOAD_CONST_INLINE_BORROW", uops)
2175+
self.assertIn("_LOAD_CONST_INLINE_BORROW", uops)
21772176

21782177
def test_remove_guard_for_known_type_tuple(self):
21792178
def f(n):
@@ -2995,7 +2994,6 @@ def testfunc(n):
29952994
self.assertNotIn("_CALL_ISINSTANCE", uops)
29962995
self.assertNotIn("_TO_BOOL_BOOL", uops)
29972996
self.assertNotIn(self.guard_is_true, uops)
2998-
self.assertNotIn("_POP_TOP_LOAD_CONST_INLINE_BORROW", uops)
29992997

30002998
def test_call_isinstance_is_false(self):
30012999
def testfunc(n):
@@ -3013,7 +3011,6 @@ def testfunc(n):
30133011
self.assertNotIn("_CALL_ISINSTANCE", uops)
30143012
self.assertNotIn("_TO_BOOL_BOOL", uops)
30153013
self.assertNotIn(self.guard_is_false, uops)
3016-
self.assertNotIn("_POP_TOP_LOAD_CONST_INLINE_BORROW", uops)
30173014

30183015
def test_call_isinstance_subclass(self):
30193016
def testfunc(n):
@@ -3031,7 +3028,6 @@ def testfunc(n):
30313028
self.assertNotIn("_CALL_ISINSTANCE", uops)
30323029
self.assertNotIn("_TO_BOOL_BOOL", uops)
30333030
self.assertNotIn(self.guard_is_true, uops)
3034-
self.assertNotIn("_POP_TOP_LOAD_CONST_INLINE_BORROW", uops)
30353031

30363032
def test_call_isinstance_unknown_object(self):
30373033
def testfunc(n):
@@ -4404,7 +4400,7 @@ def testfunc(n):
44044400
self.assertEqual(res, TIER2_THRESHOLD)
44054401
self.assertIsNotNone(ex)
44064402
uops = get_opnames(ex)
4407-
self.assertIn("_INSERT_2_LOAD_CONST_INLINE_BORROW", uops)
4403+
self.assertIn("_LOAD_CONST_INLINE_BORROW", uops)
44084404
self.assertNotIn("_BINARY_OP_SUBSCR_DICT", uops)
44094405

44104406
def test_binary_subscr_frozendict_const_fold(self):
@@ -4634,7 +4630,7 @@ def testfunc(*args):
46344630

46354631
self.assertIn("_LOAD_ATTR_PROPERTY_FRAME", uops)
46364632
# This is a sign the optimizer ran and didn't hit contradiction.
4637-
self.assertIn("_INSERT_2_LOAD_CONST_INLINE_BORROW", uops)
4633+
self.assertIn("_LOAD_CONST_INLINE_BORROW", uops)
46384634

46394635
def test_unary_negative(self):
46404636
def testfunc(n):

Python/bytecodes.c

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5903,11 +5903,6 @@ dummy_func(
59035903
value = PyStackRef_FromPyObjectNew(ptr);
59045904
}
59055905

5906-
tier2 pure op (_POP_TOP_LOAD_CONST_INLINE, (ptr/4, pop -- value)) {
5907-
PyStackRef_CLOSE(pop);
5908-
value = PyStackRef_FromPyObjectNew(ptr);
5909-
}
5910-
59115906
tier2 pure op(_LOAD_CONST_INLINE_BORROW, (ptr/4 -- value)) {
59125907
value = PyStackRef_FromPyObjectBorrow(ptr);
59135908
}
@@ -5933,24 +5928,6 @@ dummy_func(
59335928
PyStackRef_CLOSE(callable);
59345929
}
59355930

5936-
tier2 op(_POP_TOP_LOAD_CONST_INLINE_BORROW, (ptr/4, pop -- value)) {
5937-
PyStackRef_CLOSE(pop);
5938-
value = PyStackRef_FromPyObjectBorrow(ptr);
5939-
}
5940-
5941-
tier2 op(_POP_TWO_LOAD_CONST_INLINE_BORROW, (ptr/4, pop1, pop2 -- value)) {
5942-
PyStackRef_CLOSE(pop2);
5943-
PyStackRef_CLOSE(pop1);
5944-
value = PyStackRef_FromPyObjectBorrow(ptr);
5945-
}
5946-
5947-
tier2 op(_INSERT_2_LOAD_CONST_INLINE_BORROW, (ptr/4, left, right -- res, l, r)) {
5948-
res = PyStackRef_FromPyObjectBorrow(ptr);
5949-
l = left;
5950-
r = right;
5951-
INPUTS_DEAD();
5952-
}
5953-
59545931
tier2 op(_SHUFFLE_3_LOAD_CONST_INLINE_BORROW, (ptr/4, callable, null, arg -- res, a, c)) {
59555932
res = PyStackRef_FromPyObjectBorrow(ptr);
59565933
a = arg;

0 commit comments

Comments
 (0)