public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeff Law <law@redhat.com>
To: gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [RFA] [PATCH 4/4] Ignore reads of "dead" memory locations in DSE
Date: Fri, 16 Dec 2016 02:16:00 -0000	[thread overview]
Message-ID: <8d9f9db6-d697-0d3e-909c-fff9fcb2fadb@redhat.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 771 bytes --]

This is the final patch in the kit to improve our DSE implementation.

It's based on a observation by Richi.  Namely that a read from bytes of 
memory that are dead can be ignored.  By ignoring such reads we can 
sometimes find additional stores that allow us to either eliminate or 
trim an earlier store more aggressively.

This only hit (by hit I mean the ability to ignore resulted in finding a 
full or partially dead store that we didn't otherwise find) once during 
a bootstrap, but does hit often in the libstdc++ testsuite.

There's nothing in the BZ database on this issue and I can't reasonably 
call it a bugfix.  I wouldn't lose sleep if this deferred to gcc-8.

Bootstrapped and regression tested on x86-64-linux-gnu.  OK for the 
trunk or defer to gcc-8?


[-- Attachment #2: P4 --]
[-- Type: text/plain, Size: 2840 bytes --]

	* tree-ssa-dse.c (dse_possible_dead_store_p): Ignore reads of dead
	bytes.

	*  testsuite/gcc.dg/tree-ssa/ssa-dse-XX.c: New test.

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/dse-2.c b/gcc/testsuite/gcc.dg/tree-ssa/dse-2.c
new file mode 100644
index 0000000..6605dfe
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/dse-2.c
@@ -0,0 +1,33 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-dse1-details" } */
+
+enum constraint_expr_type
+{
+  SCALAR, DEREF, ADDRESSOF
+};
+typedef struct constraint_expr
+{
+  enum constraint_expr_type type;
+  unsigned int var;
+  long offset;
+} constraint_expr ;
+typedef struct constraint
+{
+  struct constraint_expr lhs;
+  struct constraint_expr rhs;
+} constraint;
+static _Bool
+constraint_expr_equal (struct constraint_expr x, struct constraint_expr y)
+{
+  return x.type == y.type && x.var == y.var && x.offset == y.offset;
+}
+
+_Bool
+constraint_equal (struct constraint a, struct constraint b)
+{
+  return constraint_expr_equal (a.lhs, b.lhs)
+    && constraint_expr_equal (a.rhs, b.rhs);
+}
+
+/* { dg-final { scan-tree-dump-times "Deleted dead store" 2 "dse1" } } */
+
diff --git a/gcc/tree-ssa-dse.c b/gcc/tree-ssa-dse.c
index a868f11..1482c7f 100644
--- a/gcc/tree-ssa-dse.c
+++ b/gcc/tree-ssa-dse.c
@@ -439,6 +439,50 @@ dse_possible_dead_store_p (ao_ref *ref, gimple *stmt, gimple **use_stmt)
 	  /* If the statement is a use the store is not dead.  */
 	  else if (ref_maybe_used_by_stmt_p (use_stmt, ref))
 	    {
+	      /* Handle common cases where we can easily build a ao_ref
+		 structure for USE_STMT and in doing so we find that the
+		 references hit non-live bytes and thus can be ignored.  */
+	      if (live_bytes)
+		{
+		  if (is_gimple_assign (use_stmt))
+		    {
+		      /* Other cases were noted as non-aliasing by
+			 the call to ref_maybe_used_by_stmt_p.  */
+		      ao_ref use_ref;
+		      ao_ref_init (&use_ref, gimple_assign_rhs1 (use_stmt));
+		      if (valid_ao_ref_for_dse (&use_ref)
+			  && use_ref.base == ref->base
+			  && use_ref.size == use_ref.max_size)
+			{
+			  size_t start = use_ref.offset / BITS_PER_UNIT;
+			  size_t end = use_ref.size / BITS_PER_UNIT;
+			  bitmap z = BITMAP_ALLOC (NULL);
+			  bitmap_set_range (z, start, end);
+			  bitmap_and_into (z, live_bytes);
+			  if (bitmap_empty_p (z))
+			    {
+			      BITMAP_FREE (z);
+			      if (gimple_vdef (use_stmt))
+				{
+				  /* If we have already seen a store and
+				     this is also a store, then we have to
+				     fail.  */
+				  if (temp)
+				    {
+				      fail = true;
+				      BREAK_FROM_IMM_USE_STMT (ui);
+				    }
+
+				  /* Otherwise walk through this store.  */
+				  temp = use_stmt;
+				}
+			      continue;
+			    }
+			  BITMAP_FREE (z);
+			}
+		    }
+		}
+
 	      fail = true;
 	      BREAK_FROM_IMM_USE_STMT (ui);
 	    }

             reply	other threads:[~2016-12-16  1:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-16  2:16 Jeff Law [this message]
2016-12-22 11:00 Jeff Law
2017-01-04 13:50 ` Richard Biener
2017-09-06 22:19   ` Jeff Law
2017-10-02 16:36     ` Richard Sandiford
2017-10-05 19:40     ` Christophe Lyon
2017-10-09 11:12       ` Christophe Lyon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8d9f9db6-d697-0d3e-909c-fff9fcb2fadb@redhat.com \
    --to=law@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).