Skip to content

Commit ce390f1

Browse files
nozomemeink0kubun
authored andcommitted
ZJIT: Remove redundant unboxing
1 parent 844f072 commit ce390f1

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

zjit/src/hir.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6545,10 +6545,9 @@ pub fn iseq_to_hir(iseq: *const rb_iseq_t) -> Result<Function, ParseError> {
65456545
let length = fun.push_insn(block, Insn::ArrayLength { array });
65466546
fun.push_insn(block, Insn::GuardBitEquals { val: length, expected: Const::CInt64(num as i64), reason: SideExitReason::ExpandArray, state: exit_id });
65476547
for i in (0..num).rev() {
6548-
let index = fun.push_insn(block, Insn::Const { val: Const::Value(VALUE::fixnum_from_usize(i.try_into().unwrap())) });
65496548
// We do not emit a length guard here because in-bounds is already
65506549
// ensured by the expandarray length check above.
6551-
let index = fun.push_insn(block, Insn::UnboxFixnum { val: index });
6550+
let index = fun.push_insn(block, Insn::Const { val: Const::CInt64(i.try_into().unwrap()) });
65526551
let element = fun.push_insn(block, Insn::ArrayAref { array, index });
65536552
state.stack_push(element);
65546553
}

zjit/src/hir/tests.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3565,12 +3565,10 @@ pub mod hir_build_tests {
35653565
v21:ArrayExact = GuardType v13, ArrayExact
35663566
v22:CInt64 = ArrayLength v21
35673567
v23:CInt64[2] = GuardBitEquals v22, CInt64(2)
3568-
v24:Fixnum[1] = Const Value(1)
3569-
v25:CInt64[1] = UnboxFixnum v24
3570-
v26:BasicObject = ArrayAref v21, v25
3571-
v27:Fixnum[0] = Const Value(0)
3572-
v28:CInt64[0] = UnboxFixnum v27
3573-
v29:BasicObject = ArrayAref v21, v28
3568+
v24:CInt64[1] = Const CInt64(1)
3569+
v25:BasicObject = ArrayAref v21, v24
3570+
v26:CInt64[0] = Const CInt64(0)
3571+
v27:BasicObject = ArrayAref v21, v26
35743572
PatchPoint NoEPEscape(test)
35753573
CheckInterrupts
35763574
Return v13

0 commit comments

Comments
 (0)