This is an archive of the discontinued LLVM Phabricator instance.

[TLI] Optimize no-builtins attribute check (NFC)
AbandonedPublic

Authored by nikic on Apr 22 2020, 12:58 PM.

Details

Reviewers
tejohnson
wenlei
Summary

Looking up a string function attribute is expensive, because attributes are stored as a plain list (not a map), and functions tend to have a large number of attributes. As the TargetLibraryInfo constructor needs to scan over all attributes to check for no-builtin-* anyway, we can also integrate the no-builtins check in the same loop. D77632 will then be able to also check for veclib in the same loop, which should mitigate most of the negative impact of that change.

Here are the improvements to instructions retired with this change: http://llvm-compile-time-tracker.com/compare.php?from=b3f5472c2b9c8cf99239a9ac655555e9f0ba9e5d&to=b1eb5ae2f8bcdb888b8a0d7c0356fa10e6e51d6a&stat=instructions

Diff Detail

Event Timeline

nikic created this revision.Apr 22 2020, 12:58 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 22 2020, 12:58 PM
arsenm added a subscriber: arsenm.Apr 22 2020, 1:21 PM

I do think we need to do something about string attributes in general

tejohnson accepted this revision.Apr 22 2020, 1:35 PM

Nice find/fix. Lgtm

include/llvm/Analysis/TargetLibraryInfo.h
236

You could break out of the loop in this case. Although that won't work any more if this loop is extended to look for veclib unfortunately.

This revision is now accepted and ready to land.Apr 22 2020, 1:35 PM
wenlei accepted this revision.Apr 22 2020, 11:12 PM

Thanks for fix. On the other hand, if hasFnAttribute is so expensive to the point that we need to refrain from using it, that's probably an indication that we should try to speed up hasFnAttribute.

because attributes are stored as a plain list (not a map)

And sounds like there's opportunity for a nice speed up.

nikic marked an inline comment as done.Apr 25 2020, 4:17 AM

I've put up D78859 for the alternative suggestion to make string attribute lookup cheaper in general. This turned out to be super simple to implement and makes for a major compile-time saving (~3%), so that's probably better than this patch :)

nikic abandoned this revision.Apr 26 2020, 12:51 AM

Abandoning this one, as I expect this to be cheap enough after D78859.