Skip to content

Conversation

@Fidget-Spinner
Copy link
Member

@Fidget-Spinner Fidget-Spinner commented Dec 17, 2025

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.

@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
Copy link
Member

@savannahostrowski savannahostrowski left a 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!

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

@Fidget-Spinner Fidget-Spinner merged commit 8b64dd8 into python:main Dec 17, 2025
77 checks passed
@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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants