public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-5324] Use modref summaries for byte-wise dead store elimination.
@ 2021-11-16 22:03 Jan Hubicka
  0 siblings, 0 replies; only message in thread
From: Jan Hubicka @ 2021-11-16 22:03 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:6dc90c4dbb6f9589dea9c670c3468496bb207de5

commit r12-5324-g6dc90c4dbb6f9589dea9c670c3468496bb207de5
Author: Jan Hubicka <jh@suse.cz>
Date:   Tue Nov 16 23:01:28 2021 +0100

    Use modref summaries for byte-wise dead store elimination.
    
    gcc/ChangeLog:
    
            * ipa-modref.c (get_modref_function_summary): Declare.
            * ipa-modref.h (get_modref_function_summary): New function.
            * tree-ssa-dse.c (clear_live_bytes_for_ref): Break out from ...
            (clear_bytes_written_by): ... here; also clear memory killed by
            calls.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.dg/tree-ssa/modref-dse-4.c: New test.

Diff:
---
 gcc/ipa-modref.c                             | 22 ++++++++++++++
 gcc/ipa-modref.h                             |  1 +
 gcc/testsuite/gcc.dg/tree-ssa/modref-dse-4.c | 26 +++++++++++++++++
 gcc/tree-ssa-dse.c                           | 43 +++++++++++++++++++++-------
 4 files changed, 81 insertions(+), 11 deletions(-)

diff --git a/gcc/ipa-modref.c b/gcc/ipa-modref.c
index 57834303290..a70575bc807 100644
--- a/gcc/ipa-modref.c
+++ b/gcc/ipa-modref.c
@@ -740,6 +740,28 @@ get_modref_function_summary (cgraph_node *func)
   return r;
 }
 
+/* Get function summary for CALL if it exists, return NULL otherwise.
+   If non-null set interposed to indicate whether function may not
+   bind to current def.  In this case sometimes loads from function
+   needs to be ignored.  */
+
+modref_summary *
+get_modref_function_summary (gcall *call, bool *interposed)
+{
+  tree callee = gimple_call_fndecl (call);
+  if (!callee)
+    return NULL;
+  struct cgraph_node *node = cgraph_node::get (callee);
+  if (!node)
+    return NULL;
+  modref_summary *r = get_modref_function_summary (node);
+  if (interposed && r)
+    *interposed = r->calls_interposable
+	    	  || !node->binds_to_current_def_p ();
+  return r;
+}
+
+
 namespace {
 
 /* Construct modref_access_node from REF.  */
diff --git a/gcc/ipa-modref.h b/gcc/ipa-modref.h
index 4eb696d086a..f868eb6de07 100644
--- a/gcc/ipa-modref.h
+++ b/gcc/ipa-modref.h
@@ -70,6 +70,7 @@ struct GTY(()) modref_summary
 };
 
 modref_summary *get_modref_function_summary (cgraph_node *func);
+modref_summary *get_modref_function_summary (gcall *call, bool *interposed);
 void ipa_modref_c_finalize ();
 void ipa_merge_modref_summary_after_inlining (cgraph_edge *e);
 
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/modref-dse-4.c b/gcc/testsuite/gcc.dg/tree-ssa/modref-dse-4.c
new file mode 100644
index 00000000000..81aa7dc587c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/modref-dse-4.c
@@ -0,0 +1,26 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-dse2-details"  } */
+struct a {int a,b,c;};
+__attribute__ ((noinline))
+void
+kill_me (struct a *a)
+{
+  a->a=0;
+  a->b=0;
+  a->c=0;
+}
+__attribute__ ((noinline))
+void
+my_pleasure (struct a *a)
+{
+  a->a=1;
+  a->c=2;
+}
+void
+set (struct a *a)
+{
+  kill_me (a);
+  my_pleasure (a);
+  a->b=1;
+}
+/* { dg-final { scan-tree-dump "Deleted dead store: kill_me" "dse2" } } */
diff --git a/gcc/tree-ssa-dse.c b/gcc/tree-ssa-dse.c
index ce0083a6dab..231e827c525 100644
--- a/gcc/tree-ssa-dse.c
+++ b/gcc/tree-ssa-dse.c
@@ -209,6 +209,26 @@ normalize_ref (ao_ref *copy, ao_ref *ref)
   return true;
 }
 
+/* Update LIVE_BYTES tracking REF for write to WRITE:
+   Verify we have the same base memory address, the write
+   has a known size and overlaps with REF.  */
+static void
+clear_live_bytes_for_ref (sbitmap live_bytes, ao_ref *ref, ao_ref write)
+{
+  HOST_WIDE_INT start, size;
+
+  if (valid_ao_ref_for_dse (&write)
+      && operand_equal_p (write.base, ref->base, OEP_ADDRESS_OF)
+      && known_eq (write.size, write.max_size)
+      /* normalize_ref modifies write and for that reason write is not
+	 passed by reference.  */
+      && normalize_ref (&write, ref)
+      && (write.offset - ref->offset).is_constant (&start)
+      && write.size.is_constant (&size))
+    bitmap_clear_range (live_bytes, start / BITS_PER_UNIT,
+			size / BITS_PER_UNIT);
+}
+
 /* Clear any bytes written by STMT from the bitmap LIVE_BYTES.  The base
    address written by STMT must match the one found in REF, which must
    have its base address previously initialized.
@@ -220,20 +240,21 @@ static void
 clear_bytes_written_by (sbitmap live_bytes, gimple *stmt, ao_ref *ref)
 {
   ao_ref write;
+
+  if (gcall *call = dyn_cast <gcall *> (stmt))
+    {
+      bool interposed;
+      modref_summary *summary = get_modref_function_summary (call, &interposed);
+
+      if (summary && !interposed)
+	for (auto kill : summary->kills)
+	  if (kill.get_ao_ref (as_a <gcall *> (stmt), &write))
+	    clear_live_bytes_for_ref (live_bytes, ref, write);
+    }
   if (!initialize_ao_ref_for_dse (stmt, &write))
     return;
 
-  /* Verify we have the same base memory address, the write
-     has a known size and overlaps with REF.  */
-  HOST_WIDE_INT start, size;
-  if (valid_ao_ref_for_dse (&write)
-      && operand_equal_p (write.base, ref->base, OEP_ADDRESS_OF)
-      && known_eq (write.size, write.max_size)
-      && normalize_ref (&write, ref)
-      && (write.offset - ref->offset).is_constant (&start)
-      && write.size.is_constant (&size))
-    bitmap_clear_range (live_bytes, start / BITS_PER_UNIT,
-			size / BITS_PER_UNIT);
+  clear_live_bytes_for_ref (live_bytes, ref, write);
 }
 
 /* REF is a memory write.  Extract relevant information from it and


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-11-16 22:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-16 22:03 [gcc r12-5324] Use modref summaries for byte-wise dead store elimination Jan Hubicka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).