This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Don't invalidate string length cache when not needed
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Marek Polacek <polacek at redhat dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 16 May 2013 22:33:27 +0200
- Subject: Re: [PATCH] Don't invalidate string length cache when not needed
- References: <20130515165909 dot GD14240 at redhat dot com> <20130515172003 dot GZ1377 at tucnak dot redhat dot com> <20130516133140 dot GG14240 at redhat dot com> <20130516133847 dot GF1377 at tucnak dot redhat dot com> <20130516140744 dot GH14240 at redhat dot com> <20130516141827 dot GG1377 at tucnak dot redhat dot com> <20130516142819 dot GH1377 at tucnak dot redhat dot com> <20130516164403 dot GI14240 at redhat dot com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
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