This is an archive of the discontinued LLVM Phabricator instance.

[InferAttrs] Add nocapture/writeonly to string/mem libcalls
ClosedPublic

Authored by xbolva00 on Oct 18 2020, 6:41 AM.

Details

Diff Detail

Event Timeline

xbolva00 created this revision.Oct 18 2020, 6:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 18 2020, 6:41 AM
xbolva00 requested review of this revision.Oct 18 2020, 6:41 AM
fhahn accepted this revision.Oct 21 2020, 5:52 AM
fhahn added a reviewer: efriedma.

LGTM, thanks! it might be good to wait a day or 2 with committing, so others can also take another look, because some of the changes can be quite subtle.

This revision is now accepted and ready to land.Oct 21 2020, 5:52 AM

Almost all the new setDoesNotCapture calls are wrong. If a call returns a pointer base on an argument, it can't be marked nocapture.

fhahn requested changes to this revision.Oct 21 2020, 2:27 PM

Almost all the new setDoesNotCapture calls are wrong. If a call returns a pointer base on an argument, it can't be marked nocapture.

Oh right, I was only thinking about stores & co for nocapture. Thanks!

This revision now requires changes to proceed.Oct 21 2020, 2:27 PM

FWIW, we should make "nocapture-maybe-return" an enum attribute, the Attributor uses that internally and can also put it in the IR if you are interested. It's quite helpful for capture analysis as we can simplify follow the return value, and therefore for aliasing.

xbolva00 updated this revision to Diff 301690.Oct 29 2020, 11:14 AM
This revision was not accepted when it landed; it landed in state Needs Review.Oct 29 2020, 12:07 PM
This revision was automatically updated to reflect the committed changes.
fhahn added inline comments.Apr 15 2021, 2:42 PM
llvm/lib/Transforms/Utils/BuildLibCalls.cpp
233

I believer this is causing the first argument of str(n)cat to be incorrectly marked as write only. str(n)cat appends at the end of the first string, but to do so it first needs to read the argument to find the end of the null-terminated string. I put up a fix D100601

xbolva00 added inline comments.Apr 15 2021, 3:14 PM
llvm/lib/Transforms/Utils/BuildLibCalls.cpp
233

Right, thanks!