GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GH-135379: Support limited scalar replacement for replicated uops in the JIT code generator. by markshannon · Pull Request #135563 · python/cpython

Conversation

@markshannon

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

Uh oh!

There was an error while loading. Please reload this page.

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.

  • Issue: Top-of-stack caching in the JIT #135379

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jugurtha114 reacted with thumbs up emoji jugurtha114 reacted with heart emoji
All reactions
  • 👍 1 reaction
  • ❤️ 1 reaction
@markshannon
Support limited scalar replacement for replicated uops in the code ge…
18c78b1
…nerator. Use it to support efficient specializations of COPY and SWAP in the JIT.
@bedevere-app bedevere-app Bot added the awaiting core review label Jun 16, 2025
@markshannon markshannon added skip news and removed awaiting core review labels Jun 16, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Jun 16, 2025
Top-of-stack caching in the JIT #135379
Closed
@Fidget-Spinner

Fidget-Spinner commented Jun 16, 2025

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Fidget-Spinner

Fidget-Spinner commented Jun 16, 2025

Copy link
Copy Markdown
Member

scalarize works too.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Fidget-Spinner
Fidget-Spinner reviewed Jun 16, 2025
View reviewed changes
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

@Fidget-Spinner Fidget-Spinner Jun 16, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@markshannon markshannon Jun 16, 2025

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@markshannon

markshannon commented Jun 16, 2025

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.

Fidget-Spinner reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Fidget-Spinner

Fidget-Spinner commented Jun 16, 2025

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".

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@markshannon 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
@markshannon
Update comment
ce421ad
Fidget-Spinner
Fidget-Spinner reviewed Jun 16, 2025
View reviewed changes
Comment thread Tools/cases_generator/analyzer.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@markshannon @Fidget-Spinner
Update Tools/cases_generator/analyzer.py
72aa4a6
Co-authored-by: Ken Jin <[email protected]>
Fidget-Spinner
Fidget-Spinner approved these changes Jun 16, 2025
View reviewed changes
@bedevere-app bedevere-app Bot added the awaiting merge label Jun 16, 2025
Fidget-Spinner
Fidget-Spinner reviewed Jun 16, 2025
View reviewed changes
Comment thread Tools/cases_generator/analyzer.py
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

@Fidget-Spinner Fidget-Spinner Jun 16, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@markshannon
markshannon merged commit 8dd8b5c into python:main Jun 17, 2025
@bedevere-app bedevere-app Bot removed the awaiting merge label Jun 17, 2025
lkollar pushed a commit to lkollar/cpython that referenced this pull request Jun 19, 2025
@markshannon @lkollar
pythonGH-135379: Support limited scalar replacement for replicated uo…
a7fe5be
…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
@markshannon @Pranjal095
pythonGH-135379: Support limited scalar replacement for replicated uo…
fee436c
…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
@markshannon @taegyunkim
pythonGH-135379: Support limited scalar replacement for replicated uo…
1134fb2
…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
@markshannon @Agent-Hellboy
pythonGH-135379: Support limited scalar replacement for replicated uo…
b00b926
…ps in the JIT code generator. (pythonGH-135563)

* Use it to support efficient specializations of COPY and SWAP in the JIT.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@Fidget-Spinner Fidget-Spinner Fidget-Spinner approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@markshannon @Fidget-Spinner
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.