[PATCH] D61634: [clang/llvm] Allow efficient implementation of libc's memory functions in C/C++

Eli Friedman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri May 10 12:14:16 PDT 2019


efriedma added a comment.

> -fno-builtin* is about preventing clang/llvm from recognizing that a piece of code has the same semantic as a particular IR intrinsic, it has nothing to do with preventing the compiler from generating runtime calls.

It has a dual purpose for C library functions.  One, it prevents the compiler from assuming an explicitly written call to that function has some particular semantics.  Two, it prevents the compiler from assuming the underlying library function exists for the purpose of optimization.  (These are sort of intertwined, but they both matter in this context.)

> I believe very few people will use the attribute described in the RFC, it will most probably be library maintainers that already know a good deal of how the compiler is allowed to transform the code.

Sure, I'm happy to assume that memcpy/memset implementations are written using some appropriate subset of C.  (We should probably document that subset at some point.)

------

I still think there are really two things you're trying to accomplish here, which should be handled separately.

1. Add a function attribute that works like -fno-builtin-memcpy currently does, to prevent the compiler from synthesizing calls to memcpy.
2. Provide a convenient way to write a small, fixed-length "memcpy", in C and in LLVM IR, that is always expanded to optimal straight-line code (without any calls or loops).

These correspond to proposals (1) and (2) from your RFC; I think we need both to arrive at a reasonable final state.

(The "rep; movs" is a third thing, which I think should also be handled separately, but it sounds like you don't think that's very important.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61634/new/

https://reviews.llvm.org/D61634





More information about the cfe-commits mailing list