https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98117
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |rsandifo at gcc dot gnu.org --- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> --- In fact there is alrady /* Create: niters >> log2(vf) */ /* If it's known that niters == number of latch executions + 1 doesn't overflow, we can generate niters >> log2(vf); otherwise we generate (niters - vf) >> log2(vf) + 1 by using the fact that we know ratio will be at least one. */ so we know about this "defect". The computation method translates easily to the range case (unconditionally). Unfortunately for some 'degenerate' cases where we arrive with const_vf == 1 we'll compute [1, 0] "ranges" this way which ICEs in niter compute. The question is whether we can construct cases we miscompile with such large niter and VF == 1 (full SLP). As noted when I added niter_m1 all uses of 'niter' would have to go away :/ For now I'm testing the "ugly" diff --git a/gcc/tree-vect-loop-manip.c b/gcc/tree-vect-loop-manip.c index 36179188f6d..36f218e7f6e 100644 --- a/gcc/tree-vect-loop-manip.c +++ b/gcc/tree-vect-loop-manip.c @@ -2034,13 +2034,21 @@ vect_gen_vector_loop_niters (loop_vec_info loop_vinfo, tree niters, niters_vector = force_gimple_operand (niters_vector, &stmts, true, var); gsi_insert_seq_on_edge_immediate (pe, stmts); /* Peeling algorithm guarantees that vector loop bound is at least ONE, - we set range information to make niters analyzer's life easier. */ + we set range information to make niters analyzer's life easier. + Note the number of latch iteration value can be TYPE_MAX_VALUE so + we have to represent the vector niter TYPE_MAX_VALUE + 1 >> log_vf. */ if (stmts != NULL && log_vf) set_range_info (niters_vector, VR_RANGE, - wi::to_wide (build_int_cst (type, 1)), - wi::to_wide (fold_build2 (RSHIFT_EXPR, type, - TYPE_MAX_VALUE (type), - log_vf))); + wi::one (TYPE_PRECISION (type)), + /* ??? Avoid creating [1, 0]. */ + const_vf == 1 + ? wi::max_value (TYPE_PRECISION (type), + TYPE_SIGN (type)) + : (wi::rshift (wi::max_value (TYPE_PRECISION (type), + TYPE_SIGN (type)) + - (const_vf - 1), + exact_log2 (const_vf), TYPE_SIGN (type)) + + 1)); } *niters_vector_ptr = niters_vector; *step_vector_ptr = step_vector;