Re: [PATCH RFC 2/2] LoongArch: BPF: Eliminate zero/sign extensions for 32-bit operations
From: Tiezhu Yang
Date: Sun Jul 26 2026 - 22:51:25 EST
On 2026/7/26 下午5:23, Hengqi Chen wrote:
On Sat, Jul 11, 2026 at 6:17 PM Tiezhu Yang <yangtiezhu@xxxxxxxxxxx> wrote:
Eliminate frequent and redundant zero-extensions and sign-extensions
for 32-bit operations. This prevents potential functional bugs caused
by incorrect extension selections and reduces runtime overhead.
...
@@ -741,28 +725,32 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool ext
switch (code) {
/* dst = src */
case BPF_ALU | BPF_MOV | BPF_X:
+ if (imm == 1) {
+ emit_insn(ctx, lu32id, reg, 0);
reg ?
+ break;
...
/* dst = dst & imm */
case BPF_ALU | BPF_AND | BPF_K:
+ if (is_unsigned_imm12(imm)) {
+ emit_insn(ctx, andi, dst, dst, imm);
+ } else {
+ move_imm(ctx, t1, imm);
+ emit_insn(ctx, and, dst, dst, t1);
+ }
+ emit_insn(ctx, addiw, dst, dst, 0);
break; ?
Thanks for your review.
As mentioned in the cover letter, this hasn't been tested.
I just want to confirm that this is the correct direction.
The long-term goal is to eliminate frequent and redundant
zero-extensions and sign-extensions, but there are still
some issues to sort out. I will send the formal patch once
all problems are fixed.
For now, I will send out the stable and verified patches
first this week.
Thanks,
Tiezhu