This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: RFA: Revamp fortran array types


On Tue, Aug 18, 2009 at 05:20:02PM +0200, Richard Guenther wrote:
> On Tue, Aug 18, 2009 at 5:14 PM, Steve
> Kargl<sgk@troutmask.apl.washington.edu> wrote:
> > On Tue, Aug 18, 2009 at 04:40:17PM +0200, Michael Matz wrote:
> >> Hmm, richi tried polyhedron and verified that it is the
> >> tree-ssa-structalias.c hunk. ?Unfortunately that hunk alone is already a
> >> correctness fix, as demonstrated with this testcase:
> >>
> >> ----------------------------------
> >> ? integer, target :: foo
> >> ? integer, pointer :: p,p2
> >> ? integer :: i
> >> ? p=>foo
> >> ? p2=>foo
> >> ? i = clobber(p,p2)
> >> ? if (i /= 2) call abort
> >> contains
> >> ? function clobber(p,p2)
> >> ? ? integer clobber
> >> ? ? integer, pointer :: p,p2
> >> ? ? p = 1
> >> ? ? p2 = 2
> >> ? ? clobber = p
> >> ? end function
> >> end
> >> ----------------------------------
> >>
> >> An unpatched compiler with "-O2 -fno-inline" will make this testcase
> >> abort, exactly due to the hack called flag_argument_noalias.
> >
> > The above code is technically invalid Fortran, so a compiler
> > can do whatever it wants. ?The abort is a possible "correct"
> > result. ?The standard prohits a programmer from aliasing
> > the input arguments. ?The standard also does not require a
> > compiler to detect aliasing.
> 
> Doesn't that effectively make pointer and targets useless?

Of course, it means a programmer needs to know what the 
rules are for the language.  Suppose, Michael's clobber
function was in a stand-alone file (ie., not a contained
procedure).  How can a compiler diagnose that p,p2 alias
without incurring some runtime penalty.

This goes back to the age-old argue that a Fortran program
will run faster than an equivalent C program because a 
Fortran can assume that array arguments in function calls 
do not alias; while a C program with functions passing pointers
can't make this assumption.  Why was "restrict" added to C99? 

> Or is the scope where a compiler is not required to detect
> aliasing somehow restricted?
> 
> Thus for
> 
>   p => a
>   p2 => a
>   p = 1
>   p2 = 2
> 
> the compiler is allowed to re-oder the two stores?

I would need to go read up on the finer points of the
properties of Fortran pointers, but I believe the answer
may be "yes".   If we consider Michael's clobber function,


 ? function clobber(p,p2)
 ? ? integer clobber
 ? ? integer, pointer :: p,p2
 ? ? p = 1
 ? ? p2 = 2
 ? ? clobber = p
 ? end function

a compiler can assign 1 to p, then assign 2 to p2, then assign
p to clobber.  I "smart" compiler might analyze the code and
decide to assign 1 directly to clobber.  Additionally, a compiler
(because p and p2 are assumed to not alias) can re-order the
assignments of p and p2.

-- 
Steve


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]