low level optimization

Jim Giles jlg at cochiti.lanl.gov
Thu May 2 02:05:57 AEST 1991


In article <5475 at goanna.cs.rmit.oz.au>, ok at goanna.cs.rmit.oz.au (Richard A. O'Keefe) writes:
|> [...]                     Can Fortran Extended pointers be used for this
|> sort of linked structure manipulation, [...]

Yes.

|> [...]                                  and what does that do to Fortran's
|> prohibition of aliases?

Shoots it all to hell.  But, there is a very important difference.
Fortran does _not_ automatically convert array reference arguments 
into pointers when you make a function call.  So, array calculations
can still be compiled to efficient code without intermodule analysis.

|> [...]
|> 	subroutine matadd(a, b, c, m, n)
|> [...]
|> 		    a(i,j) = b(i,j) + c(i,j)
|> [...]
|> I've lost count of the number of books I've seen which tell you that
|> it is ok to call a subroutine like this as
|> 	call matadd(a, a, c, m, n)
|> or	call matadd(a, b, a, m, n)

I've not seen any books that recommend that.  I have seen books that
recomment _against_ it.  There is an aliased call that is legal in 
Fortran:
      call matadd(a,b,b,m,n)

It's safe to alias the second and third arguments because neither of
them is assigned to by the procedure.  Most books on Fortran recommend
that you don't do even this, since you can't be sure and it's better
to be safe.  Numerical Recipes (the one for Fortran) has _one_ program
in it which recommends an example of unsafe aliasing - but, in their 
case, so many of their algorithms need work it is not surprising that
they make such an error.

|> 
|> If Jim Giles accompanied his criticism of C for allowing aliasing
|> with a swipe at Fortran compiler vendors whose products do not by
|> default warn users when they commit the "error" of aliasing, then
|> I'd be impressed by his fairness.

Quite so.  I have always criticized Fortran implementations for this.
Especially since it does not require a run-time test.  If the compiler
were to put the proper information into the object code, the loader
could propagate the identities of procedure arguments through the 
call chain and detect all such illegal aliasing at load-time.  It is,
in fact, almost the same algorithm that I've been recommending for use
to optimize C code at load-time.

J. Giles



More information about the Comp.lang.c mailing list