A store of an immediate first moves it into a temporary, also for a zero, which the zero register provides for free. Store it from xzr, which saves the mov on every zeroing of a stack slot, as LLVM with cpu v4 emits them in rows to initialize the structs and arrays BPF programs hand to helpers. Before/after for *(u64 *)(r10 - 8) = 0 with 16 bytes of stack: d280000a mov x10, #0x0 f90007ea str x10, [sp, #8] f90007ff str xzr, [sp, #8] Signed-off-by: Daniel Borkmann --- arch/arm64/net/bpf_jit_comp.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c index 2a9bbd600bc0..b459f50fd533 100644 --- a/arch/arm64/net/bpf_jit_comp.c +++ b/arch/arm64/net/bpf_jit_comp.c @@ -2089,9 +2089,10 @@ static int build_insn(const struct bpf_verifier_env *env, const struct bpf_insn emit(A64_ADD(1, tmp3, dst, arena_vm_base), ctx); dst = tmp3; } - /* Load imm to a register then store it */ - emit_a64_mov_i(1, tmp, imm, ctx); - emit_ldst(code, tmp, dst, off, tmp2, ctx); + /* A zero comes from the zero register, any other imm through a register */ + if (imm) + emit_a64_mov_i(1, tmp, imm, ctx); + emit_ldst(code, imm ? tmp : A64_ZR, dst, off, tmp2, ctx); ret = add_exception_handler(insn, ctx, DONT_CLEAR); if (ret) -- 2.43.0