diff mbox series

Handle EAF_DIRECT and EAF_UNUSED of pure calls

Message ID 20201125141320.GB41776@kam.mff.cuni.cz
State New
Headers show
Series Handle EAF_DIRECT and EAF_UNUSED of pure calls | expand

Commit Message

Jan Hubicka Nov. 25, 2020, 2:13 p.m. UTC
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

Comments

Richard Biener Nov. 25, 2020, 2:30 p.m. UTC | #1
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);
>      }
>
Jan Hubicka Nov. 29, 2020, 3:37 p.m. UTC | #2
> 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);
Richard Biener Nov. 30, 2020, 9:59 a.m. UTC | #3
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);
diff mbox series

Patch

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);
     }