public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* PR79715: Special case strcpy/strncpy for dse
@ 2017-02-28 10:05 Prathamesh Kulkarni
  2017-02-28 10:19 ` Jakub Jelinek
  0 siblings, 1 reply; 10+ messages in thread
From: Prathamesh Kulkarni @ 2017-02-28 10:05 UTC (permalink / raw)
  To: gcc Patches, Richard Biener, Martin Sebor

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

Hi,
The attached patch adds special-casing for strcpy/strncpy to dse pass.
Bootstrapped+tested on x86_64-unknown-linux-gnu.
OK for GCC 8 ?

Thanks,
Prathamesh

[-- Attachment #2: pr79715-1.diff --]
[-- Type: text/plain, Size: 1869 bytes --]

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr79715.c b/gcc/testsuite/gcc.dg/tree-ssa/pr79715.c
new file mode 100644
index 0000000..1a832ca
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr79715.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-dse-details" } */
+
+void f(const char *s)
+{
+  unsigned n = __builtin_strlen (s) + 1;
+  char *p = __builtin_malloc (n);
+  __builtin_strcpy (p, s);
+  __builtin_free (p);
+}
+
+/* { dg-final { scan-tree-dump "Deleted dead call: __builtin_strcpy" "dse1" } } */
diff --git a/gcc/tree-ssa-dse.c b/gcc/tree-ssa-dse.c
index 53feaf3..6d3c3c3 100644
--- a/gcc/tree-ssa-dse.c
+++ b/gcc/tree-ssa-dse.c
@@ -97,6 +97,8 @@ initialize_ao_ref_for_dse (gimple *stmt, ao_ref *write)
 	  case BUILT_IN_MEMCPY:
 	  case BUILT_IN_MEMMOVE:
 	  case BUILT_IN_MEMSET:
+	  case BUILT_IN_STRNCPY:
+	  case BUILT_IN_STRCPY:
 	    {
 	      tree size = NULL_TREE;
 	      if (gimple_call_num_args (stmt) == 3)
@@ -395,6 +397,8 @@ maybe_trim_memstar_call (ao_ref *ref, sbitmap live, gimple *stmt)
     {
     case BUILT_IN_MEMCPY:
     case BUILT_IN_MEMMOVE:
+    case BUILT_IN_STRNCPY:
+    case BUILT_IN_STRCPY:
       {
 	int head_trim, tail_trim;
 	compute_trims (ref, live, &head_trim, &tail_trim, stmt);
@@ -713,6 +717,7 @@ dse_dom_walker::dse_optimize_stmt (gimple_stmt_iterator *gsi)
 	  case BUILT_IN_MEMCPY:
 	  case BUILT_IN_MEMMOVE:
 	  case BUILT_IN_MEMSET:
+	  case BUILT_IN_STRNCPY:
 	    {
 	      /* Occasionally calls with an explicit length of zero
 		 show up in the IL.  It's pointless to do analysis
@@ -723,7 +728,10 @@ dse_dom_walker::dse_optimize_stmt (gimple_stmt_iterator *gsi)
 		  delete_dead_call (gsi);
 		  return;
 		}
-
+	    }
+	  /* fallthru  */
+	  case BUILT_IN_STRCPY:
+	    {
 	      gimple *use_stmt;
 	      enum dse_store_status store_status;
 	      m_byte_tracking_enabled

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2017-05-01 21:10 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-28 10:05 PR79715: Special case strcpy/strncpy for dse Prathamesh Kulkarni
2017-02-28 10:19 ` Jakub Jelinek
2017-02-28 13:13   ` Prathamesh Kulkarni
2017-02-28 18:00     ` Jeff Law
2017-03-01  7:54       ` Richard Biener
2017-04-24  9:36         ` Prathamesh Kulkarni
2017-04-28 18:35           ` Jeff Law
2017-05-01 18:17             ` Richard Biener
2017-05-01 21:10               ` Jeff Law
2017-05-01 17:06           ` Martin Sebor

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).