This is an archive of the discontinued LLVM Phabricator instance.

[funcattrs] Infer writeonly argument attribute [part 2]
ClosedPublic

Authored by reames on Dec 2 2021, 3:05 PM.

Details

Summary

This builds on the code from D114963, and extends it to handle calls both direct and indirect. With the revised code structure (from series of previously landed NFCs), this is pretty straight forward.

One thing to note is that we can not infer writeonly for arguments which might be captured. If the pointer can be read back by the caller, and then read through, we have no way to track that. This is the same restriction we have for readonly, except that we get no mileage out of the "callee can be readonly" exception since a writeonly param on a readonly function is either a) readnone or b) UB. This means we can't actually infer much unless nocapture has already been inferred.

Diff Detail

Event Timeline

reames created this revision.Dec 2 2021, 3:05 PM
reames requested review of this revision.Dec 2 2021, 3:05 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptDec 2 2021, 3:05 PM
reames planned changes to this revision.Dec 3 2021, 10:31 AM

Has the same propagation bug fixed in 7b54de5f, need to rework.

reames updated this revision to Diff 397124.Jan 3 2022, 12:50 PM
reames edited the summary of this revision. (Show Details)

Rework account for only being to infer on nocapture arguments.

nikic accepted this revision.Jan 4 2022, 1:13 AM
nikic added a subscriber: nikic.

LGTM

llvm/lib/Transforms/IPO/FunctionAttrs.cpp
728

This could be written as CB.doesNotReadMemory() || CB.doesNotReadMemory(UseIndex) for symmetry with the other cases. Though personally I find the naming of these methods really unfortunate (they should probably be called onlyWritesMemory()) so maybe the explicit form is better.

This revision is now accepted and ready to land.Jan 4 2022, 1:13 AM
reames added inline comments.Jan 4 2022, 8:52 AM
llvm/lib/Transforms/IPO/FunctionAttrs.cpp
728

I'm leaving this as is, but I agree we could use some naming cleanup here. (I may even do it since this is the second time I've hit this.)

Though to highlight "does not read memory" and "WriteOnly" are not quite the same. The former allows readnone which is correct, but surprising here. Personally, I hate subtle semantic surprises and am increasing of the view that we should check the attributes we mean. (At least in inference code.)

This revision was landed with ongoing or failed builds.Jan 4 2022, 9:08 AM
This revision was automatically updated to reflect the committed changes.