Skip to content

Commit acd41a3

Browse files
maximecbXrXr
authored andcommitted
Switch to 2-comparison heap object check
1 parent da73dc5 commit acd41a3

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

yjit_codegen.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -626,21 +626,15 @@ gen_setlocal_wc0(jitstate_t* jit, ctx_t* ctx)
626626
static void
627627
guard_self_is_heap(codeblock_t *cb, x86opnd_t self_opnd, uint8_t *side_exit, ctx_t *ctx)
628628
{
629+
629630
// `self` is constant throughout the entire region, so we only need to do this check once.
630631
if (!ctx->self_type.is_heap) {
631-
// FIXME: use two-comparison test
632632
ADD_COMMENT(cb, "guard self is heap");
633+
RUBY_ASSERT(Qfalse < Qnil);
633634
test(cb, self_opnd, imm_opnd(RUBY_IMMEDIATE_MASK));
634635
jnz_ptr(cb, side_exit);
635-
cmp(cb, self_opnd, imm_opnd(Qfalse));
636-
je_ptr(cb, side_exit);
637636
cmp(cb, self_opnd, imm_opnd(Qnil));
638-
je_ptr(cb, side_exit);
639-
640-
// maybe we can do
641-
// RUBY_ASSERT(Qfalse < Qnil);
642-
// cmp(cb, self_opnd, imm_opnd(Qnil));
643-
// jbe(cb, side_exit);
637+
jbe_ptr(cb, side_exit);
644638

645639
ctx->self_type.is_heap = 1;
646640
}
@@ -1433,12 +1427,11 @@ jit_guard_known_klass(jitstate_t *jit, ctx_t* ctx, VALUE known_klass, insn_opnd_
14331427
{
14341428
// FIXME: use two comparisons instead of 3 here
14351429
ADD_COMMENT(cb, "guard not immediate");
1430+
RUBY_ASSERT(Qfalse < Qnil);
14361431
test(cb, REG0, imm_opnd(RUBY_IMMEDIATE_MASK));
14371432
jnz_ptr(cb, side_exit);
1438-
cmp(cb, REG0, imm_opnd(Qfalse));
1439-
je_ptr(cb, side_exit);
14401433
cmp(cb, REG0, imm_opnd(Qnil));
1441-
je_ptr(cb, side_exit);
1434+
jbe_ptr(cb, side_exit);
14421435

14431436
ctx_set_opnd_type(ctx, insn_opnd, TYPE_HEAP);
14441437
}

0 commit comments

Comments
 (0)