Skip to content

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.

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
Pranjal095 pushed a commit to Pranjal095/cpython that referenced this pull request Jul 12, 2025
taegyunkim pushed a commit to taegyunkim/cpython that referenced this pull request Aug 4, 2025
Agent-Hellboy pushed a commit to Agent-Hellboy/cpython that referenced this pull request Aug 19, 2025
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