This patch fixes SESE merging which can sometimes form a region that is not SE.
Bootstrap/regtest running on x86_64-unknown-linux-gnu. Richard. 2017-03-09 Richard Biener <rguent...@suse.de> PR tree-optimization/79977 * graphite-scop-detection.c (scop_detection::merge_sese): Handle the case of extra exits to blocks dominating the entry. * gcc.dg/graphite/pr79977.c: New testcase. Index: gcc/graphite-scop-detection.c =================================================================== *** gcc/graphite-scop-detection.c (revision 246002) --- gcc/graphite-scop-detection.c (working copy) *************** scop_detection::merge_sese (sese_l first *** 817,822 **** --- 817,841 ---- != loop_depth (exit->dest->loop_father)) return invalid_sese; + /* For now we just bail out when there is a loop exit in the region + that is not also the exit of the region. We could enlarge the + region to cover the loop that region exits to. See PR79977. */ + if (loop_outer (entry->src->loop_father)) + { + vec<edge> exits = get_loop_exit_edges (entry->src->loop_father); + for (unsigned i = 0; i < exits.length (); ++i) + { + if (exits[i] != exit + && bb_in_region (exits[i]->src, entry->dest, exit->src)) + { + DEBUG_PRINT (dp << "[scop-detection-fail] cannot merge seses.\n"); + exits.release (); + return invalid_sese; + } + } + exits.release (); + } + /* For now we just want to bail out when exit does not post-dominate entry. TODO: We might just add a basic_block at the exit to make exit post-dominate entry (the entire region). */ Index: gcc/testsuite/gcc.dg/graphite/pr79977.c =================================================================== *** gcc/testsuite/gcc.dg/graphite/pr79977.c (nonexistent) --- gcc/testsuite/gcc.dg/graphite/pr79977.c (working copy) *************** *** 0 **** --- 1,27 ---- + /* { dg-do compile } */ + /* { dg-options "-O2 -floop-nest-optimize" } */ + + int uo[3]; + int di; + + void + i7 (int mp) + { + int l4; + + wh: + while (l4 > 1) + { + for (di = 0; di < 2; ++di) + uo[di] = 0; + + for (di = 0; di < 3; ++di) + { + uo[di] = 0; + if (mp != 0) + goto wh; + } + + --l4; + } + }