https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81889
--- Comment #8 from Richard Biener <rguenth at gcc dot gnu.org> --- Specifically it is PRE code hoisting hoisting (integer(kind=8)) _2 above if (_2 > 3) making it impossible to set a SSA range info on it. At cunroll time we still have somewhat useful info on other SSA names in the loop: <bb 12> [local count: 912680545]: # val.11_94 = PHI <0.0(17), val.11_56(20)> # RANGE [1, 17] NONZERO 7 # S.12_93 = PHI <1(17), S.12_57(20)> # RANGE [0, 2] NONZERO 3 _16 = S.12_93 + -1; _17 = xx[_16]; val.11_56 = _17 + val.11_94; # RANGE [2, 4] NONZERO 7 S.12_57 = S.12_93 + 1; if (S.12_57 > _106) goto <bb 26>; [15.00%] else goto <bb 20>; [85.00%] <bb 26> [local count: 136902080]: # val.11_122 = PHI <val.11_56(12)> goto <bb 13>; [100.00%] specifically the range info on S.12 (even if somewhat strange) could be used to derive a range "backwards" for the number of iterations from base and step from the increment stmt for example. Thus for example the following fixes the testcase and exploits any range info on undefined overflow stmts. Giving that wider testing. Index: gcc/tree-ssa-loop-niter.c =================================================================== --- gcc/tree-ssa-loop-niter.c (revision 255539) +++ gcc/tree-ssa-loop-niter.c (working copy) @@ -3510,6 +3510,12 @@ infer_loop_bounds_from_signedness (struc low = lower_bound_in_type (type, type); high = upper_bound_in_type (type, type); + wide_int minv, maxv; + if (get_range_info (def, &minv, &maxv) == VR_RANGE) + { + low = wide_int_to_tree (type, minv); + high = wide_int_to_tree (type, maxv); + } record_nonwrapping_iv (loop, base, step, stmt, low, high, false, true); }