Page MenuHomePhabricator

[SLC] Optimize mempcpy_chk to mempcpy

Authored by xbolva00 on Aug 15 2020, 9:04 AM.



As reported in PR46735:

void* f(void *d, const void *s, size_t l)

return __builtin___mempcpy_chk(d, s, l, __builtin_object_size(d, 0));


This can be optimized to return mempcpy(d, s, l);.

Diff Detail

Event Timeline

xbolva00 created this revision.Aug 15 2020, 9:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 15 2020, 9:04 AM
xbolva00 requested review of this revision.Aug 15 2020, 9:04 AM
xbolva00 added inline comments.Aug 15 2020, 9:11 AM

Well actually LLVM goes futher and transforms mempcpy to memcpy + dst, since we have more optimizations for memcpy.

xbolva00 retitled this revision from [SLC] Optimize _mempcpy_chk to direct call to mempcpy to [SLC] Optimize mempcpy_chk to mempcpy.Aug 15 2020, 10:09 AM

This patch has an obvious miscompile; please try to be more careful testing your patches.

Eh, copy paste error from memcpy.

I will fix it.

xbolva00 updated this revision to Diff 290129.Sep 6 2020, 2:10 AM
xbolva00 updated this revision to Diff 291391.Sep 12 2020, 7:08 AM



This revision is now accepted and ready to land.Sun, Oct 4, 10:07 PM
This revision was automatically updated to reflect the committed changes.
MaskRay added a subscriber: MaskRay.Mon, Oct 5, 1:48 PM

(Minor nit: [SLC] is not obvious. SimplifyLibCalls may be better.)