From a365945b404c846e8737eb975dcd9f6253f1936b Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Tue, 12 Dec 2017 12:15:38 +0000 Subject: [PATCH] re PR tree-optimization/83385 ([graphite] Wrong code w/ -O1 -floop-nest-optimize) 2017-12-12 Richard Biener 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 | 8 +++++ gcc/graphite-scop-detection.c | 40 +++++-------------------- gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/gcc.dg/graphite/pr83385.c | 32 ++++++++++++++++++++ 4 files changed, 53 insertions(+), 32 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/graphite/pr83385.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index ae7adbcf08a..4d8072ecdd4 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2017-12-12 Richard Biener + + 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 * combine.c (simplify_set): Do not transform subregs to zero_extends diff --git a/gcc/graphite-scop-detection.c b/gcc/graphite-scop-detection.c index 3d854a13e6f..bb4cfc3899e 100644 --- a/gcc/graphite-scop-detection.c +++ b/gcc/graphite-scop-detection.c @@ -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 order; - -static void -get_order (scop_p scop, basic_block bb, vec *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 *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 *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 *scops) } free (bb_to_rpo); + bb_to_rpo = NULL; DEBUG_PRINT (dp << "number of SCoPs: " << (scops ? scops->length () : 0);); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6f0ea7c5727..09fe88b2155 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-12-12 Richard Biener + + PR tree-optimization/83385 + * gcc.dg/graphite/pr83385.c: New testcase. + 2017-12-12 Marek Polacek 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 index 00000000000..627ff699040 --- /dev/null +++ b/gcc/testsuite/gcc.dg/graphite/pr83385.c @@ -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; +} -- 2.30.2