Re: [PATCH v1 1/3] LoongArch: BPF: Remove redundant zext jumping in move_imm()
Hengqi Chen <[email protected]> Sun, 26 Jul 2026 16:35:27 +0800
| Newsgroups | dev.linux.lists.loongarch,org.kernel.vger.bpf,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <CAEyhmHRFRTyV=HoRDKz7KzdGUQdg=KkbpHmkauEEKBB6AvdnPA@mail.gmail.com> |
On Sat, Jul 11, 2026 at 6:10=E2=80=AFPM Tiezhu Yang <[email protected]= > 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 <[email protected]> > --- > 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 <[email protected]> > 2.42.0 >