FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

GH-135379: Support limited scalar replacement for replicated uops in the JIT code generator. by markshannon · Pull Request #135563 · python/cpython · GitHub

Repository navigation

GH-135379: Support limited scalar replacement for replicated uops in the JIT code generator. - #135563

Merged
markshannon merged 3 commits into
python:mainfrom
faster-cpython:tier-swap-copy-specializations
Jun 17, 2025
Merged

markshannon merged 3 commits into
python:mainfrom
faster-cpython:tier-swap-copy-specializations

Conversation

markshannon commented Jun 16, 2025 •
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Member

This PR does three things:

  • Performs limited replacement of array stack items with scalars for uops.
  • Modify replicate to support ranges starting from values other than zero
  • Replicates COPY and SWAP to take advantage of that.

With TOS caching this should allow COPY and SWAP to be implemented as register-to-register moves.

…nerator. Use it to support efficient specializations of COPY and SWAP in the JIT.

Copy link
Copy Markdown
Member

Can you call the PR something else instead of "scalar replacement"? Scalar replacement is the other term for escape analysis in the JVM https://devblogs.microsoft.com/java/improving-openjdk-scalar-replacement-part-1-3/

I know CS has a lot of overlapping terms, but I think it would be clearer to call it "change replicates to ranges" or something.

Copy link
Copy Markdown
Member

scalarize works too.

Comment thread Tools/cases_generator/analyzer.py Outdated
] + items[index+1:]

def scalarize_stack(stack: StackEffect, oparg: int) -> StackEffect:
# Only scalarize if no more than one input or output is array

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This comment doesn't seem to belong to this code segment?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Yes, I refactored the code but didn't move the comment.

Copy link
Copy Markdown
Member Author

This is scalar replacement. We are replacing a composite object (an array in this case) with a set of scalar values.

In the JVM, that means breaking down an object into its parts. The JVM version is a lot more complex and powerful, but it is doing the same thing, and the motivation is the same: register allocation.

Copy link
Copy Markdown
Member

This is scalar replacement. We are replacing a composite object (an array in this case) with a set of scalar values.

In the JVM, that means breaking down an object into its parts. The JVM version is a lot more complex and powerful, but it is doing the same thing, and the motivation is the same: register allocation.

It's somewhat confusing because it's scalar replacement in the JIT, but not in the default interpreter. Though you subtly implied it with the "uops".

markshannon changed the title GH-135379: Support limited scalar replacement for replicated uops in the code generator. GH-135379: Support limited scalar replacement for replicated uops in the JIT code generator. Jun 16, 2025
Comment thread Tools/cases_generator/analyzer.py Outdated
Co-authored-by: Ken Jin <kenjin4096@gmail.com>
Comment on lines +873 to +880
index = -1
for i, item in enumerate(items):
if "oparg" in item.size:
if index >= 0:
return items
index = i
if index < 0:
return items

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This entire part is somewhat confusing, but I'll let it slide since there's a comment up top :).

markshannon merged commit 8dd8b5c into python:main Jun 17, 2025
lkollar pushed a commit to lkollar/cpython that referenced this pull request Jun 19, 2025
…ps in the JIT code generator. (pythonGH-135563)

* Use it to support efficient specializations of COPY and SWAP in the JIT.
Pranjal095 pushed a commit to Pranjal095/cpython that referenced this pull request Jul 12, 2025
…ps in the JIT code generator. (pythonGH-135563)

* Use it to support efficient specializations of COPY and SWAP in the JIT.
taegyunkim pushed a commit to taegyunkim/cpython that referenced this pull request Aug 4, 2025
…ps in the JIT code generator. (pythonGH-135563)

* Use it to support efficient specializations of COPY and SWAP in the JIT.
Agent-Hellboy pushed a commit to Agent-Hellboy/cpython that referenced this pull request Aug 19, 2025
…ps in the JIT code generator. (pythonGH-135563)

* Use it to support efficient specializations of COPY and SWAP in the JIT.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL