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
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.