return memccpy(d, "helloworld", 'r', 20)
>
return memcpy(d, "helloworld", 8 /* pos of 'r' in string */), d + 8
Differential D68089
[InstCombine] Optimize some memccpy calls to memcpy/null xbolva00 on Sep 26 2019, 9:07 AM. Authored by
Details return memccpy(d, "helloworld", 'r', 20) >return memcpy(d, "helloworld", 8 /* pos of 'r' in string */), d + 8
Diff Detail Event TimelineComment Actions (Comments using argument names from the signature void *memccpy(void *dest, const void *src, int c, size_t n);.) Please add a testcase where the optimization triggers and "c" is 0. (I think getConstantStringInfo trims the null terminator by default?) It should be possible to optimize cases where "c" doesn't appear in "src" if "n" is smaller than the length of "src".
Comment Actions
Ah, right.
Comment Actions
We dont even need to know n. If c is not in src, we have just memcpy(dst, src, n), no? Comment Actions
I think it's possible for there to be valid data after the array returned by getConstantStringInfo, in some cases. For example, if you're doing a memccpy out of something like struct X { char a[10]; char b[10]; }. Maybe worth adding a testcase. Comment Actions
I added test with string like "blabla\0x" and stop char is 'x'. As test shows, we leave this case as is. Sorry if I misunderstood you. This comment was removed by xbolva00.
This comment was removed by xbolva00. This comment was removed by xbolva00. This comment was removed by xbolva00. Comment Actions LGTM.
|
Unclear why we name Size.