This is the mail archive of the gcc@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: -fargument-noalias-global question


On Sat, 3 Jan 2009, Toon Moene wrote:

> [ Happy New Year first of all - hope we don't have too many more of them
>   ... Hey, you can recognize a Jimi Hendrix fan, don't you ]

;)

> Richard Guenther wrote:
> 
> > Actually I have two questions.  First, what is the difference between
> > -fargument-noalias-global and -fargument-noalias-anything (please
> > provide an example, not cite documentation ;))
> 
> svn blame should point to me as the culprit.  I invented
> -fargument-noalias-anything because I ran out of specifics Fortran argument
> pointers *do not point at*.
> 
> The pointers used by the Fortran Front End to implement Fortran's argument
> association *cannot* point to anything else than the storage of those
> arguments, because they (those pointers) are generated by the compiler and
> cannot point to anything else (they cannot be modified).

Ok.  I guess that would answer my request from earlier last year as if
that includes reachable memory - not.  The issue is with fortran
array passing which is (simplified) done from a middle-end point of view
as

 struct { void *data; } array1, array2;
 array1.data = xyz;
 array2.data = wur;
 foo (&array1, &array2);

so - if the argument to foo aliases with nothing that doesn't help
optimization.  We know that array1->data and arrray2->data do
not alias - but we do _not_ know that *array1->data (*xyz) and
*array2->data (*wur) do not alias - unless that "aliases nothing"
extends to everything reachable from the arguments.

I btw installed that (wrong?) patch based on the answers I got.

> Whether or not -fargument-noalias-anything is useful for languages other than
> Fortran is anybody's guess (I'm betting on "none").

It needs to be useful to the middle-end at least ... which is why I am
asking for a specification in middle-end terms.

> > Second question.  Does "global memory" include memory that escaped?
> > Thus, with -fargument-noalias-global:
> 
> The "global" in -fargument-noalias-global refers to data in COMMON. Again, it
> is hard to see how this option could be useful outside Fortran.

You shouldn't have exposed those options to outside of fortran then ...

> Note that COMMON data in Fortran escapes by default, because it can be
> accessible in any other compilation unit (just by including the COMMON
> declaration).
> 
> > int *p;
> > void foo(int *q)
> > {
> >   may *q and *p alias?
> > }
> 
> The canonical Fortran example is:
> 
>       SUBROUTINE AAP(P)
>       COMMON /NOOT/ Q
> 
> P (which is a pointer in the backend sense of the word - it's not a Fortran
> pointer) cannot point to the memory indicated by Q.

The C example above is different, the COMMON section would contain a
pointer and the question was whether that pointer may point to the same
memory as P.  Maybe that situation is not possible at all in Fortran, so
you maybe didn't think about that ;)

> > consider
> > 
> > void bar()
> > {
> >   int i;
> >   p = &i;
> >   foo (&i);
> > }
> > 
> > does that call to foo invoke undefined behavior if built with
> > -fargument-noalias-global?
> 
> It shouldn't, as 'int i' isn't global.  Now a more interesting question (one

Well, it is globally reachable after the assignment p = &i - which is
the core of my question - does global memory include globally reachable
memory?  Note that semantics too "Frontend tied" are very hard to
implement in the middle-end.

> that I do not know the answer to, because these flags were targeted at Fortran
> code) is whether this would wreck havoc in case of 'static int i' :-)

It wouldn't make a difference I guess.  But yeah, local statics are
interesting anyways ...

> > Is _that_ the difference vs.
> > -fargument-noalias-anything (-global would not alias global
> > decls, -anything would not alias any reachable memory (other than
> > what the parameter reaches?  or just what it points to?)).
> 
> -anything means that it can't point to anything else but its arguments memory.
>
> -global means it cannot point to global memory (but it assumes global memory
> works like Fortran's COMMON).

I see.  Both are not what is currently implemented by the way.

Richard.


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