Skip to content

gh-134584: Decref elimination for float ops in the JIT #134588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Jun 17, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9466417
Skip refcounting where possible for common float ops
Fidget-Spinner May 23, 2025
ad03b1e
Add for common list ops
Fidget-Spinner May 23, 2025
7f90d0c
Fix test, rename
Fidget-Spinner May 23, 2025
a42b434
Remove list optimizations to minimize PR
Fidget-Spinner May 23, 2025
f456740
📜🤖 Added by blurb_it.
blurb-it[bot] May 23, 2025
16f9dee
Merge remote-tracking branch 'upstream/main' into decref_elimination_…
Fidget-Spinner May 27, 2025
5c429b6
Rename things to make things clearer
Fidget-Spinner May 27, 2025
1535133
Revert "Rename things to make things clearer"
Fidget-Spinner May 27, 2025
8f62067
Massive refactor from JitOptSymbol to JitRef
Fidget-Spinner May 28, 2025
a158835
refactor more
Fidget-Spinner May 28, 2025
e77f842
fix debug build
Fidget-Spinner May 28, 2025
01004c2
lint
Fidget-Spinner May 28, 2025
24f98d5
Merge remote-tracking branch 'upstream/main' into decref_elimination_…
Fidget-Spinner May 28, 2025
0189413
fix upstream
Fidget-Spinner May 28, 2025
4a386bf
reduce diff
Fidget-Spinner May 28, 2025
ac034a0
fix for FT
Fidget-Spinner May 28, 2025
b6e467e
fix failing tests
Fidget-Spinner May 28, 2025
3a3fa9d
Fix for disabled GIL
Fidget-Spinner May 29, 2025
ab1ad9c
fix on FT again
Fidget-Spinner May 29, 2025
5d82489
Try fix windows
Fidget-Spinner May 29, 2025
4d9a68e
Apply code review suggestions from Tomas
Fidget-Spinner Jun 4, 2025
2bbd47a
call the functions sym instead of ref
Fidget-Spinner Jun 4, 2025
2d779c4
rename jitref functions
Fidget-Spinner Jun 4, 2025
b74e160
Address review
Fidget-Spinner Jun 4, 2025
3ebcc20
Update comment
Fidget-Spinner Jun 4, 2025
673d5c8
Merge remote-tracking branch 'upstream/main' into decref_elimination_…
Fidget-Spinner Jun 17, 2025
914f1ff
Fix changes from upstream (no more casts)
Fidget-Spinner Jun 17, 2025
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
Prev Previous commit
Next Next commit
Fix test, rename
  • Loading branch information
Fidget-Spinner committed May 23, 2025
commit 7f90d0cf7357b2b703110c685311fbac5f317ac1
10 changes: 5 additions & 5 deletions Include/internal/pycore_uop_ids.h

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

30 changes: 15 additions & 15 deletions Include/internal/pycore_uop_metadata.h

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

12 changes: 6 additions & 6 deletions Lib/test/test_capi/test_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ def testfunc(n):
self.assertLessEqual(len(guard_nos_float_count), 1)
# TODO gh-115506: this assertion may change after propagating constants.
# We'll also need to verify that propagation actually occurs.
self.assertIn("_BINARY_OP_ADD_FLOAT__NO_INPUT_DECREF", uops)
self.assertIn("_BINARY_OP_ADD_FLOAT__NO_DECREF_INPUTS", uops)

def test_float_subtract_constant_propagation(self):
def testfunc(n):
Expand All @@ -700,7 +700,7 @@ def testfunc(n):
self.assertLessEqual(len(guard_nos_float_count), 1)
# TODO gh-115506: this assertion may change after propagating constants.
# We'll also need to verify that propagation actually occurs.
self.assertIn("_BINARY_OP_SUBTRACT_FLOAT__NO_INPUT_DECREF", uops)
self.assertIn("_BINARY_OP_SUBTRACT_FLOAT__NO_DECREF_INPUTS", uops)

def test_float_multiply_constant_propagation(self):
def testfunc(n):
Expand All @@ -722,7 +722,7 @@ def testfunc(n):
self.assertLessEqual(len(guard_nos_float_count), 1)
# TODO gh-115506: this assertion may change after propagating constants.
# We'll also need to verify that propagation actually occurs.
self.assertIn("_BINARY_OP_MULTIPLY_FLOAT__NO_INPUT_DECREF", uops)
self.assertIn("_BINARY_OP_MULTIPLY_FLOAT__NO_DECREF_INPUTS", uops)

def test_add_unicode_propagation(self):
def testfunc(n):
Expand Down Expand Up @@ -1707,10 +1707,10 @@ def f(n):
self.assertIsNotNone(ex)
uops = get_opnames(ex)
self.assertEqual(uops.count("_GUARD_NOS_LIST"), 0)
self.assertEqual(uops.count("_STORE_SUBSCR_LIST_INT"), 1)
self.assertEqual(uops.count("_STORE_SUBSCR_LIST_INT__NO_DECREF_INPUTS"), 1)
self.assertEqual(uops.count("_GUARD_TOS_LIST"), 0)
self.assertEqual(uops.count("_UNPACK_SEQUENCE_LIST"), 1)
self.assertEqual(uops.count("_BINARY_OP_SUBSCR_LIST_INT"), 1)
self.assertEqual(uops.count("_BINARY_OP_SUBSCR_LIST_INT__NO_DECREF_INPUTS"), 1)
self.assertEqual(uops.count("_TO_BOOL_LIST"), 1)

def test_remove_guard_for_known_type_set(self):
Expand Down Expand Up @@ -2231,7 +2231,7 @@ def testfunc(args):
self.assertAlmostEqual(res, TIER2_THRESHOLD * (0.1 + 0.1))
self.assertIsNotNone(ex)
uops = get_opnames(ex)
self.assertIn("_BINARY_OP_ADD_FLOAT__NO_INPUT_DECREF", uops)
self.assertIn("_BINARY_OP_ADD_FLOAT__NO_DECREF_INPUTS", uops)


def global_identity(x):
Expand Down
10 changes: 5 additions & 5 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ dummy_func(
}


pure op(_BINARY_OP_MULTIPLY_FLOAT__NO_INPUT_DECREF, (left, right -- res)) {
pure op(_BINARY_OP_MULTIPLY_FLOAT__NO_DECREF_INPUTS, (left, right -- res)) {
PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
PyObject *right_o = PyStackRef_AsPyObjectBorrow(right);
assert(PyFloat_CheckExact(left_o));
Expand All @@ -693,7 +693,7 @@ dummy_func(
ERROR_IF(PyStackRef_IsNull(res));
}

pure op(_BINARY_OP_ADD_FLOAT__NO_INPUT_DECREF, (left, right -- res)) {
pure op(_BINARY_OP_ADD_FLOAT__NO_DECREF_INPUTS, (left, right -- res)) {
PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
PyObject *right_o = PyStackRef_AsPyObjectBorrow(right);
assert(PyFloat_CheckExact(left_o));
Expand All @@ -708,7 +708,7 @@ dummy_func(
ERROR_IF(PyStackRef_IsNull(res));
}

pure op(_BINARY_OP_SUBTRACT_FLOAT__NO_INPUT_DECREF, (left, right -- res)) {
pure op(_BINARY_OP_SUBTRACT_FLOAT__NO_DECREF_INPUTS, (left, right -- res)) {
PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
PyObject *right_o = PyStackRef_AsPyObjectBorrow(right);
assert(PyFloat_CheckExact(left_o));
Expand Down Expand Up @@ -907,7 +907,7 @@ dummy_func(
DECREF_INPUTS();
}

op(_BINARY_OP_SUBSCR_LIST_INT__NO_INPUT_DECREF, (list_st, sub_st -- res)) {
op(_BINARY_OP_SUBSCR_LIST_INT__NO_DECREF_INPUTS, (list_st, sub_st -- res)) {
PyObject *sub = PyStackRef_AsPyObjectBorrow(sub_st);
PyObject *list = PyStackRef_AsPyObjectBorrow(list_st);

Expand Down Expand Up @@ -1135,7 +1135,7 @@ dummy_func(
Py_DECREF(old_value);
}

op(_STORE_SUBSCR_LIST_INT__NO_INPUT_DECREF, (value, list_st, sub_st -- )) {
op(_STORE_SUBSCR_LIST_INT__NO_DECREF_INPUTS, (value, list_st, sub_st -- )) {
PyObject *sub = PyStackRef_AsPyObjectBorrow(sub_st);
PyObject *list = PyStackRef_AsPyObjectBorrow(list_st);

Expand Down
10 changes: 5 additions & 5 deletions Python/executor_cases.c.h

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

10 changes: 5 additions & 5 deletions Python/optimizer_analysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,11 +445,11 @@ get_code_with_logging(_PyUOpInstruction *op)

// TODO (gh-134584) generate most of this table automatically
const uint16_t op_without_decref_inputs[MAX_UOP_ID + 1] = {
[_BINARY_OP_MULTIPLY_FLOAT] = _BINARY_OP_MULTIPLY_FLOAT__NO_INPUT_DECREF,
[_BINARY_OP_ADD_FLOAT] = _BINARY_OP_ADD_FLOAT__NO_INPUT_DECREF,
[_BINARY_OP_SUBTRACT_FLOAT] = _BINARY_OP_SUBTRACT_FLOAT__NO_INPUT_DECREF,
[_STORE_SUBSCR_LIST_INT] = _STORE_SUBSCR_LIST_INT__NO_INPUT_DECREF,
[_BINARY_OP_SUBSCR_LIST_INT] = _BINARY_OP_SUBSCR_LIST_INT__NO_INPUT_DECREF,
[_BINARY_OP_MULTIPLY_FLOAT] = _BINARY_OP_MULTIPLY_FLOAT__NO_DECREF_INPUTS,
[_BINARY_OP_ADD_FLOAT] = _BINARY_OP_ADD_FLOAT__NO_DECREF_INPUTS,
[_BINARY_OP_SUBTRACT_FLOAT] = _BINARY_OP_SUBTRACT_FLOAT__NO_DECREF_INPUTS,
[_STORE_SUBSCR_LIST_INT] = _STORE_SUBSCR_LIST_INT__NO_DECREF_INPUTS,
[_BINARY_OP_SUBSCR_LIST_INT] = _BINARY_OP_SUBSCR_LIST_INT__NO_DECREF_INPUTS,
};

/* 1 for success, 0 for not ready, cannot error at the moment. */
Expand Down
10 changes: 5 additions & 5 deletions Python/optimizer_cases.c.h

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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy