Patch: speed up compiler a little bit by optimizing lookup_attribute() and is_attribute_p()

Dimitrios Apostolou jimis@gmx.net
Tue Jun 21 12:23:00 GMT 2011


FWIW I think that most of the speedup is due to inlining 
lookup_attribute(). I got almost the same by applying only the attached 
very simple patch, since strlen() was called too often (according to the 
profile at [1]). I used the always_inline attribute to avoid using a 
macro.

I was going to send it together with some other changes I'm trying and 
after proper measurements. Anyway, better late than ever. Thanks to 
Christophe Jaillet (CC'd) for pointing it to me.


Thanks,
Dimitris


[1] http://gcc.gnu.org/wiki/OptimisingGCC




On Tue, 21 Jun 2011, Richard Guenther wrote:

> On Tue, Jun 21, 2011 at 12:17 PM, Nicola Pero
> <nicola.pero@meta-innovation.com> wrote:
>>>> This patch speeds up the C/C++/ObjC/ObjC++ compiler a little bit by optimizing
>>>> lookup_attribute() and is_attribute_p().  The main change is that these functions
>>>> are now inline.
>>>
>>> I don't think this is a good idea.
>>
>> Can you explain why ?  You never do in your response :-)
>>
>> I'm guessing it's because you think the inline functions are too big and that's
>> counter-productive ?
>
> Yes.
>
>>> For this case I'd factor out the NULL attribute list check into an
>>> inline function and keeping the non-NULL attribute list pieces out-of-line.
>>
>> Ok ... so is this what you'd like - the common, hot case in the inline function,
>> and the less common, cold case in the out-of-line one ? :-)
>
> Right.
>
>> That makes sense - I'll try that out tonight (it takes a few hours to run all
>> the benchmarks). ;-)
>
> Thanks.
>
>>
>>> Does it work for all languages?  And yes, I agree it would be nice to
>>> canonicalize to the form without _s even in the attribute lists itself.
>>> Or go one step further - do not store an identifier but an enum as we
>>> in fact only ever insert known attributes into the list (which should
>>> be a VEC instead, possibly even sorted to allow binary search).
>>
>> Sure ... one step at a time. :-)
>
> Of course ;)
>
> Richard.
>
>> Thanks
>>
>>
>
-------------- next part --------------
--- gcc-4.6.0.orig/gcc/tree.c	2011-03-14 14:20:48.000000000 +0200
+++ gcc-4.6.0-mine/gcc/tree.c	2011-06-21 12:57:00.000000000 +0300
@@ -5230,10 +5230,9 @@ is_attribute_p (const char *attr, const_
    be passed back in if further occurrences are wanted.  */
 
 tree
-lookup_attribute (const char *attr_name, tree list)
+lookup_attribute_len (const char *attr_name, size_t attr_len, tree list)
 {
   tree l;
-  size_t attr_len = strlen (attr_name);
 
   for (l = list; l; l = TREE_CHAIN (l))
     {

--- gcc-4.6.0.orig/gcc/tree.h	2011-03-12 00:38:58.000000000 +0200
+++ gcc-4.6.0-mine/gcc/tree.h	2011-06-21 13:13:02.000000000 +0300
@@ -4369,7 +4369,16 @@ extern int is_attribute_p (const char *,
 /* Given an attribute name and a list of attributes, return the list element
    of the attribute or NULL_TREE if not found.  */
 
-extern tree lookup_attribute (const char *, tree);
+extern tree lookup_attribute_len (const char *, size_t, tree);
+
+/* implemented as inline so that the compiler optimises away the strlen() for
+   known strings*/
+static __attribute__((__always_inline__)) tree
+lookup_attribute (const char *attr_name, tree list)
+{
+  return lookup_attribute_len(attr_name, strlen (attr_name), list);
+}
+
 
 /* Remove any instances of attribute ATTR_NAME in LIST and return the
    modified list.  */


More information about the Gcc-patches mailing list