tree-ssa-dse.c (dse_optimize_redundant_stores): Improved check to catch more redundan...
authorMatthew Beliveau <mbelivea@redhat.com>
Tue, 20 Aug 2019 13:23:01 +0000 (13:23 +0000)
committerMatthew Beliveau <mbelivea@gcc.gnu.org>
Tue, 20 Aug 2019 13:23:01 +0000 (13:23 +0000)
2019-08-19  Matthew Beliveau  <mbelivea@redhat.com>

* tree-ssa-dse.c (dse_optimize_redundant_stores): Improved check to
catch more redundant zero initialization cases.
(dse_dom_walker::dse_optimize_stmt): Likewise.

From-SVN: r274749

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/redundant-assign-zero-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/redundant-assign-zero-2.c [new file with mode: 0644]
gcc/tree-ssa-dse.c

index 353429d0f17f60ca8c67c16fa5290d29ba8ae827..ecb7c06507cb83e3c8f53ba07667ca34b0a9660a 100644 (file)
@@ -1,3 +1,9 @@
+2019-08-20  Matthew Beliveau  <mbelivea@redhat.com>
+
+       * tree-ssa-dse.c (dse_optimize_redundant_stores): Improved check to
+       catch more redundant zero initialization cases.
+       (dse_dom_walker::dse_optimize_stmt): Likewise.
+
 2019-08-20  Richard Biener  <rguenther@suse.de>
 
        PR lto/91307
index 5316e07a434e647f52286cc033a033c60949f3fa..0512a60019d5e389a98db5e5b12119835ccc271c 100644 (file)
@@ -1,3 +1,8 @@
+2019-08-20  Matthew Beliveau  <mbelivea@redhat.com>
+
+       * gcc.dg/tree-ssa/redundant-assign-zero-1.c: New test.
+       * gcc.dg/tree-ssa/redundant-assign-zero-2.c: New test.
+
 2019-08-20  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/37242
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/redundant-assign-zero-1.c b/gcc/testsuite/gcc.dg/tree-ssa/redundant-assign-zero-1.c
new file mode 100644 (file)
index 0000000..b8d01d1
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-dse-details" } */
+
+void blah (char *);
+
+void bar ()
+{
+  char a[256] = "";
+  a[3] = 0; 
+  blah (a);
+}
+
+/* { dg-final { scan-tree-dump-times "Deleted redundant store" 1 "dse1"} } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/redundant-assign-zero-2.c b/gcc/testsuite/gcc.dg/tree-ssa/redundant-assign-zero-2.c
new file mode 100644 (file)
index 0000000..8cefa6f
--- /dev/null
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-dse-details" } */
+
+#include <string.h>
+
+void blahd (double *);
+
+void fubar ()
+{
+  double d;
+  double *x = &d;
+
+  memset (&d, 0 , sizeof d);
+  *x = 0.0;
+  blahd (x);
+}
+
+/* { dg-final { scan-tree-dump-times "Deleted redundant store" 1 "dse1"} } */
index 5b7c4fc6d1acd07ae3708350faf89ccc68a01a8d..ba67884a825cb8577fba5a893611443c153add77 100644 (file)
@@ -628,11 +628,8 @@ dse_optimize_redundant_stores (gimple *stmt)
       tree fndecl;
       if ((is_gimple_assign (use_stmt)
           && gimple_vdef (use_stmt)
-          && ((gimple_assign_rhs_code (use_stmt) == CONSTRUCTOR
-               && CONSTRUCTOR_NELTS (gimple_assign_rhs1 (use_stmt)) == 0
-               && !gimple_clobber_p (stmt))
-              || (gimple_assign_rhs_code (use_stmt) == INTEGER_CST
-                  && integer_zerop (gimple_assign_rhs1 (use_stmt)))))
+          && (gimple_assign_single_p (use_stmt)
+              && initializer_zerop (gimple_assign_rhs1 (use_stmt))))
          || (gimple_call_builtin_p (use_stmt, BUILT_IN_NORMAL)
              && (fndecl = gimple_call_fndecl (use_stmt)) != NULL
              && (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_MEMSET
@@ -1027,16 +1024,11 @@ dse_dom_walker::dse_optimize_stmt (gimple_stmt_iterator *gsi)
     {
       bool by_clobber_p = false;
 
-      /* First see if this store is a CONSTRUCTOR and if there
-        are subsequent CONSTRUCTOR stores which are totally
-        subsumed by this statement.  If so remove the subsequent
-        CONSTRUCTOR store.
-
-        This will tend to make fewer calls into memset with longer
-        arguments.  */
-      if (gimple_assign_rhs_code (stmt) == CONSTRUCTOR
-         && CONSTRUCTOR_NELTS (gimple_assign_rhs1 (stmt)) == 0
-         && !gimple_clobber_p (stmt))
+      /* Check if this statement stores zero to a memory location,
+        and if there is a subsequent store of zero to the same
+        memory location.  If so, remove the subsequent store.  */
+      if (gimple_assign_single_p (stmt)
+         && initializer_zerop (gimple_assign_rhs1 (stmt)))
        dse_optimize_redundant_stores (stmt);
 
       /* Self-assignments are zombies.  */