This is an archive of the discontinued LLVM Phabricator instance.

[SLC] Optimize mempcpy_chk to mempcpy
ClosedPublic

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

Details

Summary

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
llvm/test/Transforms/InstCombine/fortify-folding.ll
36

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

Updated.

Ping.

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

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