This is an archive of the discontinued LLVM Phabricator instance.

[funcattrs] Add the maximal set of implied attributes to definitions
ClosedPublic

Authored by reames on Apr 9 2021, 1:05 PM.

Details

Summary

Have funcattrs expand all implied attributes into the IR. This expands the infrastructure from D100400, but for definitions not declarations this time.

Somewhat subtly, this mostly isn't semantic. Because the accessors did the inference, any client which used the accessor was already getting the stronger result. Clients that directly checked presence of attributes (there are some), will see a stronger result now.

The old behavior can end up quite confusing for two reasons:

  • Without this change, we have situations where function-attrs appears to fail when inferring an attribute (as seen by a human reading IR), but that consuming code will see that it should have been implied. As a human trying to sanity check test results and study IR for optimization possibilities, this is exceeding error prone and confusing. (I'll note that I wasted several hours recently because of this.)
  • We can have transforms which trigger without the IR appearing (on inspection) to meet the preconditions. This change doesn't prevent this from happening (as the accessors still involve multiple checks), but it should make it less frequent.

I'd argue in favor of deleting the extra checks out of the accessors after this lands, but I want that in it's own review as a) it's purely stylistic, and b) I already know there's some disagreement.

Once this lands, I'm also going to do a cleanup change which will delete some now redundant duplicate predicates in the inference code, but again, that deserves to be a change of it's own.

Diff Detail

Event Timeline

reames created this revision.Apr 9 2021, 1:05 PM
reames requested review of this revision.Apr 9 2021, 1:05 PM
Herald added a reviewer: baziotis. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: bbn. · View Herald Transcript
nikic added inline comments.Apr 11 2021, 8:06 AM
llvm/lib/Transforms/IPO/FunctionAttrs.cpp
1277

Do I understand right that this is here for declarations that have been annotated as __attribute___((readonly))? Rather than handling it here, maybe this should be done in InferFunctionAttrsPass? It currently only handles libcalls, but I think it fits there conceptually.

reames planned changes to this revision.Apr 12 2021, 3:35 PM
reames added inline comments.
llvm/lib/Transforms/IPO/FunctionAttrs.cpp
1277

I agree with this suggestion, and will reformulate the patch to that effect.

reames added inline comments.
llvm/lib/Transforms/IPO/FunctionAttrs.cpp
1277

This suggestion is now implemented and ready for review (https://reviews.llvm.org/D100400).

Once that lands, I'll rewrite this patch using the function introduced there. (We have the same problem for non-declarations when our logic for inference is not equally strong.)

reames updated this revision to Diff 337580.Apr 14 2021, 5:06 PM
reames retitled this revision from Explicitly annotate nofree functions inferred from readonly/readnone to [funcattrs] Add the maximal set of implied attributes to definitions.
reames edited the summary of this revision. (Show Details)

Adjust patch and description to be in line with the direction suggested by reviewer, and started in D100400.

nikic accepted this revision.Apr 16 2021, 1:28 PM

LGTM

This revision is now accepted and ready to land.Apr 16 2021, 1:28 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 16 2021, 2:22 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
thopre added a subscriber: thopre.Apr 27 2021, 6:50 AM
thopre added inline comments.
llvm/test/Transforms/FunctionAttrs/2008-09-03-ReadOnly.ll
14–15

I'm getting #0 for both functions. Any idea why that might happen?

jdoerfert added inline comments.Apr 27 2021, 6:55 AM
llvm/test/Transforms/FunctionAttrs/2008-09-03-ReadOnly.ll
14–15

Random guess: your cmake was not rebuild since we switched to the new-PM and opt defaults to the old one?

thopre added inline comments.Apr 27 2021, 6:59 AM
llvm/test/Transforms/FunctionAttrs/2008-09-03-ReadOnly.ll
14–15

That's a good guess! We are still using the old PM. Thanks!