Skip to content

Commit 723b335

Browse files
committed
fix alignment for calls on x86
1 parent bb2ddd0 commit 723b335

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

zjit/src/backend/lir.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2352,8 +2352,7 @@ impl Assembler
23522352
.collect();
23532353

23542354
// Push all survivors on the stack
2355-
// TODO: Figure out optimal alignment. Are these pushes
2356-
// encoded optimally?
2355+
let needs_alignment = cfg!(target_arch = "x86_64") && survivors.len() % 2 == 1;
23572356
for &s in &survivors {
23582357
let reg_n = match assignments[s].unwrap() {
23592358
Allocation::Reg(n) => n,
@@ -2362,6 +2361,11 @@ impl Assembler
23622361
new_insns.push(Insn::CPush(Opnd::Reg(ALLOC_REGS[reg_n])));
23632362
new_ids.push(None);
23642363
}
2364+
// Maintain 16-byte stack alignment for x86_64
2365+
if needs_alignment {
2366+
new_insns.push(Insn::CPush(Opnd::Reg(ALLOC_REGS[0])));
2367+
new_ids.push(None);
2368+
}
23652369

23662370
// Extract arguments from CCall, clear opnds
23672371

@@ -2420,6 +2424,11 @@ impl Assembler
24202424
new_ids.push(None);
24212425

24222426
// Pop in reverse order
2427+
// Remove alignment padding first
2428+
if needs_alignment {
2429+
new_insns.push(Insn::CPopInto(Opnd::Reg(ALLOC_REGS[0])));
2430+
new_ids.push(None);
2431+
}
24232432
for &s in survivors.iter().rev() {
24242433
let reg_n = match assignments[s].unwrap() {
24252434
Allocation::Reg(n) => n,

0 commit comments

Comments
 (0)