Skip to content

gh-148211: decompose _POP_TOP_LOAD_CONST_INLINE(_BORROW) in JIT#148230

Merged
Fidget-Spinner merged 4 commits intopython:mainfrom
NekoAsakura:gh-148211/decompose-pop-top
Apr 8, 2026
Merged

gh-148211: decompose _POP_TOP_LOAD_CONST_INLINE(_BORROW) in JIT#148230
Fidget-Spinner merged 4 commits intopython:mainfrom
NekoAsakura:gh-148211/decompose-pop-top

Conversation

@NekoAsakura
Copy link
Copy Markdown
Contributor

@NekoAsakura NekoAsakura commented Apr 7, 2026

The composite uop definitions in bytecodes.c are kept for now — remove_unneeded_uops still produces them as intermediate forms during push/pop cancellation.

const uint16_t op_without_push[MAX_UOP_ID + 1] = {
[_COPY] = _NOP,
[_LOAD_CONST_INLINE] = _NOP,
[_LOAD_CONST_INLINE_BORROW] = _NOP,
[_LOAD_CONST_UNDER_INLINE] = _POP_TOP_LOAD_CONST_INLINE,
[_LOAD_CONST_UNDER_INLINE_BORROW] = _POP_TOP_LOAD_CONST_INLINE_BORROW,
[_LOAD_FAST] = _NOP,
[_LOAD_FAST_BORROW] = _NOP,
[_LOAD_SMALL_INT] = _NOP,
[_POP_TOP_LOAD_CONST_INLINE] = _POP_TOP,
[_POP_TOP_LOAD_CONST_INLINE_BORROW] = _POP_TOP,
[_POP_TWO_LOAD_CONST_INLINE_BORROW] = _POP_TWO,
[_POP_CALL_ONE_LOAD_CONST_INLINE_BORROW] = _POP_CALL_ONE,
[_POP_CALL_TWO_LOAD_CONST_INLINE_BORROW] = _POP_CALL_TWO,
[_SHUFFLE_2_LOAD_CONST_INLINE_BORROW] = _POP_CALL_ONE_LOAD_CONST_INLINE_BORROW,
};
const bool op_skip[MAX_UOP_ID + 1] = {
[_NOP] = true,
[_CHECK_VALIDITY] = true,
[_CHECK_PERIODIC] = true,
[_SET_IP] = true,
};
const uint16_t op_without_pop[MAX_UOP_ID + 1] = {
[_POP_TOP] = _NOP,
[_POP_TOP_NOP] = _NOP,
[_POP_TOP_INT] = _NOP,
[_POP_TOP_FLOAT] = _NOP,
[_POP_TOP_UNICODE] = _NOP,
[_POP_TOP_LOAD_CONST_INLINE] = _LOAD_CONST_INLINE,
[_POP_TOP_LOAD_CONST_INLINE_BORROW] = _LOAD_CONST_INLINE_BORROW,
[_POP_TWO] = _POP_TOP,
[_POP_TWO_LOAD_CONST_INLINE_BORROW] = _POP_TOP_LOAD_CONST_INLINE_BORROW,
[_POP_CALL_TWO_LOAD_CONST_INLINE_BORROW] = _POP_CALL_ONE_LOAD_CONST_INLINE_BORROW,
[_POP_CALL_ONE_LOAD_CONST_INLINE_BORROW] = _POP_CALL_LOAD_CONST_INLINE_BORROW,
[_POP_CALL_TWO] = _POP_CALL_ONE,
[_POP_CALL_ONE] = _POP_CALL,
};
const uint16_t op_without_pop_null[MAX_UOP_ID + 1] = {
[_POP_CALL] = _POP_TOP,
[_POP_CALL_LOAD_CONST_INLINE_BORROW] = _POP_TOP_LOAD_CONST_INLINE_BORROW,
};

Specifically, these composites chain through _POP_TOP_LOAD_CONST_INLINE_BORROW in the op_without_push / op_without_pop / op_without_pop_null tables:

  • _POP_TWO_LOAD_CONST_INLINE_BORROW
  • _POP_CALL_LOAD_CONST_INLINE_BORROW
  • _POP_CALL_ONE_LOAD_CONST_INLINE_BORROW
  • _POP_CALL_TWO_LOAD_CONST_INLINE_BORROW
  • _SHUFFLE_2_LOAD_CONST_INLINE_BORROW

Additionally, _LOAD_CONST_UNDER_INLINE(_BORROW) references _POP_TOP_LOAD_CONST_INLINE(_BORROW) as a target in op_without_push — those table entries would need updating too.

Once these dependents are decomposed, the definitions can be fully removed.

@Fidget-Spinner
Copy link
Copy Markdown
Member

Feel free to remove the composite uops altogether, including removing them from remove_unneeded_uops!

@Fidget-Spinner
Copy link
Copy Markdown
Member

Ah wait, it seems this is quite hard to remove from the unneeded ops pass without modifying it heavily. So let's skip that for now. Thanks!

Copy link
Copy Markdown
Member

@Fidget-Spinner Fidget-Spinner left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks a lot!

@Fidget-Spinner
Copy link
Copy Markdown
Member

Please fix the merge conflicts from the other PR. Thank you!

@NekoAsakura
Copy link
Copy Markdown
Contributor Author

Done :)

@Fidget-Spinner Fidget-Spinner merged commit d2fa4b2 into python:main Apr 8, 2026
78 checks passed
@NekoAsakura NekoAsakura deleted the gh-148211/decompose-pop-top branch April 8, 2026 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants