Skip to content

Commit b19e3b0

Browse files
authored
ZJIT: Avoid unnecessary PopOpnds and PushOpnds codegen (ruby#14614)
* ZJIT: Avoid unnecessary `PopOpnds` codegen If there's no opnds to restore, we don't need to do anything. * ZJIT: Avoid unnecessary sub_into when there's no opnds to allocate
1 parent 6afbbb1 commit b19e3b0

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

zjit/src/codegen.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2006,8 +2006,12 @@ fn gen_push_opnds(jit: &mut JITState, asm: &mut Assembler, opnds: &[Opnd]) -> li
20062006
let frame_size = aligned_stack_bytes(jit.c_stack_slots);
20072007
let allocation_size = aligned_stack_bytes(n);
20082008

2009-
asm_comment!(asm, "allocate {} bytes on C stack for {} values", allocation_size, n);
2010-
asm.sub_into(NATIVE_STACK_PTR, allocation_size.into());
2009+
if n != 0 {
2010+
asm_comment!(asm, "allocate {} bytes on C stack for {} values", allocation_size, n);
2011+
asm.sub_into(NATIVE_STACK_PTR, allocation_size.into());
2012+
} else {
2013+
asm_comment!(asm, "no opnds to allocate");
2014+
}
20112015

20122016
// Calculate the total offset from NATIVE_BASE_PTR to our buffer
20132017
let total_offset_from_base = (frame_size + allocation_size) as i32;
@@ -2024,6 +2028,11 @@ fn gen_push_opnds(jit: &mut JITState, asm: &mut Assembler, opnds: &[Opnd]) -> li
20242028
}
20252029

20262030
fn gen_pop_opnds(asm: &mut Assembler, opnds: &[Opnd]) {
2031+
if opnds.is_empty() {
2032+
asm_comment!(asm, "no opnds to restore");
2033+
return
2034+
}
2035+
20272036
asm_comment!(asm, "restore C stack pointer");
20282037
let allocation_size = aligned_stack_bytes(opnds.len());
20292038
asm.add_into(NATIVE_STACK_PTR, allocation_size.into());

0 commit comments

Comments
 (0)