]> git.ipfire.org Git - thirdparty/gcc.git/commit
bpf: add inline memmove and memcpy expansion
authorDavid Faust <david.faust@oracle.com>
Tue, 20 Feb 2024 22:48:33 +0000 (14:48 -0800)
committerDavid Faust <david.faust@oracle.com>
Wed, 21 Feb 2024 16:36:07 +0000 (08:36 -0800)
commit5772ea772d1dce5bd9a3be99bf095f6f67810db2
tree69aabfd7057f0931628a42e8e7f840087503e2d8
parent161a67b2bee84d8fd5ab7711e411f76221c1ea52
bpf: add inline memmove and memcpy expansion

BPF programs are not typically linked, which means we cannot fall back
on library calls to implement __builtin_{memmove,memcpy} and should
always expand them inline if possible.

GCC already successfully expands these builtins inline in many cases,
but failed to do so for a few for simple cases involving overlapping
memmove in the kernel BPF selftests and was instead emitting a libcall.

This patch implements a simple inline expansion of memcpy and memmove in
the BPF backend in a verifier-friendly way, with the caveat that the
size must be an integer constant, which is also required by clang.

gcc/

* config/bpf/bpf-protos.h (bpf_expand_cpymem): New.
* config/bpf/bpf.cc: (emit_move_loop, bpf_expand_cpymem): New.
* config/bpf/bpf.md: (cpymemdi, movmemdi): New define_expands.

gcc/testsuite/

* gcc.target/bpf/memcpy-1.c: New test.
* gcc.target/bpf/memmove-1.c: New test.
* gcc.target/bpf/memmove-2.c: New test.
gcc/config/bpf/bpf-protos.h
gcc/config/bpf/bpf.cc
gcc/config/bpf/bpf.md
gcc/testsuite/gcc.target/bpf/memcpy-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/bpf/memmove-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/bpf/memmove-2.c [new file with mode: 0644]