Skip to content
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

YJIT: Fallback Integer#<< if a shift amount varies #9426

Merged
merged 2 commits into from Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion yjit.rb
Expand Up @@ -288,7 +288,7 @@ def _print_stats_reasons(stats, out) # :nodoc:
].each do |insn|
print_counters(stats, out: out, prefix: "#{insn}_", prompt: "#{insn} exit reasons:", optional: true)
end
print_counters(stats, out: out, prefix: 'lshift_', prompt: 'left shift (ltlt) exit reasons: ')
print_counters(stats, out: out, prefix: 'lshift_', prompt: 'left shift (opt_ltlt) exit reasons: ')
print_counters(stats, out: out, prefix: 'invalidate_', prompt: 'invalidation reasons: ')
end

Expand Down
17 changes: 14 additions & 3 deletions yjit/src/codegen.rs
Expand Up @@ -4637,17 +4637,28 @@ fn jit_rb_int_lshift(

// Untag the fixnum shift amount
let shift_amt = comptime_shift.as_isize() >> 1;

if shift_amt > 63 || shift_amt < 0 {
return false;
}

// Fallback to a C call if the shift amount varies
if asm.ctx.get_chain_depth() > 1 {
return false;
}

let rhs = asm.stack_pop(1);
let lhs = asm.stack_pop(1);

// Guard on the shift value we speculated on
// Guard on the shift amount we speculated on
asm.cmp(rhs, comptime_shift.into());
asm.jne(Target::side_exit(Counter::lshift_amt_changed));
jit_chain_guard(
JCC_JNE,
jit,
asm,
ocb,
2, // defer_compilation increments chain_depth
Counter::lshift_amount_changed,
);

let in_val = asm.sub(lhs, 1.into());
let shift_opnd = Opnd::UImm(shift_amt as u64);
Expand Down
2 changes: 1 addition & 1 deletion yjit/src/stats.rs
Expand Up @@ -447,7 +447,7 @@ make_counters! {
opt_mod_zero,
opt_div_zero,

lshift_amt_changed,
lshift_amount_changed,
lshift_overflow,

opt_aref_argc_not_one,
Expand Down