Re: C and FORTRAN semantics and opt-n, was Re: C Fronts

MASLOV@VADIK.srcc.msu.su
Fri, 16 Aug 91 20:30:13 +0300

          From comp.compilers

Related articles
Re: C and FORTRAN semantics and opt-n, was Re: C Fronts MASLOV@VADIK.srcc.msu.su (1991-08-16)
| List of all articles for this month |
Newsgroups: comp.compilers
From: MASLOV@VADIK.srcc.msu.su
Keywords: optimize, C, Fortran
Organization: Research Computing Center, Moscow State University
Date: Fri, 16 Aug 91 20:30:13 +0300

        bob@tera.com (Bob Alverson) writes in 91-08-044:


> DOUBLE X(1001), Y(1001)
> lw = 994
> temp = 0.0;
> DO 4 j = 5, n, 5
> temp = temp - X(lw)*Y(j)
> lw = lw + 1
> 4 continue
> Can the compiler infer that (n < 45) in this loop? When n is as large as
> 45, lw will exceed the subscript range of X. Thus, it seems that a smart
> compiler could unroll this loop completely, allowing for 0 to 8 iterations
> of the j loop. :-)


        I think the answer must be *yes*. However ...




        Note 1:
Compiler which is smarter than one mentioned in Bob's article will infer
that n <= 40: lw from 994 to 1001 gives us 1001-994+1=8 iterations;
value of j in 8th iteration will be 5+(8-1)*5=40; that means that n <= 40.




        Note 2:
Let's consider slightly modified version of this example:


                DOUBLE X(1001), Y(1001)
                lw = 994
                DO 4 j = 5, n, 5
                      X(j)=X(lw)*Y(j)
                      lw = lw + 1
  4 continue


If compiler which is real smart discovers that cells from X(1) to X(500)
are not used later in a program (why not, maybe these cells were temporaries)
it may allow to assign them with any garbage including values that
can be taken from outside of the array X in reference X(lw).


In general, if language semantics says that incorrect operation (such as
taking values from outside of array) produces some *Err* value and allows
execution to continue then it can not be said that there will be 8 iterations
or less. There can be more (in modified example not original, of course).


However, if semantics says that appearance of any *Err* value (even if it
won't be used anymore) must stop the whole program then smart compiler
has easier ways to make clever conclusions.


In connection with this I have a question:


To what of the above described types does semantics of FORTRAN-77 belong?
--
  Yours sincerely, Vadim Yu. Maslov
  E-mail: MASLOV@VADIK.srcc.msu.su
  Office phone: 7 095 939-2347, 7 095 939-3907
[The Fortran-77 standard simply disallows incorrect programs. It is entirely
up to the implementation what to do with them. -John]
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.