This is an archive of the discontinued LLVM Phabricator instance.

cache OptSize and MinSize attributes in the DAG
AbandonedPublic

Authored by spatel on Jul 31 2015, 11:42 AM.

Details

Summary

Fixing MinSize attribute handling to be more consistent was discussed in D11363.

This patch adds bools to the SelectionDAG to cache a function's MinSize and OptSize attributes. The main benefit is that we always make optimizing for size the logical 'or' of these attributes, so we don't have to repeat that logic everywhere.

Quentin made a similar change to the DAGCombiner in r192476:
http://reviews.llvm.org/rL192476

...but here I'm pulling it one level higher, so it can be used in all DAG-related code.

The test changes confirm that a MinSize attribute alone can now trigger size optimizations (OptSize does not also have to be present).

If this looks ok, we can make a similar patch for machine-level passes.

Diff Detail

Event Timeline

spatel updated this revision to Diff 31145.Jul 31 2015, 11:42 AM
spatel retitled this revision from to cache OptSize and MinSize attributes in the DAG.
spatel updated this object.
spatel added reviewers: qcolombet, mkuper, hfinkel.
spatel added a subscriber: llvm-commits.
spatel updated this revision to Diff 31153.Jul 31 2015, 12:04 PM

Patch updated: there was a spot in X86ISelDAGToDAG that I had not updated to use the new method.

mkuper edited edge metadata.Aug 1 2015, 10:44 PM

Thanks, Sanjay.
LGTM, except that I'd prefer it to go in as two separate commits.

lib/CodeGen/SelectionDAG/SelectionDAG.cpp
942

Perhaps:

MinSize = F->hasFnAttribute(Attribute::MinSize);
OptForSize = MinSize || F->hasFnAttribute(Attribute::OptimizeForSize);

?

943

Actually, can we split this into two commits - one NFC for the caching, and one that actually changes the behavior?

Also, I don't think this || really belongs in the DAG - it ought to be just querying the Function or the MachineFunction, and MinSize should imply OptForSize on that level. Is that what you're aiming at?

spatel added inline comments.Aug 3 2015, 10:08 AM
lib/CodeGen/SelectionDAG/SelectionDAG.cpp
943

Yes - agree on both points. And if we have this interface/logic in the MachineFunction, then it probably obviates the need to cache these in the DAG entirely, so I'll most likely abandon this patch.

spatel abandoned this revision.Aug 4 2015, 8:25 AM

Abandoning - see D11734 for a better solution.