[Bug middle-end/26900] Number of iterations not know for simple loop
rakdver at gcc dot gnu dot org
gcc-bugzilla@gcc.gnu.org
Sun Apr 2 16:04:00 GMT 2006
------- Comment #10 from rakdver at gcc dot gnu dot org 2006-04-02 16:04 -------
(In reply to comment #7)
> Subject: Re: Number of iterations not know for simple loop
>
> > > I thought if we know that we are looking at the loop header copy condition that
> > > we _know_ that the loop runs at least once, so we can avoid trying to prove
> > > that again using fold.
> >
> > How?
>
> Sorry for the dumb question, I now understand what you mean. Let me
> think about this for a moment, please.
I think the basic idea is OK, although one needs to be a bit careful, at least
with the following details:
1) Loops with multiple exits -- one would have to record the fact whether the
condition was duplicated or not for each exit separately.
2) One would need to restrict this for "nice" induction variables; e.g., a loop
like this one:
int i, x, n;
int a[10];
for (i = 0, x = -100; x < n; i++, x = (int) (unsigned char) x + 1)
a[i] = x;
becomes
x = -100;
i = 0;
if (-100 < n)
do
{
a[i] = x;
i++;
x = (int) (unsigned char) x + 1
}
while (x < n)
Now, the variable x in the compare x < n has evolution {156, +, 1} (the loop
contains enough information to infer this, although we currently are not be
able to do it), and we must check for n >= 156 in may_be_zero.
>Maybe we should remember the BB of the loop header copy so we can verify
>later that it still dominates the loop header.
Checking that it still dominates the loop header should not be neccessary, just
the fact that it was copied should matter.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26900
More information about the Gcc-bugs
mailing list