Skip to content

Commit

Permalink
Merge pull request ruby#113 from Shopify/yjit-heap-check
Browse files Browse the repository at this point in the history
YJIT: Switch to 2-comparison heap object check
  • Loading branch information
maximecb committed Apr 19, 2021
2 parents c8740b0 + 14e2f39 commit 2e326c9
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions yjit_codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,21 +625,15 @@ gen_setlocal_wc0(jitstate_t* jit, ctx_t* ctx)
static void
guard_self_is_heap(codeblock_t *cb, x86opnd_t self_opnd, uint8_t *side_exit, ctx_t *ctx)
{

// `self` is constant throughout the entire region, so we only need to do this check once.
if (!ctx->self_type.is_heap) {
// FIXME: use two-comparison test
ADD_COMMENT(cb, "guard self is heap");
RUBY_ASSERT(Qfalse < Qnil);
test(cb, self_opnd, imm_opnd(RUBY_IMMEDIATE_MASK));
jnz_ptr(cb, side_exit);
cmp(cb, self_opnd, imm_opnd(Qfalse));
je_ptr(cb, side_exit);
cmp(cb, self_opnd, imm_opnd(Qnil));
je_ptr(cb, side_exit);

// maybe we can do
// RUBY_ASSERT(Qfalse < Qnil);
// cmp(cb, self_opnd, imm_opnd(Qnil));
// jbe(cb, side_exit);
jbe_ptr(cb, side_exit);

ctx->self_type.is_heap = 1;
}
Expand Down Expand Up @@ -1432,12 +1426,11 @@ jit_guard_known_klass(jitstate_t *jit, ctx_t* ctx, VALUE known_klass, insn_opnd_
{
// FIXME: use two comparisons instead of 3 here
ADD_COMMENT(cb, "guard not immediate");
RUBY_ASSERT(Qfalse < Qnil);
test(cb, REG0, imm_opnd(RUBY_IMMEDIATE_MASK));
jnz_ptr(cb, side_exit);
cmp(cb, REG0, imm_opnd(Qfalse));
je_ptr(cb, side_exit);
cmp(cb, REG0, imm_opnd(Qnil));
je_ptr(cb, side_exit);
jbe_ptr(cb, side_exit);

ctx_set_opnd_type(ctx, insn_opnd, TYPE_HEAP);
}
Expand Down

0 comments on commit 2e326c9

Please sign in to comment.