On June 30, 2016 7:38:05 PM GMT+02:00, Jakub Jelinek <ja...@redhat.com> wrote:
>Hi!
>
>I thought for ADDR_EXPRs we couldn't reach this, but we actually can,
>when
>there is an SSA_NAME with POINTER_PLUS_EXPR of ADDR_EXPR and constant.
>
>The following patch handles it.
>
>Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

Thanks,
Richard.

>2016-06-30  Jakub Jelinek  <ja...@redhat.com>
>
>       PR tree-optimization/71707
>       * tree-ssa-strlen.c (get_stridx_plus_constant): Handle already present
>       strinfo even for ADDR_EXPR ptr.
>
>       * gcc.dg/strlenopt-29.c: New test.
>
>--- gcc/tree-ssa-strlen.c.jj   2016-06-29 16:10:27.000000000 +0200
>+++ gcc/tree-ssa-strlen.c      2016-06-30 10:28:30.605430361 +0200
>@@ -677,8 +677,14 @@ get_stridx_plus_constant (strinfo *bases
>       {
>         if (r == 0)
>           {
>-            gcc_assert (TREE_CODE (ptr) == SSA_NAME);
>-            ssa_ver_to_stridx[SSA_NAME_VERSION (ptr)] = si->idx;
>+            if (TREE_CODE (ptr) == SSA_NAME)
>+              ssa_ver_to_stridx[SSA_NAME_VERSION (ptr)] = si->idx;
>+            else
>+              {
>+                int *pidx = addr_stridxptr (TREE_OPERAND (ptr, 0));
>+                if (pidx != NULL && *pidx == 0)
>+                  *pidx = si->idx;
>+              }
>             return si->idx;
>           }
>         break;
>--- gcc/testsuite/gcc.dg/strlenopt-29.c.jj     2016-06-30
>10:36:34.673371348 +0200
>+++ gcc/testsuite/gcc.dg/strlenopt-29.c        2016-06-30 10:38:21.731032244
>+0200
>@@ -0,0 +1,27 @@
>+/* PR tree-optimization/71707 */
>+/* { dg-do run } */
>+/* { dg-options "-O2 -fdump-tree-strlen" } */
>+
>+#include "strlenopt.h"
>+
>+char a[32];
>+size_t b;
>+
>+__attribute__((noinline, noclone)) char *
>+foo (void)
>+{
>+  char *p = memcpy (a, "a", 2) + 1;
>+  memcpy (&a[1], "b", 2);
>+  b = strlen (a) + strlen (&a[1]) + strlen (p);
>+  return p;
>+}
>+
>+int
>+main ()
>+{
>+  if (foo () != &a[1] || b != 4)
>+    abort ();
>+  return 0;
>+}
>+
>+/* { dg-final { scan-tree-dump-times "strlen \\(" 0 "strlen" } } */
>
>       Jakub


Reply via email to