summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Lo <stan.lo@shopify.com>2025-09-20 00:03:02 +0100
committerGitHub <noreply@github.com>2025-09-19 23:03:02 +0000
commitb19e3b0f060586dae91b567794128efb747b3f24 (patch)
tree55e52f3166d0229534ac0597b2e101d1a437a877
parent6afbbb11785e483c7dba2a803e611904d32ec01f (diff)
ZJIT: Avoid unnecessary `PopOpnds` and `PushOpnds` codegen (#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
-rw-r--r--zjit/src/codegen.rs13
1 files changed, 11 insertions, 2 deletions
diff --git a/zjit/src/codegen.rs b/zjit/src/codegen.rs
index 7185c171c1..0b236d0b57 100644
--- a/zjit/src/codegen.rs
+++ b/zjit/src/codegen.rs
@@ -2006,8 +2006,12 @@ fn gen_push_opnds(jit: &mut JITState, asm: &mut Assembler, opnds: &[Opnd]) -> li
let frame_size = aligned_stack_bytes(jit.c_stack_slots);
let allocation_size = aligned_stack_bytes(n);
- asm_comment!(asm, "allocate {} bytes on C stack for {} values", allocation_size, n);
- asm.sub_into(NATIVE_STACK_PTR, allocation_size.into());
+ if n != 0 {
+ asm_comment!(asm, "allocate {} bytes on C stack for {} values", allocation_size, n);
+ asm.sub_into(NATIVE_STACK_PTR, allocation_size.into());
+ } else {
+ asm_comment!(asm, "no opnds to allocate");
+ }
// Calculate the total offset from NATIVE_BASE_PTR to our buffer
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
}
fn gen_pop_opnds(asm: &mut Assembler, opnds: &[Opnd]) {
+ if opnds.is_empty() {
+ asm_comment!(asm, "no opnds to restore");
+ return
+ }
+
asm_comment!(asm, "restore C stack pointer");
let allocation_size = aligned_stack_bytes(opnds.len());
asm.add_into(NATIVE_STACK_PTR, allocation_size.into());