Skip to content

ZJIT: Use SP for reloading locals - #16746

Merged
k0kubun merged 2 commits into
ruby:masterfrom
nozomemein:zjit-usesp-reloadlocals
Apr 28, 2026
Merged

ZJIT: Use SP for reloading locals#16746
k0kubun merged 2 commits into
ruby:masterfrom
nozomemein:zjit-usesp-reloadlocals

Conversation

@nozomemein

@nozomemein nozomemein commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

Closes: Shopify#769

Use SP for reloading locals after block-backed send-ish instructions when EP has not escaped.
To make that safe, add a NoEPEscape patch point before the reload and use a post-send snapshot for side exits, so exiting does not re-execute the send in the interpreter.

@nozomemein
nozomemein force-pushed the zjit-usesp-reloadlocals branch from 1def70a to 7df7fb7 Compare April 15, 2026 00:37
@nozomemein

nozomemein commented Apr 15, 2026

Copy link
Copy Markdown
Contributor Author

I found an issue related to this PR tht also reproduces on master.
Filed: Shopify#976

@nozomemein
nozomemein force-pushed the zjit-usesp-reloadlocals branch 3 times, most recently from 0bdeed7 to ee867a4 Compare April 15, 2026 22:00
@nozomemein
nozomemein force-pushed the zjit-usesp-reloadlocals branch from ee867a4 to d689004 Compare April 15, 2026 22:26
@nozomemein
nozomemein marked this pull request as ready for review April 15, 2026 23:05
@matzbot
matzbot requested a review from a team April 15, 2026 23:05
Comment thread zjit/src/hir.rs Outdated
Comment on lines +8093 to +8095
let mut reload_state = state.clone();
reload_state.insn_idx = insn_idx as usize;
reload_state.pc = unsafe { rb_iseq_pc_at_idx(iseq, insn_idx) };

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.

The reload_state construction logic seems to be repeated 4 times. Can we define a function and use it to deduplicate them?

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.

done 👍
d609a48

@nozomemein
nozomemein force-pushed the zjit-usesp-reloadlocals branch from 2fcf8df to d609a48 Compare April 16, 2026 00:23
@nozomemein
nozomemein requested a review from k0kubun April 16, 2026 00:58
@tekknolagi

Copy link
Copy Markdown
Contributor

Hello and thank you for your PR! Many ZJIT members are at RubyKaigi this week and therefore will be slow to respond due to the conference and the travel associated with it. We will take a look soon!

@k0kubun k0kubun left a comment

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.

The HIR optimization seems right to me. Thank you!

@k0kubun
k0kubun merged commit 1c39cc8 into ruby:master Apr 28, 2026
95 checks passed
ima1zumi pushed a commit to ima1zumi/ruby that referenced this pull request May 7, 2026
* ZJIT: Use SP for reloading locals

* ZJIT: Deduplicate post-send NoEPEscape patch point generation
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.

ZJIT: Consider using SP register for reloading locals

3 participants