Hi! As mentioned in the PR, cunroll sometimes registers some SSA_NAMEs for renaming and then invokes some SCEV using functions before finally updating the SSA form. On the testcase we end up with 3 degenerate PHIs pointing at each other, so follow_copies_to_constant loops forever.
The following patch has 2 different fixes for this, one is to avoid looking at SSA_NAMEs registered for update (in theory all we care are the old ssa names, but we don't have an API to query just those), the other is to put some upper bound on how many times we follow SSA_NAMEs (either single defs or degenerate phis). Either of those changes is sufficient to fix this. During x86_64-linux and i686-linux bootstraps/regtests follow_copies_to_constant actually never returned anything useful, so the patch doesn't regress at least on these targets anything, there are quite a few cases where SSA_NAME is name_registered_for_update_p but the function would never return anything but var in those cases. And the highest depth ever seen was 3, except for the newly added testcase if the && !name_registered_for_update_p (res) part is commented out. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2018-01-29 Jakub Jelinek <ja...@redhat.com> PR tree-optimization/84111 * tree-scalar-evolution.c: Include tree-into-ssa.h. (follow_copies_to_constant): Stop on SSA_NAMEs registered for update, loop at most 128 times. * gcc.c-torture/compile/pr84111.c: New test. --- gcc/tree-scalar-evolution.c.jj 2018-01-03 10:19:54.735533890 +0100 +++ gcc/tree-scalar-evolution.c 2018-01-29 20:36:34.648494334 +0100 @@ -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) + int depth = 0; + while (TREE_CODE (res) == SSA_NAME + && !name_registered_for_update_p (res) + && ++depth < 128) { gimple *def = SSA_NAME_DEF_STMT (res); if (gphi *phi = dyn_cast <gphi *> (def)) --- gcc/testsuite/gcc.c-torture/compile/pr84111.c.jj 2018-01-29 20:38:10.236528914 +0100 +++ gcc/testsuite/gcc.c-torture/compile/pr84111.c 2018-01-29 20:37:53.227522763 +0100 @@ -0,0 +1,31 @@ +/* PR tree-optimization/84111 */ + +void +foo (int x, int y, int z) +{ + int a = 0; + int *b = &x; + + while (a < 1) + { + int c = y; + *b = x; + lab: + for (a = 0; a < 36; ++a) + { + *b = 0; + if (x != 0) + y = 0; + while (c < 1) + ; + } + } + if (z < 33) + { + b = (int *) 0; + ++y; + ++z; + if (x / *b != 0) + goto lab; + } +} Jakub