public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-4849] addS EAF_NOT_RETURNED_DIRECTLY
@ 2021-11-02 17:44 Jan Hubicka
  0 siblings, 0 replies; only message in thread
From: Jan Hubicka @ 2021-11-02 17:44 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:f19791565d7ed31c2a895fc29b772c2c7ed390e8

commit r12-4849-gf19791565d7ed31c2a895fc29b772c2c7ed390e8
Author: Jan Hubicka <hubicka@ucw.cz>
Date:   Tue Nov 2 18:43:17 2021 +0100

    addS EAF_NOT_RETURNED_DIRECTLY
    
    addS EAF_NOT_RETURNED_DIRECTLY which works similarly as
    EAF_NODIRECTESCAPE.  Values pointed to by a given argument may be returned but
    not the argument itself.  This helps PTA quite noticeably because we mostly
    care about tracking points to which given memory location can escape.
    
    gcc/ChangeLog:
    
            * tree-core.h (EAF_NOT_RETURNED_DIRECTLY): New flag.
            (EAF_NOREAD): Renumber.
            * ipa-modref.c (dump_eaf_flags): Dump EAF_NOT_RETURNED_DIRECTLY.
            (remove_useless_eaf_flags): Handle EAF_NOT_RETURNED_DIRECTLY
            (deref_flags): Likewise.
            (modref_lattice::init): Likewise.
            (modref_lattice::merge): Likewise.
            (merge_call_lhs_flags): Likewise.
            (analyze_ssa_name_flags): Likewise.
            (modref_merge_call_site_flags): Likewise.
            * tree-ssa-structalias.c (handle_call_arg): Likewise.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/ipa/modref-1.C: Update template.
            * gcc.dg/tree-ssa/modref-10.c: New test.

Diff:
---
 gcc/ipa-modref.c                          | 39 ++++++++++++++++++++++---------
 gcc/testsuite/g++.dg/ipa/modref-1.C       |  2 +-
 gcc/testsuite/gcc.dg/tree-ssa/modref-10.c | 20 ++++++++++++++++
 gcc/tree-core.h                           |  6 ++++-
 gcc/tree-ssa-structalias.c                | 12 ++++++++--
 5 files changed, 64 insertions(+), 15 deletions(-)

diff --git a/gcc/ipa-modref.c b/gcc/ipa-modref.c
index d866d9ed6b3..c0aae084dbd 100644
--- a/gcc/ipa-modref.c
+++ b/gcc/ipa-modref.c
@@ -160,6 +160,8 @@ dump_eaf_flags (FILE *out, int flags, bool newline = true)
     fprintf (out, " unused");
   if (flags & EAF_NOT_RETURNED)
     fprintf (out, " not_returned");
+  if (flags & EAF_NOT_RETURNED_DIRECTLY)
+    fprintf (out, " not_returned_directly");
   if (flags & EAF_NOREAD)
     fprintf (out, " noread");
   if (newline)
@@ -295,7 +297,7 @@ remove_useless_eaf_flags (int eaf_flags, int ecf_flags, bool returns_void)
   else if (ecf_flags & ECF_PURE)
     eaf_flags &= ~implicit_pure_eaf_flags;
   else if ((ecf_flags & ECF_NORETURN) || returns_void)
-    eaf_flags &= ~EAF_NOT_RETURNED;
+    eaf_flags &= ~(EAF_NOT_RETURNED | EAF_NOT_RETURNED_DIRECTLY);
   return eaf_flags;
 }
 
@@ -1373,7 +1375,7 @@ memory_access_to (tree op, tree ssa_name)
 static int
 deref_flags (int flags, bool ignore_stores)
 {
-  int ret = EAF_NODIRECTESCAPE;
+  int ret = EAF_NODIRECTESCAPE | EAF_NOT_RETURNED_DIRECTLY;
   /* If argument is unused just account for
      the read involved in dereference.  */
   if (flags & EAF_UNUSED)
@@ -1458,7 +1460,8 @@ modref_lattice::init ()
 {
   /* All flags we track.  */
   int f = EAF_DIRECT | EAF_NOCLOBBER | EAF_NOESCAPE | EAF_UNUSED
-	  | EAF_NODIRECTESCAPE | EAF_NOT_RETURNED | EAF_NOREAD;
+	  | EAF_NODIRECTESCAPE | EAF_NOT_RETURNED |
+	  EAF_NOT_RETURNED_DIRECTLY | EAF_NOREAD;
   flags = f;
   /* Check that eaf_flags_t is wide enough to hold all flags.  */
   gcc_checking_assert (f == flags);
@@ -1540,6 +1543,8 @@ modref_lattice::merge (int f)
      Fnspec machinery does set both so compensate for this.  */
   if (f & EAF_NOESCAPE)
     f |= EAF_NODIRECTESCAPE;
+  if (f & EAF_NOT_RETURNED)
+    f |= EAF_NOT_RETURNED_DIRECTLY;
   if ((flags & f) != flags)
     {
       flags &= f;
@@ -1647,7 +1652,9 @@ merge_call_lhs_flags (gcall *call, int arg, int index, bool deref,
       && (flags & ERF_RETURN_ARG_MASK) != arg)
     return;
 
-  if (gimple_call_arg_flags (call, arg) & (EAF_NOT_RETURNED | EAF_UNUSED))
+  int eaf_flags = gimple_call_arg_flags (call, arg);
+
+  if (eaf_flags & (EAF_NOT_RETURNED | EAF_UNUSED))
     return;
 
   /* If return value is SSA name determine its flags.  */
@@ -1655,12 +1662,14 @@ merge_call_lhs_flags (gcall *call, int arg, int index, bool deref,
     {
       tree lhs = gimple_call_lhs (call);
       analyze_ssa_name_flags (lhs, lattice, depth + 1, ipa);
-      if (deref)
+      if (deref || (eaf_flags & EAF_NOT_RETURNED_DIRECTLY))
 	lattice[index].merge_deref (lattice[SSA_NAME_VERSION (lhs)], false);
       else
 	lattice[index].merge (lattice[SSA_NAME_VERSION (lhs)]);
     }
   /* In the case of memory store we can do nothing.  */
+  else if (eaf_flags & EAF_NOT_RETURNED_DIRECTLY)
+    lattice[index].merge (deref_flags (0, false));
   else
     lattice[index].merge (0);
 }
@@ -1731,11 +1740,13 @@ analyze_ssa_name_flags (tree name, vec<modref_lattice> &lattice, int depth,
 	      && DECL_BY_REFERENCE (DECL_RESULT (current_function_decl)))
 	    ;
 	  else if (gimple_return_retval (ret) == name)
-	    lattice[index].merge (~(EAF_UNUSED | EAF_NOT_RETURNED));
+	    lattice[index].merge (~(EAF_UNUSED | EAF_NOT_RETURNED
+				    | EAF_NOT_RETURNED_DIRECTLY));
 	  else if (memory_access_to (gimple_return_retval (ret), name))
 	    {
 	      lattice[index].merge_direct_load ();
-	      lattice[index].merge (~(EAF_UNUSED | EAF_NOT_RETURNED));
+	      lattice[index].merge (~(EAF_UNUSED | EAF_NOT_RETURNED
+				      | EAF_NOT_RETURNED_DIRECTLY));
 	    }
 	}
       /* Account for LHS store, arg loads and flags from callee function.  */
@@ -1794,7 +1805,8 @@ analyze_ssa_name_flags (tree name, vec<modref_lattice> &lattice, int depth,
 		    if (!(ecf_flags & (ECF_CONST | ECF_NOVOPS)))
 		      {
 			int call_flags = gimple_call_arg_flags (call, i)
-					 | EAF_NOT_RETURNED;
+					 | EAF_NOT_RETURNED
+					 | EAF_NOT_RETURNED_DIRECTLY;
 			if (ignore_stores)
 			  call_flags |= ignore_stores_eaf_flags;
 
@@ -1817,7 +1829,8 @@ analyze_ssa_name_flags (tree name, vec<modref_lattice> &lattice, int depth,
 		      {
 			int call_flags = deref_flags
 			   (gimple_call_arg_flags (call, i)
-			    | EAF_NOT_RETURNED, ignore_stores);
+			    | EAF_NOT_RETURNED
+			    | EAF_NOT_RETURNED_DIRECTLY, ignore_stores);
 			if (!record_ipa)
 			  lattice[index].merge (call_flags);
 			else
@@ -3858,14 +3871,18 @@ modref_merge_call_site_flags (escape_summary *sum,
 	  flags_lto |= ignore_stores_eaf_flags;
 	}
       /* Returning the value is already accounted to at local propagation.  */
-      flags |= ee->min_flags | EAF_NOT_RETURNED;
-      flags_lto |= ee->min_flags | EAF_NOT_RETURNED;
+      flags |= ee->min_flags | EAF_NOT_RETURNED | EAF_NOT_RETURNED_DIRECTLY;
+      flags_lto |= ee->min_flags | EAF_NOT_RETURNED | EAF_NOT_RETURNED_DIRECTLY;
       /* Noescape implies that value also does not escape directly.
 	 Fnspec machinery does set both so compensate for this.  */
       if (flags & EAF_NOESCAPE)
 	flags |= EAF_NODIRECTESCAPE;
       if (flags_lto & EAF_NOESCAPE)
 	flags_lto |= EAF_NODIRECTESCAPE;
+      if (flags & EAF_NOT_RETURNED)
+	flags |= EAF_NOT_RETURNED_DIRECTLY;
+      if (flags_lto & EAF_NOT_RETURNED)
+	flags_lto |= EAF_NOT_RETURNED_DIRECTLY;
       if (!(flags & EAF_UNUSED)
 	  && cur_summary && ee->parm_index < (int)cur_summary->arg_flags.length ())
 	{
diff --git a/gcc/testsuite/g++.dg/ipa/modref-1.C b/gcc/testsuite/g++.dg/ipa/modref-1.C
index 0acae2114dd..eaa14ea5c7f 100644
--- a/gcc/testsuite/g++.dg/ipa/modref-1.C
+++ b/gcc/testsuite/g++.dg/ipa/modref-1.C
@@ -31,5 +31,5 @@ int main()
 	return 0;
 }
 /* { dg-final { scan-tree-dump "Function found to be const: {anonymous}::B::genB" "local-pure-const1"  } } */
-/* { dg-final { scan-tree-dump "Retslot flags: direct noescape nodirectescape not_returned noread" "modref1" } } */
+/* { dg-final { scan-tree-dump "Retslot flags: direct noescape nodirectescape not_returned not_returned_directly noread" "modref1" } } */
   
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/modref-10.c b/gcc/testsuite/gcc.dg/tree-ssa/modref-10.c
new file mode 100644
index 00000000000..c608408809d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/modref-10.c
@@ -0,0 +1,20 @@
+/* { dg-do link } */
+/* { dg-options "-O2 -fdump-tree-modref1"  } */
+void linker_error ();
+__attribute__((noinline))
+int *
+test (int **a)
+{
+  return *a;
+}
+int
+main()
+{
+	int val;
+	int *a=&val;
+	int *b = test (&a);
+	if (b == (int *)&a)
+		linker_error ();
+	return 0;
+}
+/* { dg-final { scan-tree-dump "parm 0 flags: noclobber noescape nodirectescape not_returned_directly" "modref1"} } */
diff --git a/gcc/tree-core.h b/gcc/tree-core.h
index d3d2a8d812f..f0c65a25f07 100644
--- a/gcc/tree-core.h
+++ b/gcc/tree-core.h
@@ -117,8 +117,12 @@ struct die_struct;
 /* Nonzero if the argument does not escape to return value.  */
 #define EAF_NOT_RETURNED	(1 << 5)
 
+/* Nonzero if the argument itself does not escape
+   to return value but memory referenced by it may escape.  */
+#define EAF_NOT_RETURNED_DIRECTLY (1 << 6)
+
 /* Nonzero if the argument is not read.  */
-#define EAF_NOREAD		(1 << 6)
+#define EAF_NOREAD		(1 << 7)
 
 /* Call return flags.  */
 /* Mask for the argument number that is returned.  Lower two bits of
diff --git a/gcc/tree-ssa-structalias.c b/gcc/tree-ssa-structalias.c
index 99072df0768..5f24c0171f0 100644
--- a/gcc/tree-ssa-structalias.c
+++ b/gcc/tree-ssa-structalias.c
@@ -4082,8 +4082,16 @@ handle_call_arg (gcall *stmt, tree arg, vec<ce_s> *results, int flags,
     {
       struct constraint_expr cexpr;
       cexpr.var = tem->id;
-      cexpr.type = SCALAR;
-      cexpr.offset = 0;
+      if (flags & EAF_NOT_RETURNED_DIRECTLY)
+	{
+	  cexpr.type = DEREF;
+	  cexpr.offset = UNKNOWN_OFFSET;
+	}
+      else
+	{
+	  cexpr.type = SCALAR;
+	  cexpr.offset = 0;
+	}
       results->safe_push (cexpr);
     }


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-11-02 17:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-02 17:44 [gcc r12-4849] addS EAF_NOT_RETURNED_DIRECTLY Jan Hubicka

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