https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84111
--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Seems this is during #0 follow_copies_to_constant (var=<ssa_name 0x7fffefa46bd0>) at ../../gcc/tree-scalar-evolution.c:1548 #1 0x00000000010ce55e in analyze_scalar_evolution_1 (loop=0x7fffefb99550, var=<ssa_name 0x7fffefa46bd0>) at ../../gcc/tree-scalar-evolution.c:2036 #2 0x00000000010ce7ff in analyze_scalar_evolution (loop=0x7fffefb99550, var=<ssa_name 0x7fffefa46bd0>) at ../../gcc/tree-scalar-evolution.c:2114 #3 0x00000000010ce8be in analyze_scalar_evolution_in_loop (wrto_loop=0x7fffefb99550, use_loop=0x7fffefb99550, version=<ssa_name 0x7fffefa46bd0>, folded_casts=0x7fffffffd6bf) at ../../gcc/tree-scalar-evolution.c:2210 #4 0x00000000010d151e in simple_iv_with_niters (wrto_loop=0x7fffefb99550, use_loop=0x7fffefb99550, op=<ssa_name 0x7fffefa46bd0>, iv=0x7fffffffd7f0, iv_niters=0x7fffffffd7c8, allow_nonconstant_step=false) at ../../gcc/tree-scalar-evolution.c:3326 #5 0x0000000001183ef6 in number_of_iterations_exit_assumptions (loop=0x7fffefb99550, exit=<edge 0x7fffefb9cea0 (17 -> 10)>, niter=0x7fffffffd8d0, at_stmt=0x7fffffffd8a8, every_iteration=true) at ../../gcc/tree-ssa-loop-niter.c:2358 #6 0x000000000118437a in number_of_iterations_exit (loop=0x7fffefb99550, exit=<edge 0x7fffefb9cea0 (17 -> 10)>, niter=0x7fffffffd8d0, warn=false, every_iteration=true) at ../../gcc/tree-ssa-loop-niter.c:2442 #7 0x0000000001184470 in find_loop_niter (loop=0x7fffefb99550, exit=0x7fffffffda28) at ../../gcc/tree-ssa-loop-niter.c:2474 #8 0x00000000011556fb in canonicalize_loop_induction_variables (loop=0x7fffefb99550, create_iv=false, ul=UL_NO_GROWTH, try_eval=false, allow_peel=true) at ../../gcc/tree-ssa-loop-ivcanon.c:1198 #9 0x000000000115609d in tree_unroll_loops_completely_1 (may_increase_size=false, unroll_outer=true, father_bbs=0x2ac25e0, loop=0x7fffefb99550) at ../../gcc/tree-ssa-loop-ivcanon.c:1410 #10 0x0000000001155faf in tree_unroll_loops_completely_1 (may_increase_size=false, unroll_outer=true, father_bbs=0x2ac25e0, loop=0x7fffefb99000) at ../../gcc/tree-ssa-loop-ivcanon.c:1379 #11 0x0000000001156180 in tree_unroll_loops_completely (may_increase_size=false, unroll_outer=true) at ../../gcc/tree-ssa-loop-ivcanon.c:1450 A few possible fixes: 1) just apply an upper bound on how many times we loop: --- gcc/tree-scalar-evolution.c.jj 2018-01-03 10:19:54.735533890 +0100 +++ gcc/tree-scalar-evolution.c 2018-01-29 20:04:33.198563895 +0100 @@ -1540,9 +1540,12 @@ static tree follow_copies_to_constant (tree var) { tree res = var; + int depth = 0; while (TREE_CODE (res) == SSA_NAME) { gimple *def = SSA_NAME_DEF_STMT (res); + if (++depth == PARAM_VALUE (PARAM_MAX_SSA_NAME_QUERY_DEPTH)) + break; if (gphi *phi = dyn_cast <gphi *> (def)) { if (tree rhs = degenerate_phi_result (phi)) or give up if name_registered_for_update_p: --- gcc/tree-scalar-evolution.c.jj 2018-01-03 10:19:54.735533890 +0100 +++ gcc/tree-scalar-evolution.c 2018-01-29 20:30:50.986363089 +0100 @@ -1540,7 +1540,8 @@ static tree follow_copies_to_constant (tree var) { tree res = var; - while (TREE_CODE (res) == SSA_NAME) + while (TREE_CODE (res) == SSA_NAME + && !name_registered_for_update_p (res)) { gimple *def = SSA_NAME_DEF_STMT (res); if (gphi *phi = dyn_cast <gphi *> (def)) or a combination of both. Thoughts on this?