Skip to content

Commit 72006a7

Browse files
authored
gh-148211: decompose [_POP_TWO/_INSERT_2]_LOAD_CONST_INLINE_BORROW in JIT (GH-148357)
1 parent 639f218 commit 72006a7

File tree

8 files changed

+1151
-1418
lines changed

8 files changed

+1151
-1418
lines changed

Include/internal/pycore_uop_ids.h

Lines changed: 1088 additions & 1098 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):
@@ -3010,7 +3009,6 @@ def testfunc(n):
30103009
self.assertNotIn("_CALL_ISINSTANCE", uops)
30113010
self.assertNotIn("_TO_BOOL_BOOL", uops)
30123011
self.assertNotIn(self.guard_is_true, uops)
3013-
self.assertNotIn("_POP_TOP_LOAD_CONST_INLINE_BORROW", uops)
30143012

30153013
def test_call_isinstance_is_false(self):
30163014
def testfunc(n):
@@ -3028,7 +3026,6 @@ def testfunc(n):
30283026
self.assertNotIn("_CALL_ISINSTANCE", uops)
30293027
self.assertNotIn("_TO_BOOL_BOOL", uops)
30303028
self.assertNotIn(self.guard_is_false, uops)
3031-
self.assertNotIn("_POP_TOP_LOAD_CONST_INLINE_BORROW", uops)
30323029

30333030
def test_call_isinstance_subclass(self):
30343031
def testfunc(n):
@@ -3046,7 +3043,6 @@ def testfunc(n):
30463043
self.assertNotIn("_CALL_ISINSTANCE", uops)
30473044
self.assertNotIn("_TO_BOOL_BOOL", uops)
30483045
self.assertNotIn(self.guard_is_true, uops)
3049-
self.assertNotIn("_POP_TOP_LOAD_CONST_INLINE_BORROW", uops)
30503046

30513047
def test_call_isinstance_unknown_object(self):
30523048
def testfunc(n):
@@ -4419,7 +4415,7 @@ def testfunc(n):
44194415
self.assertEqual(res, TIER2_THRESHOLD)
44204416
self.assertIsNotNone(ex)
44214417
uops = get_opnames(ex)
4422-
self.assertIn("_INSERT_2_LOAD_CONST_INLINE_BORROW", uops)
4418+
self.assertIn("_LOAD_CONST_INLINE_BORROW", uops)
44234419
self.assertNotIn("_BINARY_OP_SUBSCR_DICT", uops)
44244420

44254421
def test_binary_subscr_frozendict_const_fold(self):
@@ -4649,7 +4645,7 @@ def testfunc(*args):
46494645

46504646
self.assertIn("_LOAD_ATTR_PROPERTY_FRAME", uops)
46514647
# This is a sign the optimizer ran and didn't hit contradiction.
4652-
self.assertIn("_INSERT_2_LOAD_CONST_INLINE_BORROW", uops)
4648+
self.assertIn("_LOAD_CONST_INLINE_BORROW", uops)
46534649

46544650
def test_unary_negative(self):
46554651
def testfunc(n):

Python/bytecodes.c

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5918,11 +5918,6 @@ dummy_func(
59185918
value = PyStackRef_FromPyObjectNew(ptr);
59195919
}
59205920

5921-
tier2 pure op (_POP_TOP_LOAD_CONST_INLINE, (ptr/4, pop -- value)) {
5922-
PyStackRef_CLOSE(pop);
5923-
value = PyStackRef_FromPyObjectNew(ptr);
5924-
}
5925-
59265921
tier2 pure op(_LOAD_CONST_INLINE_BORROW, (ptr/4 -- value)) {
59275922
value = PyStackRef_FromPyObjectBorrow(ptr);
59285923
}
@@ -5948,24 +5943,6 @@ dummy_func(
59485943
PyStackRef_CLOSE(callable);
59495944
}
59505945

5951-
tier2 op(_POP_TOP_LOAD_CONST_INLINE_BORROW, (ptr/4, pop -- value)) {
5952-
PyStackRef_CLOSE(pop);
5953-
value = PyStackRef_FromPyObjectBorrow(ptr);
5954-
}
5955-
5956-
tier2 op(_POP_TWO_LOAD_CONST_INLINE_BORROW, (ptr/4, pop1, pop2 -- value)) {
5957-
PyStackRef_CLOSE(pop2);
5958-
PyStackRef_CLOSE(pop1);
5959-
value = PyStackRef_FromPyObjectBorrow(ptr);
5960-
}
5961-
5962-
tier2 op(_INSERT_2_LOAD_CONST_INLINE_BORROW, (ptr/4, left, right -- res, l, r)) {
5963-
res = PyStackRef_FromPyObjectBorrow(ptr);
5964-
l = left;
5965-
r = right;
5966-
INPUTS_DEAD();
5967-
}
5968-
59695946
tier2 op(_SHUFFLE_3_LOAD_CONST_INLINE_BORROW, (ptr/4, callable, null, arg -- res, a, c)) {
59705947
res = PyStackRef_FromPyObjectBorrow(ptr);
59715948
a = arg;

0 commit comments

Comments
 (0)