On Sat, Oct 15, 2016 at 04:01:36PM -0700, Mehdi Amini via llvm-dev wrote:> > > On Oct 15, 2016, at 3:56 PM, Wolfgang McSneed via llvm-dev <llvm-dev at lists.llvm.org> wrote: > > > > Hi, > > > > I am hoping that someone can help me figure out how to prevent the insertion of "memcpy" from the assembly source. > > > > My target is an instruction set simulator that doesn't support this. > > > > Thank you for your valuable time. > > > > Wolf > > > > Here are my compile commands: > > $ clang -emit-llvm -fno-builtin -o3 --target=mips -S matrix_float.c -o vl_matrix_float.ll > > 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. 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. Joerg
Hi Mehdi and Joerg, Thanks for your fast response! attached is the matrix_float.c file. Also - I should point out that I am using MIPS ISS. Thanks, Wolf Kind Regards, Wolf On Sat, Oct 15, 2016 at 6:07 PM, Joerg Sonnenberger via llvm-dev < llvm-dev at lists.llvm.org> wrote:> On Sat, Oct 15, 2016 at 04:01:36PM -0700, Mehdi Amini via llvm-dev wrote: > > > > > On Oct 15, 2016, at 3:56 PM, Wolfgang McSneed via llvm-dev < > llvm-dev at lists.llvm.org> wrote: > > > > > > Hi, > > > > > > I am hoping that someone can help me figure out how to prevent the > insertion of "memcpy" from the assembly source. > > > > > > My target is an instruction set simulator that doesn't support this. > > > > > > Thank you for your valuable time. > > > > > > Wolf > > > > > > Here are my compile commands: > > > $ clang -emit-llvm -fno-builtin -o3 --target=mips -S matrix_float.c -o > vl_matrix_float.ll > > > > 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. 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. > > Joerg > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161015/0cf2eccc/attachment.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: matrix_float.c Type: text/x-csrc Size: 2706 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161015/0cf2eccc/attachment.c>
Even with -ffreestanding LLVM generates memcpy/memset? Does this mean some passes do not honor this flag? If you really wanted to prevent libcalls, you could technically translate those memcpy/memset to loops in lowering. Kevin On Sat, Oct 15, 2016 at 4:10 PM, Wolfgang McSneed via llvm-dev < llvm-dev at lists.llvm.org> wrote:> Hi Mehdi and Joerg, > > Thanks for your fast response! attached is the matrix_float.c file. > > Also - I should point out that I am using MIPS ISS. > > Thanks, > > Wolf > > Kind Regards, > > Wolf > > On Sat, Oct 15, 2016 at 6:07 PM, Joerg Sonnenberger via llvm-dev < > llvm-dev at lists.llvm.org> wrote: > >> On Sat, Oct 15, 2016 at 04:01:36PM -0700, Mehdi Amini via llvm-dev wrote: >> > >> > > On Oct 15, 2016, at 3:56 PM, Wolfgang McSneed via llvm-dev < >> llvm-dev at lists.llvm.org> wrote: >> > > >> > > Hi, >> > > >> > > I am hoping that someone can help me figure out how to prevent the >> insertion of "memcpy" from the assembly source. >> > > >> > > My target is an instruction set simulator that doesn't support this. >> > > >> > > Thank you for your valuable time. >> > > >> > > Wolf >> > > >> > > Here are my compile commands: >> > > $ clang -emit-llvm -fno-builtin -o3 --target=mips -S matrix_float.c >> -o vl_matrix_float.ll >> > >> > 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. 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. >> >> Joerg >> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org >> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >> > > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161015/6f08e2c1/attachment.html>
On Sat, Oct 15, 2016 at 06:10:05PM -0500, Wolfgang McSneed wrote:> Thanks for your fast response! attached is the matrix_float.c file.Are you intentionally not using static (& const) arrays? The compiler has to use a copy to initialize a & b, given the size, it will use a memcpy from a read-only section for that. Joerg
> On Oct 15, 2016, at 4:07 PM, Joerg Sonnenberger via llvm-dev <llvm-dev at lists.llvm.org> wrote: > > On Sat, Oct 15, 2016 at 04:01:36PM -0700, Mehdi Amini via llvm-dev wrote: >> >>> On Oct 15, 2016, at 3:56 PM, Wolfgang McSneed via llvm-dev <llvm-dev at lists.llvm.org> wrote: >>> >>> Hi, >>> >>> I am hoping that someone can help me figure out how to prevent the insertion of "memcpy" from the assembly source. >>> >>> My target is an instruction set simulator that doesn't support this. >>> >>> Thank you for your valuable time. >>> >>> Wolf >>> >>> Here are my compile commands: >>> $ clang -emit-llvm -fno-builtin -o3 --target=mips -S matrix_float.c -o vl_matrix_float.ll >> >> 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 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 <https://gcc.gnu.org/onlinedocs/gcc/Standards.html#Standards> — Mehdi -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161015/4ed5f2ee/attachment.html>
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#StandardsThe 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