This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Debugging f-torture/execute/20000503-1.f failure
- To: Geoff Keating <geoffk at cygnus dot com>
- Subject: Re: Debugging f-torture/execute/20000503-1.f failure
- From: Toon Moene <toon at moene dot indiv dot nluug dot nl>
- Date: Sat, 01 Jul 2000 11:05:15 +0200
- CC: gcc-bugs at gcc dot gnu dot org
- Organization: Moene Computational Physics, Maartensdijk, The Netherlands
- References: <A9E96A79C068D211A6A90000C07BDF0D4D4DE0@crtsmail.crts.techaust.riotinto.com.au> <jmlmzmb9hi.fsf@envy.cygnus.com>
Geoff Keating wrote:
> "Billinghurst, David (CRTS)" <David.Billinghurst@riotinto.com.au> writes:
> > This is a partial analysis of f-torture/execute/20000503-1.f
> > The bug has been isolated to the subroutine below.
> >
> > INTEGER FUNCTION SLASQX( N )
> > INTEGER N, I0, I, K
> > I0 = 1
> > DO I = 4*I0, 2*( I0+N-1 ), 4
> > K = I
> > END DO
> > SLASQX = K
> > RETURN
> > END
> >
> > When called with N=20, the return value is 36, rather than 2*N = 40.
> I don't know whether it really means 1 or I0. I suspect the fortran
> frontend has decided they are the same and so is using the same
> register to store them. That is ok too.
That would surprise me; I recall that Craig was very much against such
trickery in the frontend - he definitely wanted the middle- and backends
deal with these kind of optimisations (which cannot be done without
proper flow analysis anyway).
> What it's really trying to compute is the number of times the loop
> executes. I think this number of times is
> (N + 1)/2
> but my grasp of Fortran is not quite good enough to be sure it's
> correct.
A Fortran DO loop always has a definite number of iterations, due to the
fact that assignments to the loop index are illegal and assignments to
the loop bounds or step do not have an effect.
So:
DO I = N1, N2, N3 ! Loop from N1 to N2 with step N3
...
ENDDO
has the following number of iterations:
MAX((N2-N1+N3)/N3,0)
or, in this case (IO=1 and N=20):
N1 = 4*1 = 4, N2 = 2*(1+20-1) = 40, N3 = 4
MAX(40-4+4)/4,0) = 10
During the first pass through the loop, I = 4*1 = 4, subsequently:
2, 3, 4, 5, 6, 7 8, 9, 10
8, 12, 16, 20, 24, 28, 32, 36, 40
So the final value is 40 and that's what K (and hence the function value
SLASQX) should end up with.
It is an interesting problem - it cannot be an error in induction
variable elimination, because the problem manifests itself even at -O0.
Given that this code hasn't changed in the Frontend since November '95 -
when I changed the loop counting from testing for i-- > 0 to --i >= 0,
this makes it highly probable that constant folding is at fault here.
--
Toon Moene - mailto:toon@moene.indiv.nluug.nl - phoneto: +31 346 214290
Saturnushof 14, 3738 XG Maartensdijk, The Netherlands
GNU Fortran 77: http://gcc.gnu.org/onlinedocs/g77_news.html
GNU Fortran 95: http://g95.sourceforge.net/ (under construction)