Skip to content

Commit

Permalink
Propagate Type::Nil when known
Browse files Browse the repository at this point in the history
  • Loading branch information
maximecb committed Aug 2, 2023
1 parent 10f619d commit 90e6b01
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions yjit/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1470,7 +1470,7 @@ fn gen_expandarray(
ocb: &mut OutlinedCb,
) -> Option<CodegenStatus> {
// Both arguments are rb_num_t which is unsigned
let num = jit.get_arg(0).as_usize();
let num = jit.get_arg(0).as_u32();
let flag = jit.get_arg(1).as_usize();

// If this instruction has the splat flag, then bail out.
Expand Down Expand Up @@ -1535,7 +1535,34 @@ fn gen_expandarray(
let array_reg = asm.load(array_opnd);
let array_len_opnd = get_array_len(asm, array_reg);

/*
// FIXME: JCC_JB not implemented
// Guard on the comptime/expected array length
if comptime_len >= num {
asm.comment(&format!("guard array length >= {}", num));
asm.cmp(array_len_opnd, num.into());
jit_chain_guard(
JCC_JB,
jit,
asm,
ocb,
OPT_AREF_MAX_CHAIN_DEPTH,
Counter::expandarray_chain_max_depth,
);
} else {
asm.comment(&format!("guard array length == {}", comptime_len));
asm.cmp(array_len_opnd, comptime_len.into());
jit_chain_guard(
JCC_JNE,
jit,
asm,
ocb,
OPT_AREF_MAX_CHAIN_DEPTH,
Counter::expandarray_chain_max_depth,
);
}
*/

asm.comment(&format!("guard array length == {}", comptime_len));
asm.cmp(array_len_opnd, comptime_len.into());
jit_chain_guard(
Expand Down Expand Up @@ -1575,12 +1602,12 @@ fn gen_expandarray(

// Loop backward through the array and push each element onto the stack.
for i in (0..num).rev() {
let top = asm.stack_push(Type::Unknown);
let offset = i32::try_from(i * SIZEOF_VALUE).unwrap();
let top = asm.stack_push(if i < comptime_len { Type::Unknown } else { Type::Nil });
let offset = i32::try_from(i * (SIZEOF_VALUE as u32)).unwrap();

// Missing elements are Qnil
asm.comment(&format!("load array[{}]", i));
let elem_opnd = if (i as u32) < comptime_len { Opnd::mem(64, ary_opnd, offset) } else { Qnil.into() };
let elem_opnd = if i < comptime_len { Opnd::mem(64, ary_opnd, offset) } else { Qnil.into() };
asm.mov(top, elem_opnd);
}
}
Expand Down

0 comments on commit 90e6b01

Please sign in to comment.