The following patch fixes the graphite ICE in the fortran testsuite. After digging and reverse engineering I concluded that the loop passed to scalar_evolution_in_region via add_condition_to_pbb and create_pw_aff_from_tree is bogus and instead the loop of the condition stmt should be used to not get chrecs with evolutions in loops that are not inside the SESE region of the SCOP. This in turn causes to trigger the assert because scalar_evolution_in_region doesn't "instantiate" defs in the region (but not defined in a loop fully contained in the region) up to parameters of the region. So what we are really interested in is that SSA names _not_ defined in the SESE region are registered as parameters.
Bootstrap and regtest running on x86_64-unknown-linux-gnu, preliminary testing on all graphite.exp with {,-m32} passed (I guess that's what we have in test coverage). I've come up with this through reverse-engineering only, knowing nothing about graphite so I'd appreciate a OK from the CCed maintainers (well, "maintainers"...) I'll try a quick before/after test of -floop-nest-optimize on SPEC 2k6. Thanks, Richard. 2017-01-31 Richard Biener <rguent...@suse.de> PR tree-optimization/77318 * graphite-sese-to-poly.c (extract_affine): Fix assert. (create_pw_aff_from_tree): Take loop parameter. (add_condition_to_pbb): Pass loop of the condition to create_pw_aff_from_tree. Index: gcc/graphite-sese-to-poly.c =================================================================== --- gcc/graphite-sese-to-poly.c (revision 245052) +++ gcc/graphite-sese-to-poly.c (working copy) @@ -407,7 +407,7 @@ extract_affine (scop_p s, tree e, __isl_ 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_ /* 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, 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)