Skip to content

gh-131798: JIT: Optimize _CALL_TYPE_1 when the result is known #135194

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 4 commits into from
Jun 6, 2025

Conversation

tomasr8
Copy link
Member

@tomasr8 tomasr8 commented Jun 5, 2025

Followup to #134369 (comment)

This completely removes _CALL_TYPE_1 when the abstract interpreter is able to deduce the result (by knowing the type of the argument).

For example, for something like type(42), we currently do

_LOAD_CONST_INLINE_BORROW (callable: type)
_PUSH_NULL
_LOAD_CONST_INLINE_BORROW (arg: 42)
_CALL_TYPE_1

Note that we still do the call even when we know the result.

In this PR, when the result is known, _CALL_TYPE_1 is replaced with _POP_CALL_ONE_LOAD_CONST_INLINE_BORROW:

_LOAD_CONST_INLINE_BORROW (callable: type)
_PUSH_NULL
_LOAD_CONST_INLINE_BORROW (arg: 42)
- _CALL_TYPE_1
+ _POP_CALL_ONE_LOAD_CONST_INLINE_BORROW (arg: int)

Thanks to some previous work on optimizing remove_unneeded_uops this becomes just:

_LOAD_CONST_INLINE_BORROW (arg: int)

that is, the entire call is replaced with a load.

@tomasr8
Copy link
Member Author

tomasr8 commented Jun 6, 2025

The test failures should be fixed by #135204, let me update main to make sure CI is all green :)

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.

Even more JIT magic, I love it.

@@ -1806,7 +1826,6 @@ def testfunc(n):
self.assertEqual(res, TIER2_THRESHOLD)
self.assertIsNotNone(ex)
uops = get_opnames(ex)
self.assertIn("_CALL_TYPE_1", uops)
Copy link
Member

Choose a reason for hiding this comment

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

Super cool when older tests like this "break" with a new optimization. :)

@brandtbucher brandtbucher merged commit 4615164 into python:main Jun 6, 2025
54 checks passed
@tomasr8 tomasr8 deleted the optimize-call-type-1 branch June 7, 2025 06:03
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