From: Richard Biener Date: Mon, 2 Oct 2017 07:32:52 +0000 (+0000) Subject: re PR tree-optimization/82355 (ICE in outermost_loop_in_sese, at sese.c:301) X-Git-Tag: upstream/12.2.0~36626 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0389d86c4e252df643f9c3539e5a114add56ec7f;p=platform%2Fupstream%2Fgcc.git re PR tree-optimization/82355 (ICE in outermost_loop_in_sese, at sese.c:301) 2017-10-02 Richard Biener PR tree-optimization/82355 * graphite-isl-ast-to-gimple.c (build_iv_mapping): Also build a mapping for the enclosing loop but avoid generating one for the loop tree root. (copy_bb_and_scalar_dependences): Remove premature codegen error on PHIs in blocks duplicated into multiple places. * graphite-scop-detection.c (scop_detection::stmt_has_simple_data_refs_p): For a loop not in the region use it as loop and nest to analyze the DR in. (try_generate_gimple_bb): Likewise. * graphite-sese-to-poly.c (extract_affine_chrec): Adjust. (add_loop_constraints): For blocks in a loop not in the region create a dimension with a single iteration. * sese.h (gbb_loop_at_index): Remove assert. * gcc.dg/graphite/fuse-1.c: Adjust. * gcc.dg/graphite/fuse-2.c: Likewise. * gcc.dg/graphite/pr82355.c: New testcase. From-SVN: r253336 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index ede5fb0..d5b0b6f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,20 @@ +2017-10-02 Richard Biener + + PR tree-optimization/82355 + * graphite-isl-ast-to-gimple.c (build_iv_mapping): Also build + a mapping for the enclosing loop but avoid generating one for + the loop tree root. + (copy_bb_and_scalar_dependences): Remove premature codegen + error on PHIs in blocks duplicated into multiple places. + * graphite-scop-detection.c + (scop_detection::stmt_has_simple_data_refs_p): For a loop not + in the region use it as loop and nest to analyze the DR in. + (try_generate_gimple_bb): Likewise. + * graphite-sese-to-poly.c (extract_affine_chrec): Adjust. + (add_loop_constraints): For blocks in a loop not in the region + create a dimension with a single iteration. + * sese.h (gbb_loop_at_index): Remove assert. + 2017-10-01 Kevin Buettner * omp-expand.c (adjust_context_scope): New function. diff --git a/gcc/graphite-isl-ast-to-gimple.c b/gcc/graphite-isl-ast-to-gimple.c index 820e14e..fb91ba1 100644 --- a/gcc/graphite-isl-ast-to-gimple.c +++ b/gcc/graphite-isl-ast-to-gimple.c @@ -774,8 +774,10 @@ build_iv_mapping (vec iv_map, gimple_poly_bb_p gbb, if (codegen_error_p ()) t = integer_zero_node; - loop_p old_loop = gbb_loop_at_index (gbb, region, i - 1); - iv_map[old_loop->num] = t; + loop_p old_loop = gbb_loop_at_index (gbb, region, i - 2); + /* Record sth only for real loops. */ + if (loop_in_sese_p (old_loop, region)) + iv_map[old_loop->num] = t; } } @@ -2587,18 +2589,6 @@ edge translate_isl_ast_to_gimple:: copy_bb_and_scalar_dependences (basic_block bb, edge next_e, vec iv_map) { int num_phis = number_of_phi_nodes (bb); - - if (region->copied_bb_map->get (bb)) - { - /* FIXME: we should be able to handle phi nodes with args coming from - outside the region. */ - if (num_phis) - { - set_codegen_error (); - return NULL; - } - } - basic_block new_bb = NULL; if (bb_contains_loop_close_phi_nodes (bb)) { diff --git a/gcc/graphite-scop-detection.c b/gcc/graphite-scop-detection.c index b374ee1..eed4efa 100644 --- a/gcc/graphite-scop-detection.c +++ b/gcc/graphite-scop-detection.c @@ -1055,10 +1055,12 @@ scop_detection::graphite_can_represent_expr (sese_l scop, loop_p loop, bool scop_detection::stmt_has_simple_data_refs_p (sese_l scop, gimple *stmt) { - loop_p nest = outermost_loop_in_sese (scop, gimple_bb (stmt)); + loop_p nest; loop_p loop = loop_containing_stmt (stmt); if (!loop_in_sese_p (loop, scop)) - loop = nest; + nest = loop; + else + nest = outermost_loop_in_sese (scop, gimple_bb (stmt)); auto_vec drs; if (! graphite_find_data_references_in_stmt (nest, loop, stmt, &drs)) @@ -1450,11 +1452,12 @@ try_generate_gimple_bb (scop_p scop, basic_block bb) vec reads = vNULL; sese_l region = scop->scop_info->region; - loop_p nest = outermost_loop_in_sese (region, bb); - + loop_p nest; loop_p loop = bb->loop_father; if (!loop_in_sese_p (loop, region)) - loop = nest; + nest = loop; + else + nest = outermost_loop_in_sese (region, bb); for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) diff --git a/gcc/graphite-sese-to-poly.c b/gcc/graphite-sese-to-poly.c index 087a44a..8611e86 100644 --- a/gcc/graphite-sese-to-poly.c +++ b/gcc/graphite-sese-to-poly.c @@ -86,7 +86,7 @@ extract_affine_chrec (scop_p s, tree e, __isl_take isl_space *space) isl_pw_aff *lhs = extract_affine (s, CHREC_LEFT (e), isl_space_copy (space)); isl_pw_aff *rhs = extract_affine (s, CHREC_RIGHT (e), isl_space_copy (space)); isl_local_space *ls = isl_local_space_from_space (space); - unsigned pos = sese_loop_depth (s->scop_info->region, get_chrec_loop (e)) - 1; + unsigned pos = sese_loop_depth (s->scop_info->region, get_chrec_loop (e)); isl_aff *loop = isl_aff_set_coefficient_si (isl_aff_zero_on_domain (ls), isl_dim_in, pos, 1); isl_pw_aff *l = isl_pw_aff_from_aff (loop); @@ -756,10 +756,10 @@ add_loop_constraints (scop_p scop, __isl_take isl_set *domain, loop_p loop, return domain; const sese_l ®ion = scop->scop_info->region; if (!loop_in_sese_p (loop, region)) - return domain; - - /* Recursion all the way up to the context loop. */ - domain = add_loop_constraints (scop, domain, loop_outer (loop), context); + ; + else + /* Recursion all the way up to the context loop. */ + domain = add_loop_constraints (scop, domain, loop_outer (loop), context); /* Then, build constraints over the loop in post-order: outer to inner. */ @@ -770,6 +770,21 @@ add_loop_constraints (scop_p scop, __isl_take isl_set *domain, loop_p loop, domain = add_iter_domain_dimension (domain, loop, scop); isl_space *space = isl_set_get_space (domain); + if (!loop_in_sese_p (loop, region)) + { + /* 0 == loop_i */ + isl_local_space *ls = isl_local_space_from_space (space); + isl_constraint *c = isl_equality_alloc (ls); + c = isl_constraint_set_coefficient_si (c, isl_dim_set, loop_index, 1); + if (dump_file) + { + fprintf (dump_file, "[sese-to-poly] adding constraint to the domain: "); + print_isl_constraint (dump_file, c); + } + domain = isl_set_add_constraint (domain, c); + return domain; + } + /* 0 <= loop_i */ isl_local_space *ls = isl_local_space_from_space (isl_space_copy (space)); isl_constraint *c = isl_inequality_alloc (ls); diff --git a/gcc/sese.h b/gcc/sese.h index 3bdb34c..f1371ee 100644 --- a/gcc/sese.h +++ b/gcc/sese.h @@ -326,8 +326,6 @@ gbb_loop_at_index (gimple_poly_bb_p gbb, sese_l ®ion, int index) while (--depth > index) loop = loop_outer (loop); - gcc_assert (loop_in_sese_p (loop, region)); - return loop; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d12fbdd..2faad379 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2017-10-02 Richard Biener + + PR tree-optimization/82355 + * gcc.dg/graphite/fuse-1.c: Adjust. + * gcc.dg/graphite/fuse-2.c: Likewise. + * gcc.dg/graphite/pr82355.c: New testcase. + 2017-10-01 Jeff Law * gcc.dg/tree-ssa/ssa-dom-simplify-1.c: New test. diff --git a/gcc/testsuite/gcc.dg/graphite/fuse-1.c b/gcc/testsuite/gcc.dg/graphite/fuse-1.c index 204d3b2..e3bf7bc 100644 --- a/gcc/testsuite/gcc.dg/graphite/fuse-1.c +++ b/gcc/testsuite/gcc.dg/graphite/fuse-1.c @@ -1,15 +1,15 @@ /* Check that the two loops are fused and that we manage to fold the two xor operations. */ -/* { dg-options "-O2 -floop-nest-optimize -fdump-tree-forwprop-all -fdump-tree-graphite-all" } */ +/* { dg-options "-O2 -floop-nest-optimize -fdump-tree-forwprop4-all -fdump-tree-graphite-all" } */ /* Make sure we fuse the loops like this: AST generated by isl: for (int c0 = 0; c0 <= 99; c0 += 1) { - S_3(c0); - S_6(c0); - S_9(c0); + S_3(0, c0); + S_6(0, c0); + S_9(0, c0); } */ -/* { dg-final { scan-tree-dump-times "AST generated by isl:.*for \\(int c0 = 0; c0 <= 99; c0 \\+= 1\\) \\{.*S_.*\\(c0\\);.*S_.*\\(c0\\);.*S_.*\\(c0\\);.*\\}" 1 "graphite" } } */ +/* { dg-final { scan-tree-dump-times "AST generated by isl:.*for \\(int c0 = 0; c0 <= 99; c0 \\+= 1\\) \\{.*S_.*\\(0, c0\\);.*S_.*\\(0, c0\\);.*S_.*\\(0, c0\\);.*\\}" 1 "graphite" } } */ /* Check that after fusing the loops, the scalar computation is also fused. */ /* { dg-final { scan-tree-dump-times "gimple_simplified to\[^\\n\]*\\^ 12" 1 "forwprop4" } } */ diff --git a/gcc/testsuite/gcc.dg/graphite/fuse-2.c b/gcc/testsuite/gcc.dg/graphite/fuse-2.c index f4cea43..dc0a9b2 100644 --- a/gcc/testsuite/gcc.dg/graphite/fuse-2.c +++ b/gcc/testsuite/gcc.dg/graphite/fuse-2.c @@ -3,13 +3,13 @@ /* Make sure we fuse the loops like this: AST generated by isl: for (int c0 = 0; c0 <= 99; c0 += 1) { - S_3(c0); - S_6(c0); - S_9(c0); + S_3(0, c0); + S_6(0, c0); + S_9(0, c0); } */ -/* { dg-final { scan-tree-dump-times "AST generated by isl:.*for \\(int c0 = 0; c0 <= 99; c0 \\+= 1\\) \\{.*S_.*\\(c0\\);.*S_.*\\(c0\\);.*S_.*\\(c0\\);.*\\}" 1 "graphite" } } */ +/* { dg-final { scan-tree-dump-times "AST generated by isl:.*for \\(int c0 = 0; c0 <= 99; c0 \\+= 1\\) \\{.*S_.*\\(0, c0\\);.*S_.*\\(0, c0\\);.*S_.*\\(0, c0\\);.*\\}" 1 "graphite" } } */ #define MAX 100 int A[MAX], B[MAX], C[MAX]; diff --git a/gcc/testsuite/gcc.dg/graphite/pr82355.c b/gcc/testsuite/gcc.dg/graphite/pr82355.c new file mode 100644 index 0000000..b60772d --- /dev/null +++ b/gcc/testsuite/gcc.dg/graphite/pr82355.c @@ -0,0 +1,23 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -floop-nest-optimize" } */ + +int dc, at; + +void +tv (int *ld, int jl) +{ + for (;;) + { + if (dc != 0) + for (;;) + { + *ld = !!(*ld) + 1; + for (dc = 0; dc < 3; ++dc) + at = (jl != 0) ? *ld : 0; + } + + while (at != 0) + { + } + } +}