Skip to content

Commit

Permalink
YJIT: Try harder to get type info for String#[]
Browse files Browse the repository at this point in the history
In the large generated code of the mail gem the context doesn't have
the type info.  In that case if we peek at the stack and add a guard
we can still apply the specialization
and it speeds up the mail benchmark by 5%.

Co-authored-by: Maxime Chevalier-Boisvert <[email protected]>
Co-authored-by: Takashi Kokubun (k0kubun) <[email protected]>
  • Loading branch information
3 people committed Nov 12, 2024
1 parent 0898166 commit 15096d4
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion yjit/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5815,7 +5815,24 @@ fn jit_rb_str_aref_m(
Type::Fixnum => {},
// Besides Fixnum this could also be a Range or a RegExp which are handled by separate c funcs.
// Other types will raise.
_ => { return false },
_ => {
// If the context doesn't have the type info we try a little harder.
let comptime_arg = jit.peek_at_stack(&asm.ctx, 0);
let arg0 = asm.stack_opnd(0);
if comptime_arg.fixnum_p() {
asm.test(arg0, Opnd::UImm(RUBY_FIXNUM_FLAG as u64));

jit_chain_guard(
JCC_JZ,
jit,
asm,
SEND_MAX_DEPTH,
Counter::guard_send_not_fixnums,
);
} else {
return false
}
},
}
} else {
return false
Expand Down

0 comments on commit 15096d4

Please sign in to comment.