Skip to content

gh-148211: decompose [_POP_TWO/_INSERT_2]_LOAD_CONST_INLINE_BORROW in JIT#148357

Merged
Fidget-Spinner merged 3 commits intopython:mainfrom
NekoAsakura:gh-148211/decompose-pop-two-insert-2
Apr 11, 2026
Merged

gh-148211: decompose [_POP_TWO/_INSERT_2]_LOAD_CONST_INLINE_BORROW in JIT#148357
Fidget-Spinner merged 3 commits intopython:mainfrom
NekoAsakura:gh-148211/decompose-pop-two-insert-2

Conversation

@NekoAsakura
Copy link
Copy Markdown
Contributor

@NekoAsakura NekoAsakura commented Apr 10, 2026

@NekoAsakura
Copy link
Copy Markdown
Contributor Author

Conflicts already 😲 JIT is moving so fast.
Next PR would be: _POP_CALL(_ONE/_TWO)

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.

Awesome, another nice simplification. Thanks!

@Fidget-Spinner
Copy link
Copy Markdown
Member

Conflicts already 😲 JIT is moving so fast. Next PR would be: _POP_CALL(_ONE/_TWO)

Yeah there're like 5 active contributors sending stuff to the JIT almost daily. It's a happy problem :).

@Fidget-Spinner
Copy link
Copy Markdown
Member

@NekoAsakura I would like to add you to the contributors in the What's New page. Would you be alright with that and do you mind if I use your Neko Asakura handle?

@NekoAsakura
Copy link
Copy Markdown
Contributor Author

@NekoAsakura I would like to add you to the contributors in the What's New page. Would you be alright with that and do you mind if I use your Neko Asakura handle?

That'd be lovely, thanks! Would it be alright to use a different name though?

@Fidget-Spinner
Copy link
Copy Markdown
Member

That'd be lovely, thanks! Would it be alright to use a different name though?

Yeah of course.

@Fidget-Spinner
Copy link
Copy Markdown
Member

I'll open the PR to add new JIT contributors. Give me a moment. Will tag you in it.

Comment on lines +260 to +261
("_SWAP", "3, 0"),
("_SWAP", "2, 0")],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems a little inefficient, but I think it should be fine as it's just a register to register move with stack caching in the JIT.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Are there any better practices for this?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

don't think so: no matter what you do, you probably have to shuffle the register anyways. We can remove some movs, but I doubt that will speed up things by that much on modern CPUs considering register renaming is a thing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sound about right.

@Fidget-Spinner
Copy link
Copy Markdown
Member

I verified that for the following:

def constant():
    for _ in range(4096):
        a = 1
        b = 2
        c = a + b

constant()

We emit the following:

  25 OPTIMIZED: _LOAD_CONST_INLINE_BORROW_r23 (0, target=21, operand0=0x5fdb9ad03c88, operand1=0)
  26 OPTIMIZED: _SWAP_3_r33 (3, target=21, operand0=0, operand1=0)
  27 OPTIMIZED: _SWAP_2_r33 (2, target=21, operand0=0, operand1=0)

Which means everything is in registers. So that's great.

@NekoAsakura
Copy link
Copy Markdown
Contributor Author

Next PR would be: _POP_CALL(_ONE/_TWO)

Would you like me to decompose _POP_TWO as well? I see op_without_pop already peels it during refcount elimination, so we'd just be making that explicit.

@Fidget-Spinner
Copy link
Copy Markdown
Member

Next PR would be: _POP_CALL(_ONE/_TWO)

Would you like me to decompose _POP_TWO as well? I see op_without_pop already peels it during refcount elimination, so we'd just be making that explicit.

Yes please, the op elimination pass should be as simple as possible. We want this so any optimizations we do in the future are easier and more effective.

@Fidget-Spinner Fidget-Spinner merged commit 72006a7 into python:main Apr 11, 2026
83 checks passed
@NekoAsakura NekoAsakura deleted the gh-148211/decompose-pop-two-insert-2 branch April 11, 2026 10:28
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