bpf, x86: Small optimization in comparing against imm0
authorDaniel Borkmann <daniel@iogearbox.net>
Wed, 2 Oct 2019 23:45:11 +0000 (01:45 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 4 Oct 2019 19:26:51 +0000 (12:26 -0700)
commit38f51c07054ff4796e473dba3bff2e648378002c
treece408174555426e21490d6c86c7d32fb1a444d8e
parentc588146378962786ddeec817f7736a53298a7b01
bpf, x86: Small optimization in comparing against imm0

Replace 'cmp reg, 0' with 'test reg, reg' for comparisons against
zero. Saves 1 byte of instruction encoding per occurrence. The flag
results of test 'reg, reg' are identical to 'cmp reg, 0' in all
cases except for AF which we don't use/care about. In terms of
macro-fusibility in combination with a subsequent conditional jump
instruction, both have the same properties for the jumps used in
the JIT translation. For example, same JITed Cilium program can
shrink a bit from e.g. 12,455 to 12,317 bytes as tests with 0 are
used quite frequently.

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Song Liu <songliubraving@fb.com>
Acked-by: John Fastabend <john.fastabend@gmail.com>
arch/x86/net/bpf_jit_comp.c