On Thu, May 16, 2013 at 04:07:44PM +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 16:03:50.373504796 +0200
> @@ -1717,6 +1717,27 @@ handle_char_store (gimple_stmt_iterator
>           si->endptr = ssaname;
>         si->dont_invalidate = true;
>       }
> +      /* If si->length is non-zero constant, we aren't overwriting '\0',
> +         and if we aren't storing '\0', we know that the length of the

The above line has 8 spaces instead of tab.  Also, please write
"that the length of the string and any other zero terminated string in
memory remains the same."

> +      string remains the same.  In that case we move to the next
> +      gimple statement and return to signal the caller that it shouldn't
> +      invalidate anything.  
> +      
> +      This is benefical for cases like:
> +      
> +      char p[] = "foobar";
> +      size_t len = strlen (p);
> +      p[0] = 'X'

Missing ; at the end of the above line.

> +      size_t len2 = strlen (p);

Also, you could make it clear that it affects any other strings.  Perhaps
        char p[20];
        void foo (char *q)
        {
          strcpy (p, "foobar");
          size_t len = strlen (p);      // This can be optimized into 6
          size_t len2 = strlen (q);     // This has to be computed
          p[0] = 'X';
          size_t len3 = strlen (p);     // This can be optimized into 6
          size_t len4 = strlen (q);     // This can be optimized into len2
          bar (len, len2, len3, len4);
        }
As q could point to p, if we didn't do what your patch does on the p[0] = 'X';
store, then we'd need to invalidate the recorded length of the q string.
Similarly if there is p[0] = '\0' or p[0] = var.

        Jakub

Reply via email to