This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Don't invalidate string length cache when not needed


On Thu, May 16, 2013 at 06:44:03PM +0200, Marek Polacek wrote:
> --- gcc/tree-ssa-strlen.c.mp	2013-05-15 14:11:20.079707492 +0200
> +++ gcc/tree-ssa-strlen.c	2013-05-16 17:57:33.963150006 +0200
> @@ -1693,8 +1693,10 @@ handle_char_store (gimple_stmt_iterator
>  		}
>  	      else
>  		{
> -		  si->writable = true;
> -		  si->dont_invalidate = true;
> +		  /* The string might be e.g. in the .rodata section.  */
> +		  si->writable = false;

No, this really should be si->writable = true; (and comment not needed).
Ok with that change.

The thing is, while the string might not be known to be writable before,
i.e. we can't optimize away this store, because supposedly it should
trap, if we notice e.g. another write to the same location (writing zero
there again), we can optimize that other write already, because we know
that this store stored there something.

> +#include "strlenopt.h"
> +
> +__attribute__((noinline, noclone)) size_t
> +fn1 (char *p, const char *r)
> +{
> +  size_t len1 = __builtin_strlen (r);
> +  char *q = __builtin_strchr (p, '\0');
> +  *q = '\0';
> +  return len1 - __builtin_strlen (r); // This strlen should be optimized into len1.

With strlenopt.h include you can avoid using __builtin_ prefixes, all the
builtins needed are prototyped in that header.

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]