Should I convert FORTRAN code to C?
Jim Giles
jlg at beta.lanl.gov
Sat Jul 2 02:29:58 AEST 1988
In article <6067 at megaron.arizona.edu>, mike at arizona.edu (Mike Coffin) writes:
> From article <20454 at beta.lanl.gov>, by jlg at beta.lanl.gov (Jim Giles):
> > By the way, I've not seen any C compilers which optimize static 2-d
> > arrays anyway. An early step in the compiler usually turns the array
> > reference into a linear function on the indices - this throws out the
> > dependency information.
>
> This is not true. How can information be lost by changing "a[i]" to
> "*(a+i)"? In fact at least one very fancy FORTRAN compiler converts
> array references to exactly that form to extract dependency
> information that is difficult to recognize otherwise. See
> "Interprocedural Dependency Analysis and Parallelization" by Michael
> Burke and Ron Cytron, in the 1986 SIGPLAN Symposium on Compiler
> Construction, pp 162-175.
>
Most simple compilers (read 'C compilers') can't vectorize the following
(assume i is a loop index):
A[i+N] = A[i+M]
regardless of the values of N or M. However the following expression
might have been the source of the above expression:
A[4][i] = A[5][i]
This clearly has no dependencies and even a simple compiler (read 'some
Fortran compilers') can vectorize this (ie. A(i,4)=A(i,5)). Turning
the references above into *(A+i+4*dim2) = *(A+I+5*dim2) which, after
constant folding, is the expression I started out with is what causes
the C compiler to incorrectly identify a dependency.
Now, it is true that with careful analysis of M, N, and the range if i,
the compiler could still have compiled this efficiently. No C compilers
that I've seen do this very well.
Thank you for the reference. I have always been convinced that dependency
analysis should TRY the kind of stuff you suggest, but only if simplistic
analysis fails to get rid of the dependencies (compiler speed should
be considered too). The problem is that C doesn't use either analysis
technique very well. C actually CAN'T analyse those dynamic multi-
dimensional arrays (pointer-to-pointer) because it can't assume the
pointers have any specific relationships. It is probably for this
reason that it doesn't bother for static arrays either. (vote for
'noalias', that should help.)
J. Giles
Los Alamos
More information about the Comp.lang.c
mailing list