This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: number_of_iterations_in_loop and a non-constant loop bound start
- From: Zdenek Dvorak <rakdver at atrey dot karlin dot mff dot cuni dot cz>
- To: Andrew Pinski <pinskia at physics dot uc dot edu>
- Cc: "gcc at gcc dot gnu dot org List" <gcc at gcc dot gnu dot org>
- Date: Thu, 26 Aug 2004 11:29:26 +0200
- Subject: Re: number_of_iterations_in_loop and a non-constant loop bound start
- References: <41C46E43-F70F-11D8-A009-00039351ED8A@physics.uc.edu>
Hello,
> While working on a loop pass I found that number_of_iterations_in_loop
> reported
> that a loop with a non constant start as being undetermined which is
> wrong for
> this case as we know that the initializer will always before the end.
>
> Take for an example:
>
>
> void g(int init, int max, char *a)
> {
> int i;
> for (i = init; i < max; i++)
> a[i] = 0;
> }
>
> in the loop we know that init < max as the tree looks like:
this is a deficiency in fold; the code to determine number of
iterations takes the init < max condition into account, but
fold is unable to simplify the following expressions:
init_2 < max_4 && max_4 == -2147483648
should be folded to 0, since there is no integer smaller than
-2147483648
init_2 < max_4 && init_2 + 1 > max_4 - 1 + 1
should be folded to 0, since init_2 cannot be both smaller and
greater or equal to max_4.
In the later case a part of the reason this does not work is that
one of the "1" constants has overflow flag set, which makes fold
to behave just crazily.
Zdenek