Message ID | 4DE49E91.60502@codesourcery.com |
---|---|
State | New |
Headers | show |
Hi, > As far as I can tell, what is current calculated in i_bound (and assigned to > nb_iterations_upper_bound), is the maximum amount of times any statement in the > loop is executed, where any includes exit tests. Differently put, the maximum > amount of times the loop header is executed. hmm... this is rather confusing, I don't really recall why I gave nb_iterations_upper_bound a different semantics from any other instance of what # of iterations of a loop means. > This is confirmed by this comment in tree-vrp.c: > > /* Try to use estimated number of iterations for the loop to constrain the > final value in the evolution. > We are interested in the number of executions of the latch, while > nb_iterations_upper_bound includes the last execution of the exit test. */ > > I modified the patch to improved the comment. I think a better fix would be to make the nb_iterations_upper_bound semantics consistent with that of nb_iterations. Let me try to do it, hopefully this should be mostly mechanical, Zdenek
Index: gcc/tree-ssa-loop-ivopts.c =================================================================== --- gcc/tree-ssa-loop-ivopts.c (revision 173734) +++ gcc/tree-ssa-loop-ivopts.c (working copy) @@ -4391,8 +4391,14 @@ may_eliminate_iv (struct ivopts_data *da { if (!estimated_loop_iterations (loop, true, &max_niter)) return false; - /* The loop bound is already adjusted by adding 1. */ - if (double_int_ucmp (max_niter, period_value) > 0) + /* (a) loop->nb_iterations_upper_bound (assigned to max_niter) + includes the last execution of the exit test. + (b) The number of distinct values of the cand is + period_value + 1. + So, the transformation is allowed if + max_niter <= period_value + 1. */ + period_value = double_int_add (period_value, double_int_one); + if (double_int_ucmp (max_niter, period_value) > 0) return false; } else