Skip to content

ZJIT: Split shift with immediate operand #13914

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 1 commit into from
Jul 16, 2025

Conversation

tekknolagi
Copy link
Contributor

@tekknolagi tekknolagi commented Jul 16, 2025

@matzbot matzbot requested a review from a team July 16, 2025 18:50
@tekknolagi tekknolagi force-pushed the mb-shift-imm branch 2 times, most recently from 6a97041 to e365f99 Compare July 16, 2025 18:54
@tekknolagi tekknolagi enabled auto-merge (squash) July 16, 2025 18:54
def test(n) = C * n
test(4)
test(4)
test(4)
Copy link
Member

Choose a reason for hiding this comment

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

How does the script generate the URShift instruction and is it possible to see it in dumped HIR output?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it's only in LIR; it's a shift for untagging

Optimized HIR:
fn test@testshift.rb:4:
bb0(v0:BasicObject, v1:BasicObject):
  PatchPoint SingleRactorMode
  PatchPoint StableConstantNames(0x600001b86020, RP2A03_CC)
  v10:Fixnum[12] = Const Value(12)
  PatchPoint BOPRedefined(INTEGER_REDEFINED_OP_FLAG, BOP_MULT)
  v13:Fixnum = GuardType v1, Fixnum
  v14:Fixnum = FixnumMult v10, v13
  Return v14

LIR:
fn test:
Assembler
    000 Label() target=Label(Label(0)) -> None
    001 FrameSetup() -> None
    002 LiveReg(A64Reg { num_bits: 64, reg_no: 0 }) -> VReg(0)
    003 LiveReg(A64Reg { num_bits: 64, reg_no: 1 }) -> VReg(1)
    004 PatchPoint(VReg(1)) target=SideExit { pc: 0x600000cbae00, stack: [], locals: [VReg(1)], c_stack_bytes: 0, reason: PatchPoint(SingleRactorMode), label: Some(Label(1)) } -> None
    005 PosMarker() -> None
    006 PatchPoint(VReg(1)) target=SideExit { pc: 0x600000cbae00, stack: [], locals: [VReg(1)], c_stack_bytes: 0, reason: PatchPoint(StableConstantNames { idlist: 0x600001b86020 }), label: Some(Label(2)) } -> None
    007 PosMarker() -> None
    008 PatchPoint(Value(VALUE(25)), VReg(1), VReg(1)) target=SideExit { pc: 0x600000cbae20, stack: [Value(VALUE(25)), VReg(1)], locals: [VReg(1)], c_stack_bytes: 0, reason: PatchPoint(BOPRedefined { klass: 1, bop: 2 }), label: Some(Label(3)) } -> None
    009 PosMarker() -> None
    010 Test(VReg(1), 1_u64) -> None
    011 Jz(Value(VALUE(25)), VReg(1), VReg(1)) target=SideExit { pc: 0x600000cbae20, stack: [Value(VALUE(25)), VReg(1)], locals: [VReg(1)], c_stack_bytes: 0, reason: GuardType(Type { bits: 4194304, spec: Any }), label: None } -> None
    012 RShift(Value(VALUE(25)), 1_u64) -> VReg(2)
    013 Sub(VReg(1), 1_u64) -> VReg(3)
    014 Mul(VReg(2), VReg(3)) -> VReg(4)
    015 JoMul(Value(VALUE(25)), VReg(1), VReg(1)) target=SideExit { pc: 0x600000cbae20, stack: [Value(VALUE(25)), VReg(1)], locals: [VReg(1)], c_stack_bytes: 0, reason: FixnumMultOverflow, label: None } -> None
    016 Add(VReg(4), 1_u64) -> VReg(5)
    017 Add(A64Reg { num_bits: 64, reg_no: 19 }, 38_u64) -> VReg(6)
    018 Mov(A64Reg { num_bits: 64, reg_no: 19 }, VReg(6)) -> None
    019 Mov(Mem64[Reg(20) + 16], A64Reg { num_bits: 64, reg_no: 19 }) -> None
    020 FrameTeardown() -> None
    021 CRet(VReg(5)) -> None
    022 PadPatchPoint() -> None

Copy link
Member

Choose a reason for hiding this comment

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

Ah sorry I'm blind on the file name 🤦

@XrXr
Copy link
Member

XrXr commented Jul 16, 2025

 TestZJIT#test_fixnum_mul [/home/runner/work/ruby/ruby/src/test/ruby/test_zjit.rb:386]:

  thread '<unnamed>' panicked at zjit/src/asm/x86_64/mod.rs:1252:5:
  assertion failed: matches!(opnd0, X86Opnd::Reg(_) | X86Opnd::Mem(_))

Will need a fix on x86 as well 😢

@tekknolagi tekknolagi merged commit 900eb04 into ruby:master Jul 16, 2025
84 checks passed
@tekknolagi tekknolagi deleted the mb-shift-imm branch July 16, 2025 19:50
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: Running optcarrot (on ARM64) causes assembler panic
3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy