public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jan Hubicka <hubicka@ucw.cz>
To: Richard Biener <rguenther@suse.de>
Cc: gcc@gcc.gnu.org
Subject: Re: Definition of EAF_NOESCAPE and fnspec strings
Date: Mon, 9 Nov 2020 11:29:46 +0100	[thread overview]
Message-ID: <20201109102946.GA83507@kam.mff.cuni.cz> (raw)
In-Reply-To: <nycvar.YFH.7.76.2011090820080.10073@p653.nepu.fhfr.qr>

> > But it also means that some of our FNSPECs are wrong now.  I wonder if we can
> > split this porperty to two different flags like EAF_NOEASCAPE and
> > EAF_INDIRECT_NOESCAPE?
> 
> Note that EAF_NOESCAPE allows "escaping" to the return value (see
> handle_rhs_call).  I guess for simplicity we could allow escaping

I see, missed that! 

> of not escaped but USED params to other written to params.  I think
> we also don't handle "escaping" of a parameter indirectly to itself, thus
> 
> int i;
> int *p = &i;
> int **q = &p;
> foo (&q);
> if (*q != i)
>   abort ();
> 
> and
> 
> foo (int ***p)
> {
>   *p = **p;
> } 
> 
> or so with foos param EAF_NOESCAPE (but not EAF_DIRECT).
> 
> Splitting up EAF_NOESCAPE makes it quite difficult to understand.
> Arguably explicit handling of memcpy and friends _does_ pay off
> for points-to analysis since I'd say modelling all possible and useful
> things in fnspec would make it a monster ... you'd basically want
> to have a way to specify additional constraints in the fnspec itself,
> like *1 = *2, but then also distinguish points-to effects from
> may-alias ones.

Yep, i am not arguing for eliminating special case of memcpy (because we
have the additional info that it only copies pointers from *src to
*dest).

However I find current definition of EAF_NOESCAPE bit hard to handle in
modref, since naturally it is quite reliable to track all uses of ssa
name that correspond to parameters, but it is harder to track where
values read from pointed-to memory can eventually go.

What I do is to walk all uses of SSA_NAME that correspond to parameter
and try to unerstand it.  If it is one of
 1) memory load via derefence of name
 2) memory store where name is base of LHS
 3) memory store where name is rhs
 4) name is passed as a value to function 
 5) dereferenced value from name is passed to funtion
 6) used as value normal gimple expression
 7) used in return (as RHS or base of memory dereference address)
 8) it is used only in reference but not as base (as array index or so)

Then I merge in (and) flags I determine as follow:

For 1) clear EAF_USED and recurse to LHS name. Based on its flags I
decide on:
  - EAF_DIRECT (if LHS has EAF_UNUSED),
  - EAF_NOCLOBBER (if LHS has EAF_NOCLOBBER)
  - EAF_NOESCAPE (if LHS has EAF_NOESCAPE). 

For 2) I clear EAF_NOCLOBBER and EAF_UNUSED flag

For 3) I give up (clear all flags) since I would need to track where the
memory is going.

For 4) I determine flag of function parameter

For 5) I need to do same handling as 1) where flag of "loaded value" is
flag of the function

For 6) I determine flags of LHS and merge them in

For 7) I clear NOESCAPE if rhs is name itself
and UNUSED + NOESCAPE if rhs is derefernece from name.

For 8) I do nothing.  Here the names are non-pointers that I track
because of earlier dereference.



So I think 7) can be relaxed.  Main problem is hoever that we often see 1)
and then 3) or 7) on LHS that makes us punt very often.

The fact that pointer directly does not escape but pointed to memory can
seems still very useful since one does not need to add *ptr to points-to
sets. But I will try relaxing 7).

If we allow values escaping to other parameters and itself, I think I
can relax 3) if base of the store is default def of PARM_DECL.
> 
> I wonder if we should teach the GIMPLE FE to parse 'fn spec'
> so we can write unit tests for the attribute ... or maybe simply
> add this to the __GIMPLE spec string.

May be nice and also describe carefully that NOESCAPE and NOCLOBBER also
reffers to indirect references.  Current description
"Nonzero if the argument does not escape."
reads to me that it is about ptr itself, not about *ptr and also it does
not speak of the escaping to return value etc.

Honza

  reply	other threads:[~2020-11-09 10:29 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-08 12:47 Jan Hubicka
2020-11-09  7:31 ` Richard Biener
2020-11-09 10:29   ` Jan Hubicka [this message]
2020-11-09 12:38     ` Richard Biener
2020-11-09 13:16       ` Detect EAF flags in ipa-modref Jan Hubicka
2020-11-09 23:14         ` Jan Hubicka
2020-11-10  9:17           ` Jan Hubicka
2020-11-10 10:25           ` Jan Hubicka
2020-11-10 10:55             ` Jan Hubicka
2020-11-10 11:04           ` Richard Biener
2020-11-10 12:54             ` Jan Hubicka
2020-11-10 14:31               ` Jan Hubicka
2020-11-13  8:06                 ` Richard Biener
2020-11-15 13:25                   ` H.J. Lu
2020-11-15 14:13                     ` Jan Hubicka
2020-11-15 10:41                 ` Andreas Schwab
2020-11-15 11:12                   ` Jan Hubicka
2020-11-15 11:25                     ` Rainer Orth
2020-11-15 12:33                       ` Jan Hubicka
2020-11-15 12:43                         ` Rainer Orth
2020-11-15 13:03                           ` Jan Hubicka
2020-11-15 16:03                             ` Rainer Orth
2020-11-15 16:15                             ` Andreas Schwab
2020-11-15 18:07                               ` Jan Hubicka
2020-11-16  7:48                                 ` Richard Biener
2020-11-16  9:26                                 ` Andreas Schwab
2020-11-16 10:59                                   ` Jan Hubicka
2020-11-16 12:36                                     ` Richard Biener
2020-11-16 12:44                                       ` Jan Hubicka
2020-11-16 19:33                                         ` Martin Liška
2020-11-16 19:46                                           ` Jan Hubicka
2020-11-11 10:09               ` Richard Biener

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201109102946.GA83507@kam.mff.cuni.cz \
    --to=hubicka@ucw.cz \
    --cc=gcc@gcc.gnu.org \
    --cc=rguenther@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).