Skip to content

gh-131798: JIT: Split CALL_STR_1 into several uops #132849

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_STR_1 is equivalent to str(...).

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 str.

Comment on lines 859 to 863
if (sym_matches_type(arg, &PyUnicode_Type)) {
// e.g. str('foo') or str(foo) where foo is known to be a string
PyObject *value = sym_get_const(ctx, arg);
res = sym_new_const(ctx, value);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This is an optimization that Brandt suggested. When in str(foo), foo is known to be a string, we can propagate it to the output. I also added a test for this case.

Copy link
Member

@brandtbucher brandtbucher left a comment

Choose a reason for hiding this comment

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

Looks great! Just two suggestions:

@tomasr8 tomasr8 requested a review from brandtbucher April 24, 2025 19:52
@brandtbucher brandtbucher merged commit 0a387b3 into python:main Apr 24, 2025
64 checks passed
@tomasr8 tomasr8 deleted the jit-call-str-1 branch April 24, 2025 19:58
@tomasr8
Copy link
Member Author

tomasr8 commented Apr 24, 2025

Thanks for the review!

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.

2 participants