On 11/06/13 10:23, Jakub Jelinek wrote:
On Wed, Nov 06, 2013 at 06:13:42PM +0100, Jakub Jelinek wrote:
I've looked at the above testcase to see why we aren't able to determine
the number of iterations upper bound properly here.

And here is a patch that uses get_range_info during # of iterations
analysis, so that for your testcase we can actually find out that it has
at most 2 latch executions and at most 3 header executions.

On that testcase, bound_difference is actually called with n_5(D) + 0xffffffff
and 0 and we don't have range info for n_5(D), because we had better range
info only for the SSA_NAMEs temporarily created for the assertions.
But with the previously posted patch, we have reasonable range info on the
PHI of the IV at loop->header, and as that PHI has n_5(D) as one of its
arguments (the one from preheader edge), we can still use that range info
when inside of the loop for # of iters purposes, even when it might be
wider range than strictly necessary (but not in this case).
So, the patch looks at both get_range_info of var itself and of all the
results of PHIs on loop->header that have var as PHI arg from the preheader
edge, and ands all the ranges together.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2013-11-06  Jakub Jelinek  <ja...@redhat.com>

        * tree-ssa-loop-niter.c: Include tree-ssanames.h.
        (determine_value_range): Add loop argument.  Use get_range_info to
        improve range.
        (bound_difference): Adjust caller.
Clever, using the range from the PHI in the loop header. While it may be too wide, it's likely going to be a lot better than nothing.

Add a testcase and this is OK.

jeff

Reply via email to