re PR bootstrap/82916 (gcc miscompiled during stagefeedback (PGO bootstrap))
authorJakub Jelinek <jakub@redhat.com>
Fri, 10 Nov 2017 10:31:34 +0000 (11:31 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 10 Nov 2017 10:31:34 +0000 (11:31 +0100)
PR bootstrap/82916
* gimple-ssa-store-merging.c
(pass_store_merging::terminate_all_aliasing_chains): For
gimple_store_p stmts also call refs_output_dependent_p.

* gcc.dg/store_merging_2.c: Only expect 2 successful mergings instead
of 3.
* gcc.dg/pr82916.c: New test.

From-SVN: r254623

gcc/ChangeLog
gcc/gimple-ssa-store-merging.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr82916.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/store_merging_2.c

index f2de9142e6ae84dc86ee940429f7885ee5a8da6c..b82ce62fdff9f7a103a00071a499d56a5915deba 100644 (file)
@@ -1,5 +1,10 @@
 2017-11-10  Jakub Jelinek  <jakub@redhat.com>
 
+       PR bootstrap/82916
+       * gimple-ssa-store-merging.c
+       (pass_store_merging::terminate_all_aliasing_chains): For
+       gimple_store_p stmts also call refs_output_dependent_p.
+
        PR rtl-optimization/82913
        * compare-elim.c (try_merge_compare): Punt if def_insn is not
        single set.
index 421498beafb7093128c5ab3b73d5c47c5ba7a4bd..a5ee7aa3943c89091ae58feeca3d80034df79583 100644 (file)
@@ -947,6 +947,7 @@ pass_store_merging::terminate_all_aliasing_chains (imm_store_chain_info
   if (!gimple_vuse (stmt))
     return false;
 
+  tree store_lhs = gimple_store_p (stmt) ? gimple_get_lhs (stmt) : NULL_TREE;
   for (imm_store_chain_info *next = m_stores_head, *cur = next; cur; cur = next)
     {
       next = cur->next;
@@ -960,8 +961,10 @@ pass_store_merging::terminate_all_aliasing_chains (imm_store_chain_info
       unsigned int i;
       FOR_EACH_VEC_ELT (cur->m_store_info, i, info)
        {
-         if (ref_maybe_used_by_stmt_p (stmt, gimple_assign_lhs (info->stmt))
-             || stmt_may_clobber_ref_p (stmt, gimple_assign_lhs (info->stmt)))
+         tree lhs = gimple_assign_lhs (info->stmt);
+         if (ref_maybe_used_by_stmt_p (stmt, lhs)
+             || stmt_may_clobber_ref_p (stmt, lhs)
+             || (store_lhs && refs_output_dependent_p (store_lhs, lhs)))
            {
              if (dump_file && (dump_flags & TDF_DETAILS))
                {
index e83d3ce03dbbd9e8e3c66db04b973e80c7012339..a543e4fa404d6d8f72f23089ac977596748a37f9 100644 (file)
@@ -1,3 +1,10 @@
+2017-11-10  Jakub Jelinek  <jakub@redhat.com>
+
+       PR bootstrap/82916
+       * gcc.dg/store_merging_2.c: Only expect 2 successful mergings instead
+       of 3.
+       * gcc.dg/pr82916.c: New test.
+
 2017-11-10  Thomas Preud'homme  <thomas.preudhomme@arm.com>
 
        * lib/scanasm.exp (scan-assembler): Extract filename from testname used
diff --git a/gcc/testsuite/gcc.dg/pr82916.c b/gcc/testsuite/gcc.dg/pr82916.c
new file mode 100644 (file)
index 0000000..50e467f
--- /dev/null
@@ -0,0 +1,47 @@
+/* PR bootstrap/82916 */
+/* { dg-do run } */
+/* { dg-options "-O2 -fno-tree-dse" } */
+
+struct A { struct A *next; };
+struct C
+{
+  int *of;
+  struct C *parent, *prev, *next;
+  int depth;
+  int min;
+  struct C *min_occ;
+};
+
+__attribute__((noipa)) struct C *
+foo (int *node)
+{
+  struct A *p = __builtin_malloc (sizeof (struct C));
+  if (!p)
+    return 0;
+  p->next = 0;
+  /* Originally placement new.  */
+  struct C *nw = (struct C *)(void *)p;
+  nw->of = node;
+  nw->parent = 0;
+  nw->prev = 0;
+  nw->next = 0;
+  nw->depth = 0;
+  nw->min_occ = nw;
+  nw->min = 0;
+  return nw;
+}
+
+int
+main ()
+{
+  int o;
+  struct C *p = foo (&o);
+  if (p)
+    {
+      if (p->of != &o || p->parent || p->prev || p->next || p->depth
+         || p->min || p->min_occ != p)
+       __builtin_abort ();
+    }
+  __builtin_free (p);
+  return 0;
+}
index 19de3e2e0b53c70d533478366a5909df3a8cb373..8cd29f4243c15730224156ca4bb8dc233f615aef 100644 (file)
@@ -77,4 +77,4 @@ main (void)
   return 0;
 }
 
-/* { dg-final { scan-tree-dump-times "Merging successful" 3 "store-merging" } } */
+/* { dg-final { scan-tree-dump-times "Merging successful" 2 "store-merging" } } */