Skip to content

Commit 1f07568

Browse files
DinoVmeta-codesync[bot]
authored andcommitted
Fix FP register encoding and stack alignment in codegen
Summary: Fix two AArch64 code generation bugs: 1. In generatePrologue, FP argument loading used a64::d(arg.loc) directly, but arg.loc includes the VECD_REG_BASE offset (e.g., 32 for D0). This produced invalid register IDs like d32 instead of d0. Fix by subtracting VECD_REG_BASE, consistent with all other FP register construction in the codebase. 2. In rewriteRegularFunction, the stack argument buffer size was not aligned to kStackAlign (16 bytes). When a regular function call had an odd number of stack-spilled arguments, the unaligned size triggered an assertion failure in generatePrologue on AArch64 where the stack pointer must always be 16-byte aligned. Fix by rounding up the buffer size, consistent with prepareArgsArray which already does this for vectorcall paths. Reviewed By: kddnewton Differential Revision: D93875144 fbshipit-source-id: 9454441b7941572f98f318a43ba508803f318885
1 parent a3a8ffd commit 1f07568

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

cinderx/Jit/codegen/gen_asm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1694,7 +1694,7 @@ void NativeGenerator::generatePrologue(
16941694
as_, kArgsReg, i * sizeof(void*), arch::reg_scratch_0));
16951695
} else {
16961696
as_->ldr(
1697-
a64::d(arg.loc),
1697+
a64::d(arg.loc - VECD_REG_BASE),
16981698
arch::ptr_resolve(
16991699
as_, kArgsReg, i * sizeof(void*), arch::reg_scratch_0));
17001700
}

cinderx/Jit/lir/postalloc.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ int rewriteRegularFunction(instr_iter_t instr_iter) {
147147
}
148148
}
149149

150+
// Align to kStackAlign for AArch64 stack pointer alignment requirements.
151+
if (stack_arg_size % kStackAlign != 0) {
152+
stack_arg_size += kStackAlign - (stack_arg_size % kStackAlign);
153+
}
150154
return stack_arg_size;
151155
}
152156

0 commit comments

Comments
 (0)