[llvm] f62de7c - [SLC] Transform strncpy(dst, "text", C) to memcpy(dst, "text\0\0\0", C) for C <= 128 only
Joerg Sonnenberger via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 23 11:45:41 PDT 2020
On Fri, Aug 14, 2020 at 04:53:43PM -0700, Dávid Bolvanský via llvm-commits wrote:
>
> Author: Dávid Bolvanský
> Date: 2020-08-15T01:53:32+02:00
> New Revision: f62de7c9c71134af060a3a1686e30e69d439e785
>
> URL: https://github.com/llvm/llvm-project/commit/f62de7c9c71134af060a3a1686e30e69d439e785
> DIFF: https://github.com/llvm/llvm-project/commit/f62de7c9c71134af060a3a1686e30e69d439e785.diff
>
> LOG: [SLC] Transform strncpy(dst, "text", C) to memcpy(dst, "text\0\0\0", C) for C <= 128 only
>
> Transformation creates big strings for big C values, so bail out for C > 128.
This seems to be mixing two unrelated things? Unless we are optimizing
strictly for size, the length of the string itself doesn't matter. The
amount we extend it is relevant. Let's consider this from the logical
perspective first. strncpy(dst, "text", C) is equivalent to memcpy +
memset. We can and should fold the memset into the string for smallish
extra, I'd say if it is smaller than 16? Otherwise, it is still
profitable to turn the strncpy into a memcpy followed by memset?
Joerg
More information about the llvm-commits
mailing list