Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.

Richard.

2018-09-03  Richard Biener  <rguent...@suse.de>

        PR tree-optimization/87197
        * tree-ssa-sccvn.c (vn_nary_build_or_lookup_1): Mark the new def
        visited.  CSE the VN_INFO hashtable lookup.

        * gcc.dg/torture/pr87197.c: New testcase.

Index: gcc/tree-ssa-sccvn.c
===================================================================
--- gcc/tree-ssa-sccvn.c        (revision 264049)
+++ gcc/tree-ssa-sccvn.c        (working copy)
@@ -1783,11 +1783,13 @@ vn_nary_build_or_lookup_1 (gimple_match_
       /* The expression is not yet available, value-number lhs to
         the new SSA_NAME we created.  */
       /* Initialize value-number information properly.  */
-      VN_INFO (result)->valnum = result;
-      VN_INFO (result)->value_id = get_next_value_id ();
+      vn_ssa_aux_t result_info = VN_INFO (result);
+      result_info->valnum = result;
+      result_info->value_id = get_next_value_id ();
+      result_info->visited = 1;
       gimple_seq_add_stmt_without_update (&VN_INFO (result)->expr,
                                          new_stmt);
-      VN_INFO (result)->needs_insertion = true;
+      result_info->needs_insertion = true;
       /* ???  PRE phi-translation inserts NARYs without corresponding
          SSA name result.  Re-use those but set their result according
         to the stmt we just built.  */
@@ -1810,7 +1812,7 @@ vn_nary_build_or_lookup_1 (gimple_match_
          unsigned int length = vn_nary_length_from_stmt (new_stmt);
          vn_nary_op_t vno1
            = alloc_vn_nary_op_noinit (length, &vn_tables_insert_obstack);
-         vno1->value_id = VN_INFO (result)->value_id;
+         vno1->value_id = result_info->value_id;
          vno1->length = length;
          vno1->predicated_values = 0;
          vno1->u.result = result;
Index: gcc/testsuite/gcc.dg/torture/pr87197.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/pr87197.c      (nonexistent)
+++ gcc/testsuite/gcc.dg/torture/pr87197.c      (working copy)
@@ -0,0 +1,35 @@
+/* { dg-do compile } */
+
+int a, c, e, f, g;
+void
+h (int i)
+{
+  a = i;
+}
+void
+j (char *i, long k)
+{
+  while (k--)
+    c = *i++;
+}
+void
+l (unsigned char *i, long k)
+{
+  unsigned char *b = i + k;
+  while (i < b)
+    {
+      h (*i);
+      i++;
+    }
+}
+void
+m ()
+{
+  while (e)
+    {
+      float d = g;
+      l ((char *) &d, sizeof (g));
+      if (f)
+       j ((char *) &d, sizeof (g));
+    }
+}

Reply via email to