re PR tree-optimization/85757 (tree optimizers fail to fully clean up fixed-size...
authorRichard Biener <rguenther@suse.de>
Thu, 17 May 2018 06:57:45 +0000 (06:57 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Thu, 17 May 2018 06:57:45 +0000 (06:57 +0000)
2018-05-17  Richard Biener  <rguenther@suse.de>

PR tree-optimization/85757
* tree-ssa-dse.c (dse_classify_store): Record a PHI def and
remove defs that only feed that PHI from further processing.

* gcc.dg/tree-ssa/ssa-dse-34.c: New testcase.

From-SVN: r260306

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-34.c [new file with mode: 0644]
gcc/tree-ssa-dse.c

index 700ac4a37078cfe34c51d7c2e08616f0cccfcd33..23d13acc522ab40524c010173530beabaa02f6ce 100644 (file)
@@ -1,3 +1,9 @@
+2018-05-17  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/85757
+       * tree-ssa-dse.c (dse_classify_store): Record a PHI def and
+       remove defs that only feed that PHI from further processing.
+
 2018-05-16  Jim Wilson  <jimw@sifive.com>
 
        * config/riscv/riscv.md (<optab>si3_mask, <optab>si3_mask_1): Prepend
index 9eab3adfa40fc93ffc41b181acba0c677d30b90a..f52a555a12282aa574214b2c3279eb5fb86a92da 100644 (file)
@@ -1,3 +1,8 @@
+2018-05-17  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/85757
+       * gcc.dg/tree-ssa/ssa-dse-34.c: New testcase.
+
 2018-05-16  Marek Polacek  <polacek@redhat.com>
 
        PR c++/85363
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-34.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-34.c
new file mode 100644 (file)
index 0000000..3016dfe
--- /dev/null
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-dse1-details" } */
+
+void f(int n, char *p0, char *p1, char *p2, char *o)
+{
+  int t0, t1;
+  __builtin_memcpy(&t0, p0, 1);
+  __builtin_memcpy(&t1, p1, 1);
+  if (n==3)
+    __builtin_memcpy(o+2, p2, 1);
+  __builtin_memcpy(o+0, &t0, 1);
+  __builtin_memcpy(o+1, &t1, 1);
+}
+
+/* { dg-final { scan-tree-dump-times "Deleted dead store" 2 "dse1" } } */
index 32a25b9eb1ef3b54517276d9c1a2c8efdb37d8ac..589cfef5df55d472e618da22f50d5ca5be1f4c08 100644 (file)
@@ -577,6 +577,7 @@ dse_classify_store (ao_ref *ref, gimple *stmt,
       else
        defvar = gimple_vdef (temp);
       auto_vec<gimple *, 10> defs;
+      gimple *phi_def = NULL;
       FOR_EACH_IMM_USE_STMT (use_stmt, ui, defvar)
        {
          /* Limit stmt walking.  */
@@ -600,7 +601,10 @@ dse_classify_store (ao_ref *ref, gimple *stmt,
                 processing.  */
              if (!bitmap_bit_p (visited,
                                 SSA_NAME_VERSION (PHI_RESULT (use_stmt))))
-               defs.safe_push (use_stmt);
+               {
+                 defs.safe_push (use_stmt);
+                 phi_def = use_stmt;
+               }
            }
          /* If the statement is a use the store is not dead.  */
          else if (ref_maybe_used_by_stmt_p (use_stmt, ref))
@@ -657,15 +661,31 @@ dse_classify_store (ao_ref *ref, gimple *stmt,
          return DSE_STORE_DEAD;
        }
 
-      /* Process defs and remove paths starting with a kill from further
-         processing.  */
+      /* Process defs and remove those we need not process further.  */
       for (unsigned i = 0; i < defs.length (); ++i)
-       if (stmt_kills_ref_p (defs[i], ref))
-         {
-           if (by_clobber_p && !gimple_clobber_p (defs[i]))
-             *by_clobber_p = false;
+       {
+         gimple *def = defs[i];
+         gimple *use_stmt;
+         use_operand_p use_p;
+         /* If the path to check starts with a kill we do not need to
+            process it further.
+            ???  With byte tracking we need only kill the bytes currently
+            live.  */
+         if (stmt_kills_ref_p (def, ref))
+           {
+             if (by_clobber_p && !gimple_clobber_p (def))
+               *by_clobber_p = false;
+             defs.unordered_remove (i);
+           }
+         /* In addition to kills we can remove defs whose only use
+            is another def in defs.  That can only ever be PHIs of which
+            we track a single for simplicity reasons (we fail for multiple
+            PHIs anyways).  */
+         else if (gimple_code (def) != GIMPLE_PHI
+                  && single_imm_use (gimple_vdef (def), &use_p, &use_stmt)
+                  && use_stmt == phi_def)
            defs.unordered_remove (i);
-         }
+       }
 
       /* If all defs kill the ref we are done.  */
       if (defs.is_empty ())