Re: [PATCH v3 3/3] LoongArch: BPF: Optimize 32-bit operations using native instructions
From: Hengqi Chen
Date: Tue Oct 27 2026 - 04:14:16 EST
On Tue, Oct 27, 2026 at 12:10 PM Tiezhu Yang <yangtiezhu@xxxxxxxxxxx> wrote:
>
> On 2026/10/27 上午10:02, Hengqi Chen wrote:
> > On Fri, Oct 16, 2026 at 4:10 PM Tiezhu Yang <yangtiezhu@xxxxxxxxxxx> wrote:
> >>
> >> Currently, the LoongArch BPF JIT emits numerous redundant zero and sign
> >> extensions across 32-bit operations, bloating the final JIT image size
> >> and also leading to runtime overhead, particularly in the division and
> >> modulo operations. Thus, it is necessary to optimize 32-bit operations
> >> by emitting LoongArch native 32-bit word instructions.
>
> ...
>
> >> + if (cpu_has_div32) {
> >> + if (!off)
> >> + emit_insn(ctx, divwu, dst, dst, src);
> >> + else
> >> + emit_insn(ctx, divw, dst, dst, src);
> >
> > For ALU32 SDIV, off != 0, it seems like there is a overflow in S32_MIN / -1.
> > verifier_sdiv.c has related test cases but annotate with
> > __arch_x86_64, so it is not run on LoongArch.
>
> After enabling the signed division and modulo overflow tests for
> LoongArch, here are the test results:
>
> $ sudo ./test_progs -t verifier_sdiv | grep "MIN/-1"
> #731/121 verifier_sdiv/SDIV64, overflow r/r, LLONG_MIN/-1:OK
> #731/123 verifier_sdiv/SDIV64, overflow r/i, LLONG_MIN/-1:OK
> #731/125 verifier_sdiv/SDIV32, overflow r/r, INT_MIN/-1:OK
> #731/127 verifier_sdiv/SDIV32, overflow r/i, INT_MIN/-1:OK
> #731/129 verifier_sdiv/SMOD64, overflow r/r, LLONG_MIN/-1:OK
> #731/131 verifier_sdiv/SMOD64, overflow r/i, LLONG_MIN/-1:OK
> #731/133 verifier_sdiv/SMOD32, overflow r/r, INT_MIN/-1:OK
> #731/135 verifier_sdiv/SMOD32, overflow r/i, INT_MIN/-1:OK
>
> That is to say, the current jit code is no problem.
>
Great.
Acked-by: Hengqi Chen <hengqi.chen@xxxxxxxxx>
> Thanks,
> Tiezhu
>