ICE when compiling with Graphite loop optimizations internal compiler error: in add_loop_constraints, at graphite-sese-to-poly.c:931 https://bugs.gentoo.org/615876 http://gcc.gnu.org/PR71824 --- a/gcc/graphite-scop-detection.c +++ b/gcc/graphite-scop-detection.c @@ -905,6 +905,18 @@ scop_detection::build_scop_breadth (sese_l s1, loop_p loop) sese_l combined = merge_sese (s1, s2); + /* Combining adjacent loops may add unrelated loops into the + region so we have to check all sub-loops of the outer loop + that are in the combined region. */ + if (combined) + for (l = loop_outer (loop)->inner; l; l = l->next) + if (bb_in_sese_p (l->header, combined) + && ! loop_is_valid_in_scop (l, combined)) + { + combined = invalid_sese; + break; + } + if (combined) s1 = combined; else @@ -931,6 +943,8 @@ scop_detection::can_represent_loop_1 (loop_p loop, sese_l scop) && niter_desc.control.no_overflow && (niter = number_of_latch_executions (loop)) && !chrec_contains_undetermined (niter) + && !chrec_contains_undetermined (scalar_evolution_in_region (scop, + loop, niter)) && graphite_can_represent_expr (scop, loop, niter); } --- a/gcc/graphite-sese-to-poly.c +++ b/gcc/graphite-sese-to-poly.c @@ -407,7 +407,7 @@ extract_affine (scop_p s, tree e, __isl_take isl_space *space) case SSA_NAME: gcc_assert (-1 != parameter_index_in_region_1 (e, s->scop_info) - || !invariant_in_sese_p_rec (e, s->scop_info->region, NULL)); + || defined_in_sese_p (e, s->scop_info->region)); res = extract_affine_name (s, e, space); break; @@ -436,11 +436,11 @@ extract_affine (scop_p s, tree e, __isl_take isl_space *space) /* Returns a linear expression for tree T evaluated in PBB. */ static isl_pw_aff * -create_pw_aff_from_tree (poly_bb_p pbb, tree t) +create_pw_aff_from_tree (poly_bb_p pbb, loop_p loop, tree t) { scop_p scop = PBB_SCOP (pbb); - t = scalar_evolution_in_region (scop->scop_info->region, pbb_loop (pbb), t); + t = scalar_evolution_in_region (scop->scop_info->region, loop, t); gcc_assert (!chrec_contains_undetermined (t)); gcc_assert (!automatically_generated_chrec_p (t)); @@ -455,8 +455,9 @@ create_pw_aff_from_tree (poly_bb_p pbb, tree t) static void add_condition_to_pbb (poly_bb_p pbb, gcond *stmt, enum tree_code code) { - isl_pw_aff *lhs = create_pw_aff_from_tree (pbb, gimple_cond_lhs (stmt)); - isl_pw_aff *rhs = create_pw_aff_from_tree (pbb, gimple_cond_rhs (stmt)); + loop_p loop = gimple_bb (stmt)->loop_father; + isl_pw_aff *lhs = create_pw_aff_from_tree (pbb, loop, gimple_cond_lhs (stmt)); + isl_pw_aff *rhs = create_pw_aff_from_tree (pbb, loop, gimple_cond_rhs (stmt)); isl_set *cond; switch (code) --- /dev/null +++ b/gcc/testsuite/gcc.dg/graphite/pr71824-2.c @@ -0,0 +1,34 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -floop-nest-optimize" } */ + +typedef struct { float x1; } bx; +typedef struct { + int w; + short o; +} T2P; +T2P a; +int b; +void fn2(); +void fn3(bx*,short); +void fn1() { + unsigned i = 0; + int c; + bx *d; + bx **h; + if (b == 0) { + fn2(); + return; + } + for (; c; c++) + for (; i < 100; i++) { + d = h[i]; + d->x1 = a.w; + } + for (; i < 100; i++) { + d = h[i]; + d->x1 = a.w; + } + if (a.o) + for (; b;) + fn3(d, a.o); +} --- /dev/null +++ b/gcc/testsuite/gcc.dg/graphite/pr71824-3.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -ftree-loop-distribution -floop-nest-optimize" } */ + +struct +{ + int bz; +} od, ka[2]; + +int fw; + +void +pc (void) +{ + for (od.bz = 0; od.bz < 2; ++od.bz) + { + ++fw; + ka[0] = ka[1]; + } +} --- /dev/null +++ b/gcc/testsuite/gcc.dg/graphite/pr71824.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -floop-nest-optimize" } */ + +int a, b, d; +int **c; +int fn1() { + while (a) + if (d) { + int e = -d; + for (; b < e; b++) + c[b] = &a; + } else { + for (; b; b++) + c[b] = &b; + d = 0; + } +}