re PR tree-optimization/83385 ([graphite] Wrong code w/ -O1 -floop-nest-optimize)
authorRichard Biener <rguenther@suse.de>
Tue, 12 Dec 2017 12:15:38 +0000 (12:15 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 12 Dec 2017 12:15:38 +0000 (12:15 +0000)
2017-12-12  Richard Biener  <rguenther@suse.de>

PR tree-optimization/83385
* graphite-scop-detection.c (get_order, order): Remove.
(bb_to_rpo): New global.
(cmp_pbbs): Adjust.
(build_scops): Sort pbbs in RPO order.

* gcc.dg/graphite/pr83385.c: New testcase.

From-SVN: r255579

gcc/ChangeLog
gcc/graphite-scop-detection.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/graphite/pr83385.c [new file with mode: 0644]

index ae7adbc..4d8072e 100644 (file)
@@ -1,3 +1,11 @@
+2017-12-12  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/83385
+       * graphite-scop-detection.c (get_order, order): Remove.
+       (bb_to_rpo): New global.
+       (cmp_pbbs): Adjust.
+       (build_scops): Sort pbbs in RPO order.
+
 2017-12-12  James Greenhalgh  <james.greenhalgh@arm.com>
 
        * combine.c (simplify_set): Do not transform subregs to zero_extends
index 3d854a1..bb4cfc3 100644 (file)
@@ -1608,26 +1608,7 @@ gather_bbs::after_dom_children (basic_block bb)
 /* Compute sth like an execution order, dominator order with first executing
    edges that stay inside the current loop, delaying processing exit edges.  */
 
-static vec<unsigned> order;
-
-static void
-get_order (scop_p scop, basic_block bb, vec<unsigned> *order, unsigned *dfs_num)
-{
-  if (! bb_in_sese_p (bb, scop->scop_info->region))
-    return;
-
-  (*order)[bb->index] = (*dfs_num)++;
-  for (basic_block son = first_dom_son (CDI_DOMINATORS, bb);
-       son;
-       son = next_dom_son (CDI_DOMINATORS, son))
-    if (flow_bb_inside_loop_p (bb->loop_father, son))
-      get_order (scop, son, order, dfs_num);
-  for (basic_block son = first_dom_son (CDI_DOMINATORS, bb);
-       son;
-       son = next_dom_son (CDI_DOMINATORS, son))
-    if (! flow_bb_inside_loop_p (bb->loop_father, son))
-      get_order (scop, son, order, dfs_num);
-}
+static int *bb_to_rpo;
 
 /* Helper for qsort, sorting after order above.  */
 
@@ -1636,9 +1617,11 @@ cmp_pbbs (const void *pa, const void *pb)
 {
   poly_bb_p bb1 = *((const poly_bb_p *)pa);
   poly_bb_p bb2 = *((const poly_bb_p *)pb);
-  if (order[bb1->black_box->bb->index] < order[bb2->black_box->bb->index])
+  if (bb_to_rpo[bb1->black_box->bb->index]
+      < bb_to_rpo[bb2->black_box->bb->index])
     return -1;
-  else if (order[bb1->black_box->bb->index] > order[bb2->black_box->bb->index])
+  else if (bb_to_rpo[bb1->black_box->bb->index]
+          > bb_to_rpo[bb2->black_box->bb->index])
     return 1;
   else
     return 0;
@@ -1662,7 +1645,7 @@ build_scops (vec<scop_p> *scops)
   /* Domwalk needs a bb to RPO mapping.  Compute it once here.  */
   int *postorder = XNEWVEC (int, n_basic_blocks_for_fn (cfun));
   int postorder_num = pre_and_rev_post_order_compute (NULL, postorder, true);
-  int *bb_to_rpo = XNEWVEC (int, last_basic_block_for_fn (cfun));
+  bb_to_rpo = XNEWVEC (int, last_basic_block_for_fn (cfun));
   for (int i = 0; i < postorder_num; ++i)
     bb_to_rpo[postorder[i]] = i;
   free (postorder);
@@ -1676,16 +1659,8 @@ build_scops (vec<scop_p> *scops)
       /* Record all basic blocks and their conditions in REGION.  */
       gather_bbs (CDI_DOMINATORS, scop, bb_to_rpo).walk (s->entry->dest);
 
-      /* domwalk does not fulfil our code-generations constraints on the
-         order of pbb which is to produce sth like execution order, delaying
-        exection of loop exit edges.  So compute such order and sort after
-        that.  */
-      order.create (last_basic_block_for_fn (cfun));
-      order.quick_grow (last_basic_block_for_fn (cfun));
-      unsigned dfs_num = 0;
-      get_order (scop, s->entry->dest, &order, &dfs_num);
+      /* Sort pbbs after execution order for initial schedule generation.  */
       scop->pbbs.qsort (cmp_pbbs);
-      order.release ();
 
       if (! build_alias_set (scop))
        {
@@ -1732,6 +1707,7 @@ build_scops (vec<scop_p> *scops)
     }
 
   free (bb_to_rpo);
+  bb_to_rpo = NULL;
   DEBUG_PRINT (dp << "number of SCoPs: " << (scops ? scops->length () : 0););
 }
 
index 6f0ea7c..09fe88b 100644 (file)
@@ -1,3 +1,8 @@
+2017-12-12  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/83385
+       * gcc.dg/graphite/pr83385.c: New testcase.
+
 2017-12-12  Marek Polacek  <polacek@redhat.com>
 
        PR c/82679
diff --git a/gcc/testsuite/gcc.dg/graphite/pr83385.c b/gcc/testsuite/gcc.dg/graphite/pr83385.c
new file mode 100644 (file)
index 0000000..627ff69
--- /dev/null
@@ -0,0 +1,32 @@
+/* { dg-do run } */
+/* { dg-options "-O1 -floop-nest-optimize" } */
+
+int xc, n1 = 0;
+int bx[2];
+
+int
+main (void)
+{
+  int aj = 1;
+  int cs;
+
+  for (cs = aj; cs >= 0; --cs)
+    {
+      int sq;
+
+      for (sq = 0; sq < 2; ++sq)
+       {
+         if (aj != 0)
+           --n1;
+
+         for (xc = 0; xc < 2; ++xc)
+           bx[xc] = 0;
+       }
+
+      --aj;
+    }
+
+  if (n1 != -2)
+    __builtin_abort ();
+  return 0;
+}