Repository navigation
Closed
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-JITtype-featureA feature request or enhancementA feature request or enhancementtype-refactorCode refactoring (with no changes in behavior)Code refactoring (with no changes in behavior)
Description
Feature or enhancement
Proposal:
The JIT optimizer initially only allowed a inplace op rewrites. This led to us contorting the JIT uops to fit that.
Now that the JIT optimizer allows more than one op to be written at once, we should clean up and de-duplicate all the composite uops.
E.g.
REPLACE_OP(_POP_TOP_LOAD_CONST_INLINE_BORROW, ..)
should become
ADD_OP(_POP_TOP, ...)
ADD_OP(_LOAD_CONST_INLINE_BORROW, ...)
and _POP_TOP_LOAD_CONST_INLINE_BORROW should then be completely removed from the JIT uops and bytecodes.c. This will allow us to de-duplicate and refactor the code greatly, while making the existing optimizations also more effective as we don't have to do as much repeated work.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Linked PRs
- gh-148211: decompose
_POP_TOP_LOAD_CONST_INLINE(_BORROW)in JIT #148230 - gh-148211: refactor bool to explicit uops in JIT #148258
- gh-148211: decompose
_INSERT_1_LOAD_CONST_INLINE(_BORROW)in JIT #148283 - gh-148211: decompose
[_POP_CALL_X/_SHUFFLE_2]_LOAD_CONST_INLINE_BORROWin JIT #148313 - gh-148211: decompose
[_POP_TWO/_INSERT_2]_LOAD_CONST_INLINE_BORROWin JIT #148357 - gh-148211: decompose
_POP_TWO/_POP_CALL(_ONE/_TWO)in JIT #148377 - gh-148211: decompose
_SHUFFLE_3_LOAD_CONST_INLINE_BORROWin JIT #148816
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-JITtype-featureA feature request or enhancementA feature request or enhancementtype-refactorCode refactoring (with no changes in behavior)Code refactoring (with no changes in behavior)
Activity
Fidget-Spinner commentedon Apr 7, 2026
@NekoAsakura would you like to work on this?
NekoAsakura commentedon Apr 7, 2026
Of course! Pls assign it to me <3
Fidget-Spinner commentedon Apr 7, 2026
@NekoAsakura I don't think we assign things here to non-coreteam, but feel free to comment which ops you are taking op (this is a big issue), and I'll make sure to deconflict. Thanks a lot!
NekoAsakura commentedon Apr 7, 2026
Uh, I just meant an oral assignment, similar to what you did in #145866 (comment), but no worries!
I've had a look through composite uops. These are some straightforward POP + LOAD_CONST fusions that can be cleanly decomposed:
_POP_TOP_LOAD_CONST_INLINE_POP_TOP_LOAD_CONST_INLINE_BORROW_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_BORROWHappy to take the first three in one PR and leave the rest for anyone else who fancies having a go. Sound alright?
Fidget-Spinner commentedon Apr 7, 2026
Sounds good, thanks for taking these up!
pythongh-148211: decompose `_POP_TOP_LOAD_CONST_INLINE(_BORROW)` in JIT
NekoAsakura commentedon Apr 7, 2026
A bit more:
_INSERT_1_LOAD_CONST_INLINE_INSERT_1_LOAD_CONST_INLINE_BORROW_LOAD_CONST_UNDER_INLINE_LOAD_CONST_UNDER_INLINE_BORROWMerge branch 'main' into pythongh-148211/decompose-pop-top
Merge branch 'main' into pythongh-148211/decompose-pop-top
pythongh-148211: decompose `_POP_TOP_LOAD_CONST_INLINE(_BORROW)` in JIT
gh-148211: decompose `_POP_TOP_LOAD_CONST_INLINE(_BORROW)` in JIT (GH…
markshannon commentedon Apr 8, 2026
I've noticed that some of the optimizer functions are gaining boolean parameters for whether to pop, or insert. To read the code requires constant reference to the function being called.
For future PRs consider using prefix and/or postfix instructions as arguments, to improve clarity.
optimize_thing(POP_TOP, value, NOP)is easier to follow thanoptimize_thing(value, true, false)20 remaining items
gh-148211: decompose `[_POP_TWO/_INSERT_2]_LOAD_CONST_INLINE_BORROW` …
pythongh-148211: decompose / in JIT
pythongh-148211: decompose `_POP_TWO/_POP_CALL(_ONE/_TWO)` in JIT
gh-148211: decompose `_POP_TWO/_POP_CALL(_ONE/_TWO)` in JIT (GH-148377)
Fidget-Spinner commentedon Apr 11, 2026
Thanks to a lot of effort from @NekoAsakura , this is done. Thanks a lot for cleaning up the JIT!
pythongh-148211: decompose `_SHUFFLE_3_LOAD_CONST_INLINE_BORROW` in JIT
Merge branch 'main' into pythongh-148211/decompose-shuffle-3
pythongh-148211: decompose `_POP_TOP_LOAD_CONST_INLINE(_BORROW)` in J…
pythongh-148211: refactor bool to explicit uops in JIT (pythonGH-148258)
pythongh-148211: decompose `_INSERT_1_LOAD_CONST_INLINE(_BORROW)` in …
pythongh-148211: decompose `[_POP_CALL_X/_SHUFFLE_2]_LOAD_CONST_INLIN…
pythongh-148211: decompose `[_POP_TWO/_INSERT_2]_LOAD_CONST_INLINE_BO…
pythongh-148211: decompose `_POP_TWO/_POP_CALL(_ONE/_TWO)` in JIT (py…
gh-148211: decompose `_SHUFFLE_3_LOAD_CONST_INLINE_BORROW` in JIT (GH…