Re: [PATCH v1 1/3] LoongArch: BPF: Remove redundant zext jumping in move_imm()

From: Hengqi Chen

Date: Sun Jul 26 2026 - 04:35:47 EST


On Sat, Jul 11, 2026 at 6:10 PM Tiezhu Yang <yangtiezhu@xxxxxxxxxxx> wrote:
>
> In move_imm(), when an immediate hits the 12-bit unsigned range, an
> `ori rd, $zero, imm` instruction is emitted.
>
> According to the manual, the ori instruction inherently performs a
> logical or with zero-extended immediate operands against $zero, so
> the upper 32 bits of the destination register `rd` are already 0.
>

It would be great to add a link to the doc:
https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html#_andi_ori_xori

> However, the existing JIT code unconditionally executes `goto zext;`
> after ori, forcing it to fallthrough into `emit_zext_32()` to clear
> the upper 32 bits for 32-bit ALU operations.
>
> Fix this redundancy by directly returning from the function inside
> the `is_unsigned_imm12` block.
>
> Signed-off-by: Tiezhu Yang <yangtiezhu@xxxxxxxxxxx>
> ---
> arch/loongarch/net/bpf_jit.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/loongarch/net/bpf_jit.h b/arch/loongarch/net/bpf_jit.h
> index a8e29be35fa8..bb58c42c2f2a 100644
> --- a/arch/loongarch/net/bpf_jit.h
> +++ b/arch/loongarch/net/bpf_jit.h
> @@ -156,7 +156,7 @@ static inline void move_imm(struct jit_ctx *ctx, enum loongarch_gpr rd, long imm
> /* ori rd, $zero, imm_11_0 */
> if (is_unsigned_imm12(imm)) {
> emit_insn(ctx, ori, rd, LOONGARCH_GPR_ZERO, imm);
> - goto zext;
> + return;
> }
>
> /* lu52id rd, $zero, imm_63_52 */
> --

Acked-by: Hengqi Chen <hengqi.chen@xxxxxxxxx>

> 2.42.0
>