re PR tree-optimization/83518 (Missing optimization: useless instructions should...
authorRichard Biener <rguenther@suse.de>
Tue, 23 Jul 2019 10:00:24 +0000 (10:00 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 23 Jul 2019 10:00:24 +0000 (10:00 +0000)
2019-07-23  Richard Biener  <rguenther@suse.de>

PR tree-optimization/83518
* tree-ssa-sccvn.c (vn_reference_lookup_3): Handle aggregate
init from a constant even when partial defs are already recorded.

c/
* gimple-parser.c (c_parser_parse_gimple_body): When we have
a CFG also rebuild cgraph edges.

* gcc.dg/tree-ssa/ssa-fre-79.c: New testcase.

From-SVN: r273732

gcc/ChangeLog
gcc/c/ChangeLog
gcc/c/gimple-parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-79.c [new file with mode: 0644]
gcc/tree-ssa-sccvn.c

index fb9b0ff8db262e4d2d0b42c7142f87eac6064c86..1add332e0fe98793f37d72ead013b4254e7eca85 100644 (file)
@@ -1,3 +1,9 @@
+2019-07-23  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/83518
+       * tree-ssa-sccvn.c (vn_reference_lookup_3): Handle aggregate
+       init from a constant even when partial defs are already recorded.
+
 2019-07-23  Jan Hubicka  <hubicka@ucw.cz>
 
        * i386-common.c: Use PROCESSOR_ZNVER2 scheduler for znver2.
index a75f0d80955012e59a497110bd4d640810c91f5b..0bb1d4c1c325890f8fe0d3c2ef466ba149b15c95 100644 (file)
@@ -1,3 +1,9 @@
+2019-07-23  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/83518
+       * gimple-parser.c (c_parser_parse_gimple_body): When we have
+       a CFG also rebuild cgraph edges.
+
 2019-07-20  Jakub Jelinek  <jakub@redhat.com>
 
        * c-parser.c (c_parser_omp_clause_name): Handle bind clause.
index 4970ae1e9e086fb8aca2c533943ff3eb60fcca98..3f575992d327db9e589293631b9fc3626e661bae 100644 (file)
@@ -356,6 +356,8 @@ c_parser_parse_gimple_body (c_parser *cparser, char *gimple_pass,
       gcov_type t = PARAM_VALUE (PARAM_GIMPLE_FE_COMPUTED_HOT_BB_THRESHOLD);
       set_hot_bb_threshold (t);
       update_max_bb_count ();
+      cgraph_node::get_create (cfun->decl);
+      cgraph_edge::rebuild_edges ();
     }
   dump_function (TDI_gimple, current_function_decl);
 }
index d5efd503cb80b5f8d077e101f4b9bf21bf1b0f01..8e6b02668fbbfaf469dacc86e839059a619c6bf7 100644 (file)
@@ -1,3 +1,8 @@
+2019-07-23  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/83518
+       * gcc.dg/tree-ssa/ssa-fre-79.c: New testcase.
+
 2019-07-23  Ed Schonberg  <schonberg@adacore.com>
 
        * gnat.dg/task4.adb: New testcase.
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-79.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-79.c
new file mode 100644 (file)
index 0000000..83aef9a
--- /dev/null
@@ -0,0 +1,29 @@
+/* { dg-do run } */
+/* { dg-options "-O -fgimple -fdump-tree-fre1" } */
+
+struct S { char a[4]; };
+const struct S cs = { 1, 2, 3, 4 };
+
+int __GIMPLE(ssa,startwith("fre"))
+main ()
+{
+  struct S s;
+  short _1;
+
+  __BB(2):
+  s = cs;
+  s.a[1] = _Literal (char) 3;
+  _1 = __MEM <short, 1> (&s + 1);
+  if (_1 != _Literal (short) 0x303)
+    goto __BB3;
+  else
+    goto __BB4;
+
+  __BB(3):
+  __builtin_abort ();
+
+  __BB(4):
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump-not "abort" "fre1" } } */
index cab2460a30894c6bb8e19f98eb80a092c561c145..9369c36f50eba2b8cddac32ae71433c01ea3f5f8 100644 (file)
@@ -2702,9 +2702,7 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_,
           && gimple_assign_single_p (def_stmt)
           && (DECL_P (gimple_assign_rhs1 (def_stmt))
               || TREE_CODE (gimple_assign_rhs1 (def_stmt)) == MEM_REF
-              || handled_component_p (gimple_assign_rhs1 (def_stmt)))
-          /* Handling this is more complicated, give up for now.  */
-          && data->partial_defs.is_empty ())
+              || handled_component_p (gimple_assign_rhs1 (def_stmt))))
     {
       tree base2;
       int i, j, k;
@@ -2808,8 +2806,30 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_,
       /* Try folding the new reference to a constant.  */
       tree val = fully_constant_vn_reference_p (vr);
       if (val)
-       return vn_reference_lookup_or_insert_for_pieces
-                (vuse, vr->set, vr->type, vr->operands, val);
+       {
+         if (data->partial_defs.is_empty ())
+           return vn_reference_lookup_or_insert_for_pieces
+               (vuse, vr->set, vr->type, vr->operands, val);
+         /* This is the only interesting case for partial-def handling
+            coming from targets that like to gimplify init-ctors as
+            aggregate copies from constant data like aarch64 for
+            PR83518.  */
+         if (maxsize.is_constant (&maxsizei)
+             && known_eq (ref->size, maxsize))
+           {
+             pd_data pd;
+             pd.rhs = val;
+             pd.offset = 0;
+             pd.size = maxsizei / BITS_PER_UNIT;
+             return data->push_partial_def (pd, vuse, maxsizei);
+           }
+       }
+
+      /* Continuing with partial defs isn't easily possible here, we
+         have to find a full def from further lookups from here.  Probably
+        not worth the special-casing everywhere.  */
+      if (!data->partial_defs.is_empty ())
+       return (void *)-1;
 
       /* Adjust *ref from the new operands.  */
       if (!ao_ref_init_from_vn_reference (&r, vr->set, vr->type, vr->operands))