From 7943cb22f667cc4382e8ea3f7ca674c470f601c6 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 14 Feb 2024 11:49:10 -0800 Subject: [PATCH] Consider rb_str_getbyte as leaf sometimes If YJIT knows the parameter to rb_str_getbyte is a fixnum, then I think we can consider the function to be a leaf --- yjit/src/codegen.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/yjit/src/codegen.rs b/yjit/src/codegen.rs index afdf3a8712..e080905ea0 100644 --- a/yjit/src/codegen.rs +++ b/yjit/src/codegen.rs @@ -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