Skip to content

Commit

Permalink
Consider rb_str_getbyte as leaf sometimes
Browse files Browse the repository at this point in the history
If YJIT knows the parameter to rb_str_getbyte is a fixnum, then I think
we can consider the function to be a leaf
  • Loading branch information
tenderlove committed Feb 14, 2024
1 parent fadb7d4 commit 7943cb2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions yjit/src/codegen.rs
Expand Up @@ -5395,11 +5395,18 @@ fn jit_rb_str_getbyte(
extern "C" {
fn rb_str_getbyte(str: VALUE, index: VALUE) -> VALUE;
}
// Raises when non-integers are passed in
jit_prepare_non_leaf_call(jit, asm);

let index = asm.stack_opnd(0);
let recv = asm.stack_opnd(1);

let arg0_type = asm.ctx.get_opnd_type(index.into());

// rb_str_getbyte should be leaf if the index is a fixnum
if arg0_type != Type::Fixnum {
// Raises when non-integers are passed in
jit_prepare_non_leaf_call(jit, asm);
}

let ret_opnd = asm.ccall(rb_str_getbyte as *const u8, vec![recv, index]);
asm.stack_pop(2); // Keep them on stack during ccall for GC

Expand Down

0 comments on commit 7943cb2

Please sign in to comment.