re PR tree-optimization/78343 (Loop is not eliminated)
authorRichard Biener <rguenther@suse.de>
Fri, 25 Nov 2016 10:22:57 +0000 (10:22 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Fri, 25 Nov 2016 10:22:57 +0000 (10:22 +0000)
2016-11-24  Richard Biener  <rguenther@suse.de>

PR tree-optimization/78343
* passes.def: Add CD-DCE pass after loop splitting.
* tree-ssa-dce.c (find_obviously_necessary_stmts): Move
SCEV init/finalize ...
(perform_tree_ssa_dce): ... here.  Deal with being
executed inside the loop pipeline in aggressive mode.

* gcc.dg/tree-ssa/sccp-2.c: New testcase.
* gcc.dg/autopar/uns-outer-6.c: Adjust.
* gcc.dg/tree-ssa/20030808-1.c: Likewise.
* gcc.dg/tree-ssa/20040305-1.c: Likewise.
* gcc.dg/vect/pr38529.c: Likewise.

From-SVN: r242872

gcc/ChangeLog
gcc/passes.def
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/autopar/uns-outer-6.c
gcc/testsuite/gcc.dg/tree-ssa/20030808-1.c
gcc/testsuite/gcc.dg/tree-ssa/20040305-1.c
gcc/testsuite/gcc.dg/tree-ssa/sccp-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/pr38529.c
gcc/tree-ssa-dce.c

index 9e2c4ff0550324e6aae1a3df981b7b89d1601fce..9681566de997edbbfcfe789c134f83d94e27c021 100644 (file)
@@ -1,3 +1,12 @@
+2016-11-24  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/78343
+       * passes.def: Add CD-DCE pass after loop splitting.
+       * tree-ssa-dce.c (find_obviously_necessary_stmts): Move
+       SCEV init/finalize ...
+       (perform_tree_ssa_dce): ... here.  Deal with being
+       executed inside the loop pipeline in aggressive mode.
+
 2016-11-25  Thomas Preud'homme  <thomas.preudhomme@arm.com>
 
        * tree-ssa-math-opts.c (struct symbolic_number): Improve comment.
index b73000923b6453f209d1988ae00c19ddb3eb417d..1117b8b112b7461c415f3d4e3bd8792fb66e1d2a 100644 (file)
@@ -272,6 +272,9 @@ along with GCC; see the file COPYING3.  If not see
          NEXT_PASS (pass_tree_unswitch);
          NEXT_PASS (pass_scev_cprop);
          NEXT_PASS (pass_loop_split);
+         /* All unswitching, final value replacement and splitting can expose
+            empty loops.  Remove them now.  */
+         NEXT_PASS (pass_cd_dce);
          NEXT_PASS (pass_record_bounds);
          NEXT_PASS (pass_loop_distribution);
          NEXT_PASS (pass_copy_prop);
index 7e1aace6837097ebbb4dadb542472c7991375e9b..7072950f2366e44f6ff0b3e0f35cb4b02c4e73ac 100644 (file)
@@ -1,3 +1,12 @@
+2016-11-24  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/78343
+       * gcc.dg/tree-ssa/sccp-2.c: New testcase.
+       * gcc.dg/autopar/uns-outer-6.c: Adjust.
+       * gcc.dg/tree-ssa/20030808-1.c: Likewise.
+       * gcc.dg/tree-ssa/20040305-1.c: Likewise.
+       * gcc.dg/vect/pr38529.c: Likewise.
+
 2016-11-25  Thomas Preud'homme  <thomas.preudhomme@arm.com>
 
        PR tree-optimization/77673
index dc2870be8d470d17db0d26b798d2bf4163efc832..12bd3979202b103cb486bfcead3b9ab02f44aaa9 100644 (file)
@@ -25,7 +25,7 @@ parloop (int N)
   for (i = 0; i < N; i++)
     {
       for (j = 0; j < N; j++)
-       y[i]=x[i][j];
+       y[i] += x[i][j];
       sum += y[i];
     }
   g_sum = sum;
index 7cc5404561cbb0490e81a934ed41cc126b8be07d..cda86a7bbf1b88eda08c12d4043ef997fdda7639 100644 (file)
@@ -33,8 +33,8 @@ delete_dead_jumptables ()
 /* There should be no loads of ->code.  If any exist, then we failed to
    optimize away all the IF statements and the statements feeding
    their conditions.  */
-/* { dg-final { scan-tree-dump-times "->code" 0 "cddce2"} } */
+/* { dg-final { scan-tree-dump-times "->code" 0 "cddce3"} } */
    
 /* There should be no IF statements.  */
-/* { dg-final { scan-tree-dump-times "if " 0 "cddce2"} } */
+/* { dg-final { scan-tree-dump-times "if " 0 "cddce3"} } */
 
index 501e28cff54df34998a3c278238c2ee20d39ecfb..d1a9af833484d3e823eabc369e9039cbb1f5ac6a 100644 (file)
@@ -27,4 +27,4 @@ void foo(int edx, int eax)
 
 /* After cddce we should have two IF statements remaining as the other
    two tests can be threaded.  */
-/* { dg-final { scan-tree-dump-times "if " 2 "cddce2"} } */
+/* { dg-final { scan-tree-dump-times "if " 2 "cddce3"} } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/sccp-2.c b/gcc/testsuite/gcc.dg/tree-ssa/sccp-2.c
new file mode 100644 (file)
index 0000000..099b281
--- /dev/null
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+unsigned int
+test(unsigned int quant)
+{
+  unsigned int sum = 0;
+  for (unsigned int i = 0; i < quant; ++i)
+    sum += quant;
+  return sum;
+}
+
+/* A single basic-block should remain (computing and
+   returning quant * quant).  */
+/* { dg-final { scan-tree-dump-times "bb" 1 "optimized" } } */
index 171adebfa2056f518df0e372843683b102a188b8..9b5919d6704d429f2d387bd6050ce46ee6034850 100644 (file)
@@ -11,7 +11,3 @@ void foo()
     for (j = 0; j < 17; ++j)
       a[i] = 0;
 }
-
-/* { dg-final { scan-tree-dump-times "OUTER LOOP VECTORIZED" 1 "vect"  } } */
-
-
index 7b9814e1aa72b9b829701bb54f0d7438ba7e8a7f..50b5eefc1fca277dd33952a014df5c993677f823 100644 (file)
@@ -400,7 +400,6 @@ find_obviously_necessary_stmts (bool aggressive)
   if (aggressive)
     {
       struct loop *loop;
-      scev_initialize ();
       if (mark_irreducible_loops ())
        FOR_EACH_BB_FN (bb, cfun)
          {
@@ -423,7 +422,6 @@ find_obviously_necessary_stmts (bool aggressive)
              fprintf (dump_file, "can not prove finiteness of loop %i\n", loop->num);
            mark_control_dependent_edges_necessary (loop->latch, false);
          }
-      scev_finalize ();
     }
 }
 
@@ -1567,9 +1565,13 @@ perform_tree_ssa_dce (bool aggressive)
   /* Preheaders are needed for SCEV to work.
      Simple lateches and recorded exits improve chances that loop will
      proved to be finite in testcases such as in loop-15.c and loop-24.c  */
-  if (aggressive)
-    loop_optimizer_init (LOOPS_NORMAL
-                        | LOOPS_HAVE_RECORDED_EXITS);
+  bool in_loop_pipeline = scev_initialized_p ();
+  if (aggressive && ! in_loop_pipeline)
+    {
+      scev_initialize ();
+      loop_optimizer_init (LOOPS_NORMAL
+                          | LOOPS_HAVE_RECORDED_EXITS);
+    }
 
   tree_dce_init (aggressive);
 
@@ -1588,8 +1590,11 @@ perform_tree_ssa_dce (bool aggressive)
 
   find_obviously_necessary_stmts (aggressive);
 
-  if (aggressive)
-    loop_optimizer_finalize ();
+  if (aggressive && ! in_loop_pipeline)
+    {
+      loop_optimizer_finalize ();
+      scev_finalize ();
+    }
 
   longest_chain = 0;
   total_chain = 0;
@@ -1623,7 +1628,7 @@ perform_tree_ssa_dce (bool aggressive)
   if (something_changed)
     {
       free_numbers_of_iterations_estimates (cfun);
-      if (scev_initialized_p ())
+      if (in_loop_pipeline)
        scev_reset ();
       return TODO_update_ssa | TODO_cleanup_cfg;
     }