https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86232
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |ASSIGNED Known to work| |8.1.1 Keywords| |ice-on-valid-code Last reconfirmed| |2018-06-21 Assignee|unassigned at gcc dot gnu.org |rguenth at gcc dot gnu.org Ever confirmed|0 |1 Summary|ICE in record_estimate, at |[9 Regression] ICE in |tree-ssa-loop-niter.c:3258 |record_estimate, at | |tree-ssa-loop-niter.c:3258 Target Milestone|--- |9.0 --- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> --- 3258 gcc_checking_assert (i_bound == wi::to_widest (bound)); (gdb) l 3253 /* If the I_BOUND is just an estimate of BOUND, it rarely is close to the 3254 real number of iterations. */ 3255 if (TREE_CODE (bound) != INTEGER_CST) 3256 realistic = false; 3257 else 3258 gcc_checking_assert (i_bound == wi::to_widest (bound)); 3259 3260 /* If we have a guaranteed upper bound, record it in the appropriate 3261 list, unless this is an !is_exit bound (i.e. undefined behavior in 3262 at_stmt) in a loop with known constant number of iterations. */ (gdb) p i_bound $1 = (const widest_int &) @0x7fffffffd738: {<fixed_wide_int_storage<192>> = { val = {32, 140737330801152, 140737330854096, 140737329677800}, len = 1}, static is_sign_extended = <optimized out>} (gdb) p bound $2 = <integer_cst 0x7ffff69cb8d0> (gdb) p debug_generic_expr (bound) 1 $3 = void that's because we compute niter to constant 1 but specify a max of 32. Fix: diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c index 936591502d0..f5ffc0f19ad 100644 --- a/gcc/tree-ssa-loop-niter.c +++ b/gcc/tree-ssa-loop-niter.c @@ -2575,9 +2575,6 @@ number_of_iterations_popcount (loop_p loop, edge exit, return false; /* Update NITER params accordingly */ - max = TYPE_PRECISION (TREE_TYPE (src)); - if (adjust) - max = max - 1; tree utype = unsigned_type_for (TREE_TYPE (src)); src = fold_convert (utype, src); tree call = fold_convert (utype, build_call_expr (fn, 1, src)); @@ -2588,6 +2585,15 @@ number_of_iterations_popcount (loop_p loop, edge exit, else iter = call; + if (TREE_CODE (call) == INTEGER_CST) + max = tree_to_uhwi (call); + else + { + max = TYPE_PRECISION (TREE_TYPE (src)); + if (adjust) + max = max - 1; + } + niter->niter = iter; niter->assumptions = boolean_true_node; if (adjust)