Skip to content

Commit ed691bb

Browse files
authored
Merge pull request ruby#186 from jhawthorn/check_type_side_exit
Avoid immediate side exits in checktype
2 parents 0074c0a + bbf8861 commit ed691bb

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

test/ruby/test_yjit.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,16 @@ def make_str(foo, bar)
152152
RUBY
153153
end
154154

155+
def test_string_interpolation_cast
156+
assert_compiles(<<~'RUBY', insns: %i[checktype concatstrings tostring], result: "123")
157+
def make_str(foo, bar)
158+
"#{foo}#{bar}"
159+
end
160+
161+
make_str(1, 23)
162+
RUBY
163+
end
164+
155165
def test_fib_recursion
156166
assert_compiles(<<~'RUBY', insns: %i[opt_le opt_minus opt_plus opt_send_without_block], result: 34)
157167
def fib(n)

yjit_codegen.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,9 +1642,6 @@ gen_defined(jitstate_t* jit, ctx_t* ctx)
16421642
static codegen_status_t
16431643
gen_checktype(jitstate_t* jit, ctx_t* ctx)
16441644
{
1645-
// TODO: could we specialize on the type we detect
1646-
uint8_t* side_exit = yjit_side_exit(jit, ctx);
1647-
16481645
enum ruby_value_type type_val = (enum ruby_value_type)jit_get_arg(jit, 0);
16491646
// Only three types are emitted by compile.c
16501647
if (type_val == T_STRING || type_val == T_ARRAY || type_val == T_HASH) {
@@ -1669,28 +1666,31 @@ gen_checktype(jitstate_t* jit, ctx_t* ctx)
16691666
}
16701667

16711668
mov(cb, REG0, val);
1669+
mov(cb, REG1, imm_opnd(Qfalse));
1670+
1671+
uint32_t ret = cb_new_label(cb, "ret");
16721672

16731673
if (!val_type.is_heap) {
16741674
// if (SPECIAL_CONST_P(val)) {
1675-
// Bail if receiver is not a heap object
1675+
// Return Qfalse via REG1 if not on heap
16761676
test(cb, REG0, imm_opnd(RUBY_IMMEDIATE_MASK));
1677-
jnz_ptr(cb, side_exit);
1678-
cmp(cb, REG0, imm_opnd(Qfalse));
1679-
je_ptr(cb, side_exit);
1677+
jnz_label(cb, ret);
16801678
cmp(cb, REG0, imm_opnd(Qnil));
1681-
je_ptr(cb, side_exit);
1679+
jbe_label(cb, ret);
16821680
}
16831681

16841682
// Check type on object
16851683
mov(cb, REG0, mem_opnd(64, REG0, offsetof(struct RBasic, flags)));
16861684
and(cb, REG0, imm_opnd(RUBY_T_MASK));
16871685
cmp(cb, REG0, imm_opnd(type_val));
16881686
mov(cb, REG0, imm_opnd(Qtrue));
1689-
mov(cb, REG1, imm_opnd(Qfalse));
1690-
cmovne(cb, REG0, REG1);
1687+
// REG1 contains Qfalse from above
1688+
cmove(cb, REG1, REG0);
16911689

1690+
cb_write_label(cb, ret);
16921691
stack_ret = ctx_stack_push(ctx, TYPE_IMM);
1693-
mov(cb, stack_ret, REG0);
1692+
mov(cb, stack_ret, REG1);
1693+
cb_link_labels(cb);
16941694

16951695
return YJIT_KEEP_COMPILING;
16961696
} else {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy