On Fri, Jun 2, 2023 at 3:11 AM Alexandre Oliva via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > On Jan 19, 2023, Alexandre Oliva <ol...@adacore.com> wrote: > > > Would it make more sense to extend it, even constrained by the > > limitations mentioned above, or handle memset only? In the latter case, > > would it still make sense to adopt a command-line option that suggests a > > broader effect than it already has, even if it's only a hopeful future > > extension? -finline-all-stringops[={memset,memcpy,...}], that you > > suggested, seems to be a reasonable and extensible one to adopt. > > I ended up implementing all of memset, memcpy, memmove, and memcmp: > > Introduce -finline-stringops > > try_store_by_multiple_pieces was added not long ago, enabling > variable-sized memset to be expanded inline when the worst-case > in-range constant length would, using conditional blocks with powers > of two to cover all possibilities of length and alignment. > > This patch introduces -finline-stringops[=fn] to request expansions to > start with a loop, so as to still take advantage of known alignment > even with long lengths, but without necessarily adding store blocks > for every power of two. > > This makes it possible for the supported stringops (memset, memcpy, > memmove, memset) to be expanded, even if storing a single byte per > iteration. Surely efficient implementations can run faster, with a > pre-loop to increase alignment, but that would likely be excessive for > inline expansions. > > Still, in some cases, such as in freestanding environments, users > prefer to inline such stringops, especially those that the compiler > may introduce itself, even if the expansion is not as performant as a > highly optimized C library implementation could be, to avoid > depending on a C runtime library. > > Regstrapped on x86_64-linux-gnu, also bootstrapped with > -finline-stringops enabled by default, and tested with arm, aarch, 32- > and 64-bit riscv with gcc-12. Ok to install? >[...]
This seems to be related to Clang's __builtin_mem{set,cpy}_inline . I just created https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110094 ("Support __builtin_mem*_inline").