[llvm-dev] How to remove memcpy

Joerg Sonnenberger via llvm-dev llvm-dev at lists.llvm.org
Sat Oct 15 16:26:31 PDT 2016


On Sat, Oct 15, 2016 at 04:16:25PM -0700, Mehdi Amini wrote:
> >> Technically  -fno-bultin prevents the compiler from understand the
> >> memset in the original code. The right option to prevent the compiler
> >> from insert libc calls “out-of-the-blue” is -ffreestanding.
> > 
> > Huh? The -fno-builtin is not the problem.
> 
> I’m not sure what you mean by “it is not the problem” or how it relate to what I wrote.
> 
> Many people use -fno-builtin thinking it’ll prevent the compiler from
> calling memset. I’m pointing this isn’t true (the command line he
> posted includes -fno-builtin).

The original code contains no memset (nor memcpy). As such, -fno-builtin
does not change the interpretation of the program as far as lowering to
IR goes. The backend using memset internally is a completely unrelated
problem.


> > The compiler is *expected* to
> > call certain functions even for -ffreestanding. memcpy and memset are
> > two of those. It is certainly perfectly valid target lowering for
> > llvm.memcpy to be turned back into a libcall.
> 
> Source?
> AFAICT this is GCC behavior, but not the standard:
> https://gcc.gnu.org/onlinedocs/gcc/Standards.html#Standards

The standard has almost nothing to say about how freestanding really
works. It has a few requirements on what must be working in freestanding
environments, but the precise contract of what the compiler expects as
part of the ABI is outside the scope of the standard. Helper functions
for implementing division in software certainly fall into this scope as
well. The second-to-last paragraph are the lines about requirements GCC
puts on the environment, the same essentially applies to LLVM.

Joerg


More information about the llvm-dev mailing list