Skip to content

ZJIT: Avoid splitting add_into/sub_into for x86_64 #14177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 12, 2025

Conversation

k0kubun
Copy link
Member

@k0kubun k0kubun commented Aug 12, 2025

This PR addresses #14154 (comment).

On x86_64, we were splitting asm.add_into to two instructions. By fixing it, this PR also updates asm.sub_into to use an implementation that looks similar to asm.add_into.

Before

add_into in concatstrings looked like this:

  # restore C stack pointer
  0x652fd19ee1b8: mov rdi, rsp
  0x652fd19ee1bb: add rdi, 0x20

After

It's now:

  # restore C stack pointer
  0x5629f326e1b8: add rsp, 0x20

The instructions generated by sub_into in concatstrings stayed the same because merging sub + mov works fine.

@k0kubun k0kubun changed the title ZJIT: Avoid splitting add_into/sub_into ZJIT: Avoid splitting add_into/sub_into for x86_64 Aug 12, 2025
@k0kubun k0kubun marked this pull request as ready for review August 12, 2025 00:13
@matzbot matzbot requested a review from a team August 12, 2025 00:14
@@ -1889,9 +1889,8 @@ impl Assembler {
out
}

pub fn add_into(&mut self, left: Opnd, right: Opnd) -> Opnd {
pub fn add_into(&mut self, left: Opnd, right: Opnd) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't love that this breaks SSA if we use a vreg operand as an argument. Can we require it only take memory/phyreg? (here and below)

Copy link
Member Author

Choose a reason for hiding this comment

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

I changed them to only take Opnd::Reg for now a43e62e since it's the only expected usage of them.

Btw if you want LIR to be SSA, you need to fix cpop_into, lea_into, load_into, mov, and store as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for the change. Didn't know that. I thought LIR was SSA...

Copy link
Member Author

Choose a reason for hiding this comment

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

Almost. You can make it happen with just ^. We just haven't come up with anything that needs the guarantee yet.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sketching in #14188

Copy link

Tests Failed

✖️no tests failed ✔️62266 tests passed(1 flake)

@k0kubun k0kubun merged commit e26ab5d into ruby:master Aug 12, 2025
83 of 86 checks passed
@k0kubun k0kubun deleted the yjit-sub-into branch August 12, 2025 16:54
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.

4 participants