public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Handle EAF_DIRECT and EAF_UNUSED of pure calls
@ 2020-11-25 14:13 Jan Hubicka
  2020-11-25 14:30 ` Richard Biener
  0 siblings, 1 reply; 4+ messages in thread
From: Jan Hubicka @ 2020-11-25 14:13 UTC (permalink / raw)
  To: gcc-patches

Hi,
while looking into structalias I noticed that we ignore EAF flags here.
This is pity since we still can apply direct and unused.
This patch simply copies logic from normal call handling. I relaize that
it is bit more expensive by creating callarg and doing transitive
closure there instead of doing one common transitive closure on call use.
I can also scan first if there are both direct and !direct argument and
do this optimization, but it does not seem to affect build times (tested
on spec2k6 gcc LTO build)

lto-boostrapped/regtested x86_64-linux.

Honza

diff --git a/gcc/tree-ssa-structalias.c b/gcc/tree-ssa-structalias.c
index a4832b75436..5f84f7d467f 100644
--- a/gcc/tree-ssa-structalias.c
+++ b/gcc/tree-ssa-structalias.c
@@ -4253,12 +4253,20 @@ handle_pure_call (gcall *stmt, vec<ce_s> *results)
   for (i = 0; i < gimple_call_num_args (stmt); ++i)
     {
       tree arg = gimple_call_arg (stmt, i);
+      int flags = gimple_call_arg_flags (stmt, i);
+
+      if (flags & EAF_UNUSED)
+	continue;
+
       if (!uses)
-	{
-	  uses = get_call_use_vi (stmt);
-	  make_any_offset_constraints (uses);
-	  make_transitive_closure_constraints (uses);
-	}
+	uses = get_call_use_vi (stmt);
+      varinfo_t tem = new_var_info (NULL_TREE, "callarg", true);
+      tem->is_reg_var = true;
+      make_constraint_to (tem->id, arg);
+      make_any_offset_constraints (tem);
+      if (!(flags & EAF_DIRECT))
+	make_transitive_closure_constraints (tem);
+      make_copy_constraint (uses, tem->id);
       make_constraint_to (uses->id, arg);
     }
 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Handle EAF_DIRECT and EAF_UNUSED of pure calls
  2020-11-25 14:13 Handle EAF_DIRECT and EAF_UNUSED of pure calls Jan Hubicka
@ 2020-11-25 14:30 ` Richard Biener
  2020-11-29 15:37   ` Jan Hubicka
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Biener @ 2020-11-25 14:30 UTC (permalink / raw)
  To: Jan Hubicka; +Cc: GCC Patches

On Wed, Nov 25, 2020 at 3:14 PM Jan Hubicka <hubicka@ucw.cz> wrote:
>
> Hi,
> while looking into structalias I noticed that we ignore EAF flags here.
> This is pity since we still can apply direct and unused.
> This patch simply copies logic from normal call handling. I relaize that
> it is bit more expensive by creating callarg and doing transitive
> closure there instead of doing one common transitive closure on call use.
> I can also scan first if there are both direct and !direct argument and
> do this optimization, but it does not seem to affect build times (tested
> on spec2k6 gcc LTO build)
>
> lto-boostrapped/regtested x86_64-linux.

OK.

Richard.

> Honza
>
> diff --git a/gcc/tree-ssa-structalias.c b/gcc/tree-ssa-structalias.c
> index a4832b75436..5f84f7d467f 100644
> --- a/gcc/tree-ssa-structalias.c
> +++ b/gcc/tree-ssa-structalias.c
> @@ -4253,12 +4253,20 @@ handle_pure_call (gcall *stmt, vec<ce_s> *results)
>    for (i = 0; i < gimple_call_num_args (stmt); ++i)
>      {
>        tree arg = gimple_call_arg (stmt, i);
> +      int flags = gimple_call_arg_flags (stmt, i);
> +
> +      if (flags & EAF_UNUSED)
> +       continue;
> +
>        if (!uses)
> -       {
> -         uses = get_call_use_vi (stmt);
> -         make_any_offset_constraints (uses);
> -         make_transitive_closure_constraints (uses);
> -       }
> +       uses = get_call_use_vi (stmt);
> +      varinfo_t tem = new_var_info (NULL_TREE, "callarg", true);
> +      tem->is_reg_var = true;
> +      make_constraint_to (tem->id, arg);
> +      make_any_offset_constraints (tem);
> +      if (!(flags & EAF_DIRECT))
> +       make_transitive_closure_constraints (tem);
> +      make_copy_constraint (uses, tem->id);
>        make_constraint_to (uses->id, arg);
>      }
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Handle EAF_DIRECT and EAF_UNUSED of pure calls
  2020-11-25 14:30 ` Richard Biener
@ 2020-11-29 15:37   ` Jan Hubicka
  2020-11-30  9:59     ` Richard Biener
  0 siblings, 1 reply; 4+ messages in thread
From: Jan Hubicka @ 2020-11-29 15:37 UTC (permalink / raw)
  To: Richard Biener; +Cc: GCC Patches

> On Wed, Nov 25, 2020 at 3:14 PM Jan Hubicka <hubicka@ucw.cz> wrote:
> >
> > Hi,
> > while looking into structalias I noticed that we ignore EAF flags here.
> > This is pity since we still can apply direct and unused.
> > This patch simply copies logic from normal call handling. I relaize that
> > it is bit more expensive by creating callarg and doing transitive
> > closure there instead of doing one common transitive closure on call use.
> > I can also scan first if there are both direct and !direct argument and
> > do this optimization, but it does not seem to affect build times (tested
> > on spec2k6 gcc LTO build)
> >
> > lto-boostrapped/regtested x86_64-linux.
> 
> OK.
Hi,
I actually noticed that I missed to update handling of static chain and
NRV values, but while testing updated patch I also found that it has no
measurable effect on cc1plus and I failed to construct testcase where
handling of EAF_DIRECT would do somehting useful.  The points-to set
of returned value contains all eascape and nonlocal solutions (as it
should).  So I decided to commit only the EAF_UNUSED part. As it stands
EAF_DIRECT handling only makes constraint graph bigger for no much
benefit.

I think to make return values useful we need to also use the info about
global memory uses.  This is easilly available from modref but doing so
seems non-trivial since pure functions can return addresses of global
symbols but NONLOCAL solution is too big for that.

Honza

	* tree-ssa-structalias.c (handle_pure_call): Skip EAF_UNUSED
	 parameters.
diff --git a/gcc/tree-ssa-structalias.c b/gcc/tree-ssa-structalias.c
index 9f4de96d544..cf653be8b6d 100644
--- a/gcc/tree-ssa-structalias.c
+++ b/gcc/tree-ssa-structalias.c
@@ -4274,6 +4274,11 @@ handle_pure_call (gcall *stmt, vec<ce_s> *results)
   for (i = 0; i < gimple_call_num_args (stmt); ++i)
     {
       tree arg = gimple_call_arg (stmt, i);
+      int flags = gimple_call_arg_flags (stmt, i);
+
+      /* If the argument is not used we can ignore it.  */
+      if (flags & EAF_UNUSED)
+	continue;
       if (!uses)
 	{
 	  uses = get_call_use_vi (stmt);

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Handle EAF_DIRECT and EAF_UNUSED of pure calls
  2020-11-29 15:37   ` Jan Hubicka
@ 2020-11-30  9:59     ` Richard Biener
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Biener @ 2020-11-30  9:59 UTC (permalink / raw)
  To: Jan Hubicka; +Cc: GCC Patches

On Sun, Nov 29, 2020 at 4:37 PM Jan Hubicka <hubicka@ucw.cz> wrote:
>
> > On Wed, Nov 25, 2020 at 3:14 PM Jan Hubicka <hubicka@ucw.cz> wrote:
> > >
> > > Hi,
> > > while looking into structalias I noticed that we ignore EAF flags here.
> > > This is pity since we still can apply direct and unused.
> > > This patch simply copies logic from normal call handling. I relaize that
> > > it is bit more expensive by creating callarg and doing transitive
> > > closure there instead of doing one common transitive closure on call use.
> > > I can also scan first if there are both direct and !direct argument and
> > > do this optimization, but it does not seem to affect build times (tested
> > > on spec2k6 gcc LTO build)
> > >
> > > lto-boostrapped/regtested x86_64-linux.
> >
> > OK.
> Hi,
> I actually noticed that I missed to update handling of static chain and
> NRV values, but while testing updated patch I also found that it has no
> measurable effect on cc1plus and I failed to construct testcase where
> handling of EAF_DIRECT would do somehting useful.  The points-to set
> of returned value contains all eascape and nonlocal solutions (as it
> should).  So I decided to commit only the EAF_UNUSED part. As it stands
> EAF_DIRECT handling only makes constraint graph bigger for no much
> benefit.
>
> I think to make return values useful we need to also use the info about
> global memory uses.  This is easilly available from modref but doing so
> seems non-trivial since pure functions can return addresses of global
> symbols but NONLOCAL solution is too big for that.

Well, pure can even return the address of escaped things.

int *p;

int *foo () { return p; } // pure

int main()
{
  int i;
  p = &i;
  if (foo () != &i)
    abort ();
}

so ESCAPED would be correct and even larger than NONLOCAL.

> Honza
>
>         * tree-ssa-structalias.c (handle_pure_call): Skip EAF_UNUSED
>          parameters.
> diff --git a/gcc/tree-ssa-structalias.c b/gcc/tree-ssa-structalias.c
> index 9f4de96d544..cf653be8b6d 100644
> --- a/gcc/tree-ssa-structalias.c
> +++ b/gcc/tree-ssa-structalias.c
> @@ -4274,6 +4274,11 @@ handle_pure_call (gcall *stmt, vec<ce_s> *results)
>    for (i = 0; i < gimple_call_num_args (stmt); ++i)
>      {
>        tree arg = gimple_call_arg (stmt, i);
> +      int flags = gimple_call_arg_flags (stmt, i);
> +
> +      /* If the argument is not used we can ignore it.  */
> +      if (flags & EAF_UNUSED)
> +       continue;
>        if (!uses)
>         {
>           uses = get_call_use_vi (stmt);

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-11-30 10:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-25 14:13 Handle EAF_DIRECT and EAF_UNUSED of pure calls Jan Hubicka
2020-11-25 14:30 ` Richard Biener
2020-11-29 15:37   ` Jan Hubicka
2020-11-30  9:59     ` Richard Biener

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).