This is an archive of the discontinued LLVM Phabricator instance.

[TTI] Enable analysis of clib functions in getIntrinsicCosts. NFCI.
ClosedPublic

Authored by SjoerdMeijer on Mar 6 2019, 12:58 AM.

Details

Summary

This is addressing the issue that we're not modeling the cost of clib functions
in TTI::getIntrinsicCosts and thus we're basically addressing this fixme:

    
// FIXME: This is wrong for libc intrinsics.

To enable analysis of clib functions, we not only need an intrinsic ID and
formal arguments, but also the actual user of that function so that we can e.g.
look at alignment and values of arguments. So, this is the initial plumbing to
pass the user of an intrinsinsic on to getCallCosts, which queries
getIntrinsicCosts.

Diff Detail

Event Timeline

SjoerdMeijer created this revision.Mar 6 2019, 12:58 AM
RKSimon added inline comments.Mar 7 2019, 8:26 AM
include/llvm/Analysis/TargetTransformInfo.h
817

Why do we need to provide individual cost functions like this? Isn't that what getCallCost/getIntrinsicCost are there for?

include/llvm/Analysis/TargetTransformInfoImpl.h
26

include ordering - clang-format should fix this

SjoerdMeijer added inline comments.Mar 7 2019, 8:50 AM
include/llvm/Analysis/TargetTransformInfo.h
817

I thought a separate function would be good so that targets can override it and do their target dependent decision making there, like e.g. checking if source/destinations types are legal or not. But I agree it is probably not strictly necessary, as querying DataLayout here would also be possible.

include/llvm/Analysis/TargetTransformInfoImpl.h
26

Cheers, will look at that.

samparker added inline comments.Mar 7 2019, 8:59 AM
include/llvm/Analysis/TargetTransformInfo.h
211

Can these be const pointers?

1507

Since you're implementing this, we should have a test.

RKSimon added inline comments.Mar 7 2019, 11:55 AM
include/llvm/Analysis/TargetTransformInfo.h
211

+1

817

Would it be possible to remove the memcpy change from this patch so its just about adding the User* argument?

SjoerdMeijer edited the summary of this revision. (Show Details)

Thanks for the reviews!

  • removed the memcpy business from this patch.
  • and we do have more const pointers now.
dmgreen added inline comments.Mar 8 2019, 1:13 AM
include/llvm/Analysis/TargetTransformInfo.h
217

I may be missing something.. but where is this one defined? The changes in TargetTransformInfo.cpp only have two getCallCost functions.

SjoerdMeijer marked an inline comment as done.Mar 8 2019, 2:28 AM
SjoerdMeijer added inline comments.
include/llvm/Analysis/TargetTransformInfo.h
217

Thanks for spotting this one.
The story here is indeed that we don't have a definition for this one, which is of course odd. I propose changing it here anyway to also have a const User *U argument, just for consistency reasons. If we would like to remove this declaration, then we can do that in separate patch. If (downstream) users have a problem with that, this patch is unaffected and I don't need to change it again.

Just for your information, how I would like to use this patch: I've uploaded work-in-progress patch D59129. This is using getInstructionCost to decide if alloca's need to be lowered. The missing piece is the memcpy instruction cost decision making that I stripped out (the intial plumbing) from this patch, that I will start working on now.

samparker accepted this revision.Mar 11 2019, 4:08 AM

This looks okay to me now.

This revision is now accepted and ready to land.Mar 11 2019, 4:08 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMar 12 2019, 2:50 AM