number_of_iterations_in_loop and a non-constant loop bound start
Zdenek Dvorak
rakdver@atrey.karlin.mff.cuni.cz
Thu Aug 26 11:31:00 GMT 2004
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
More information about the Gcc
mailing list