[llvm-branch-commits] [llvm] [llvm][IR] Treat memcmp and bcmp as libcalls (PR #135706)
Eli Friedman via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Apr 15 12:19:13 PDT 2025
efriedma-quic wrote:
There are, currently, basically three different ways to supply libc which we support:
- Dynamic linking: the libc isn't part of your program at all, it's part of the environment. You only have the abstract interface.
- Static linking, no LTO of libc: the libc becomes part of your program at link-time: the linker lowers the libc abstraction into concrete calls.
- -fno-builtins: The libc, excluding a small set of functions which are necessary for codegen, becomes part of your program at compile-time; once you're in LLVM IR, the abstraction is gone.
To do "LTO of libc", you want something else... but you need to define what "something else" is. There needs to be a clearly delineated point at which libc implementation bits transition from an abstraction to concrete code. If your libc cooperates, that point can be different for different interfaces, but there still needs to be a specific point. You can't just blindly throw everything at the existing optimizer and hope for the best.
If you say memcmp stays an abstraction past codegen, you're getting basically zero benefit from LTO'ing it, as far as I can tell: the caller is opaque to the callee, and the callee is opaque to the caller. At best. At worst, your code explodes because your memcmp implementation depends on runtime CPU detection code that runs startup, and LTO can't understand the dependency between the detection code and memcmp.
So in essence, I feel like can't review this patch without a proposal that addresses where we're going overall.
https://github.com/llvm/llvm-project/pull/135706
More information about the llvm-branch-commits
mailing list