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-139757: Treat call specially in JIT assembly backend optimizer on x86-64 and AArch64 by Fidget-Spinner · Pull Request #142907 · python/cpython

Conversation

@Fidget-Spinner

@Fidget-Spinner Fidget-Spinner commented Dec 17, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

On x86-64 and AArch64, a call is effectively a jump to a label with some caveats. As such, the assembly flow optimizer must treat it as such, or it risks emitting invalid optimizations.

The bug triggers in the following code:

_JIT_ENTRY:
    call PyStackRef_CLOSE

PyStackRef_CLOSE:
    bar

The assembly optimizer currently doesn't see PyStackRef_CLOSE as being used, and just optimizes the whole thing away.

The fix informs the assembly optimizer we might jump to PyStackRef_CLOSE, thus the label is used and to preserve it.

I verified it fixes the crash on FT builds on my system.

The reason why we didn't see this earlier is that our stencils were at -O3 and that squashed them all into one function. After we switched to -Os, bigger stencils get outlined. It just so happens the biggest stencils are on FT.

  • Issue: JIT assembly optimizer leaves some redundant branches #139757

Sorry, something went wrong.

Uh oh!

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

All reactions
@Fidget-Spinner
Treat call as jump in JIT assembly backend optimizer on x86-64
6e9d577
@Fidget-Spinner
Fidget-Spinner requested review from brandtbucher, diegorusso and savannahostrowski as code owners December 17, 2025 20:29
@bedevere-app bedevere-app Bot mentioned this pull request Dec 17, 2025
JIT assembly optimizer leaves some redundant branches #139757
Closed
@bedevere-app bedevere-app Bot added the awaiting core review label Dec 17, 2025
blurb-it Bot and others added 4 commits December 17, 2025 20:31
@blurb-it
📜🤖 Added by blurb_it.
0abce6d
@Fidget-Spinner
a proper fix by special casing calls
969c8fd
@Fidget-Spinner
Merge branch 'treat_call_as_jump' of github.com:Fidget-Spinner/cpytho…
859b7bc
…n into treat_call_as_jump
@Fidget-Spinner
update comment
ddf85c6
savannahostrowski
savannahostrowski reviewed Dec 17, 2025
View reviewed changes
Comment thread Tools/jit/_optimizers.py Resolved

Uh oh!

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

@Fidget-Spinner Fidget-Spinner changed the title gh-139757: Treat call as jump in JIT assembly backend optimizer on x86-64 gh-139757: Treat call specially in JIT assembly backend optimizer on x86-64 Dec 17, 2025
@Fidget-Spinner Fidget-Spinner changed the title gh-139757: Treat call specially in JIT assembly backend optimizer on x86-64 gh-139757: Treat call specially in JIT assembly backend optimizer on x86-64 and AArch64 Dec 17, 2025
@Fidget-Spinner
address review
bfe5eb9
savannahostrowski
savannahostrowski reviewed Dec 17, 2025
View reviewed changes
Comment thread Tools/jit/_optimizers.py Resolved

Uh oh!

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

Fidget-Spinner and others added 4 commits December 17, 2025 21:20
@Fidget-Spinner @savannahostrowski
Address review
cddf406
Co-authored-by: Savannah Ostrowski <[email protected]>
@Fidget-Spinner
try fix macos
be80179
@Fidget-Spinner
Merge branch 'treat_call_as_jump' of github.com:Fidget-Spinner/cpytho…
8ec5768
…n into treat_call_as_jump
@Fidget-Spinner
trigger macos CI
7fad18f
@Fidget-Spinner
Fidget-Spinner requested review from AA-Turner, ezio-melotti and hugovk as code owners December 17, 2025 21:44
Fidget-Spinner added 2 commits December 17, 2025 21:48
@Fidget-Spinner
fix macos again
f603077
@Fidget-Spinner
revert CI changes
e4d37d0
@Fidget-Spinner
Fidget-Spinner removed request for AA-Turner, ezio-melotti and hugovk December 17, 2025 21:53
savannahostrowski
savannahostrowski approved these changes Dec 17, 2025
View reviewed changes

@savannahostrowski savannahostrowski left a comment

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.

LGTM - thanks for the back and forth on this!

Sorry, something went wrong.

Uh oh!

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

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Dec 17, 2025
@Fidget-Spinner

Fidget-Spinner commented Dec 17, 2025

Copy link
Copy Markdown
Member Author

I'm merging this as it's fixing an actual bug that causes malformed code in the JIT. We can refine it later if we want, but I have gone through a lot of discussion with Savannah about the correctness of this PR, and I feel confident on it.

All reactions

Sorry, something went wrong.

Uh oh!

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

@Fidget-Spinner
Fidget-Spinner merged commit 8b64dd8 into python:main Dec 17, 2025
77 checks passed

Uh oh!

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

@bedevere-app bedevere-app Bot removed the awaiting merge label Dec 17, 2025
@Fidget-Spinner
Fidget-Spinner deleted the treat_call_as_jump branch December 17, 2025 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@savannahostrowski savannahostrowski savannahostrowski approved these changes
@brandtbucher brandtbucher Awaiting requested review from brandtbucher brandtbucher is a code owner
@diegorusso diegorusso Awaiting requested review from diegorusso diegorusso is a code owner

Uh oh!

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

Assignees

No one assigned

Labels

None yet

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

@Fidget-Spinner @savannahostrowski
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.