The following fixes SCEV follow_copies_to_constant to properly deal with regions with not up-to-date SSA form as we are presented with by some passes like for example unrolling or graphite. follow_copies_to_constant can venture into sibling loops which is what those passes do not expect -- they rightfully treat those as unrelated and thus not important to have correct IL in.
So here's another name_registered_for_update_p () workaround for this. Eventually a fix would be to simply make update_ssa cheaper (work on SESE regions). Those passes delay update-ssa because else they'd be quadratic. Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk. Richard. 2018-03-08 Richard Biener <rguent...@suse.de> PR middle-end/84552 * tree-scalar-evolution.c: Include tree-into-ssa.h. (follow_copies_to_constant): Do not follow SSA names registered for update. * gcc.dg/graphite/pr84552.c: New testcase. Index: gcc/tree-scalar-evolution.c =================================================================== --- gcc/tree-scalar-evolution.c (revision 258359) +++ gcc/tree-scalar-evolution.c (working copy) @@ -280,6 +280,7 @@ along with GCC; see the file COPYING3. #include "params.h" #include "tree-ssa-propagate.h" #include "gimple-fold.h" +#include "tree-into-ssa.h" static tree analyze_scalar_evolution_1 (struct loop *, tree); static tree analyze_scalar_evolution_for_address_of (struct loop *loop, @@ -1540,7 +1541,10 @@ static tree follow_copies_to_constant (tree var) { tree res = var; - while (TREE_CODE (res) == SSA_NAME) + while (TREE_CODE (res) == SSA_NAME + /* We face not updated SSA form in multiple places and this walk + may end up in sibling loops so we have to guard it. */ + && !name_registered_for_update_p (res)) { gimple *def = SSA_NAME_DEF_STMT (res); if (gphi *phi = dyn_cast <gphi *> (def)) Index: gcc/testsuite/gcc.dg/graphite/pr84552.c =================================================================== --- gcc/testsuite/gcc.dg/graphite/pr84552.c (nonexistent) +++ gcc/testsuite/gcc.dg/graphite/pr84552.c (working copy) @@ -0,0 +1,23 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -floop-nest-optimize -fno-tree-copy-prop -fno-tree-fre -fno-tree-loop-ivcanon" } */ + +int cx; + +int +e6 (int pj, int xe) +{ + for (cx = 0; cx < 2; ++cx) + while (xe < 1) + { + for (cx = 0; cx < 2; ++cx) + pj *= 2; + + if (cx != 0) + goto o3; + + ++xe; + } + +o3: + return pj; +}