Skip to content

gh-131798: JIT: Split CALL_TUPLE_1 into several uops #132851

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 6 commits into from
Apr 24, 2025

Conversation

tomasr8
Copy link
Member

@tomasr8 tomasr8 commented Apr 23, 2025

CALL_TUPLE_1 is equivalent to tuple(...).

Very similar to previous work on splitting up CALL_TYPE_1: #132419
This splits the instruction into a smaller instruction + 2 guards which can be optimized away. This also sets the return type to tuple.

Comment on lines +961 to +964
if (sym_matches_type(arg, &PyTuple_Type)) {
// e.g. tuple((1, 2)) or tuple(foo) where foo is known to be a tuple
res = arg;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same optimization as in #132849 (comment)

x = 0
for _ in range(n):
y = tuple((1, 2)) # tuple argument
a, _ = y # _UNPACK_SEQUENCE_TWO_TUPLE
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I needed to use UNPACK_SEQUENCE(_TWO)_TUPLE here since it is currently the only uop that propagates the tuple items to the result.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice observation. Seems like _BINARY_OP_SUBSCR_TUPLE_INT could be taught how to do this pretty easily for a constant RHS. Want to add that to your queue?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's already in the queue 😄

@brandtbucher brandtbucher merged commit 08e3389 into python:main Apr 24, 2025
68 checks passed
@tomasr8 tomasr8 deleted the jit-call-tuple-1 branch April 25, 2025 05:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants