public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jan Hubicka <hubicka@kam.mff.cuni.cz>
To: gcc-patches@gcc.gnu.org
Subject: Fix modref and hadnling of some builtins
Date: Sat, 13 Nov 2021 01:52:06 +0100	[thread overview]
Message-ID: <20211113005206.GA15769@kam.mff.cuni.cz> (raw)

Hi,
ipa-modref gets confused by EAF flags of memcpy becuase parameter 1 is
escaping but used only directly.  In modref we do not track values saved to
memory and thus we clear all other flags on each store.  This needs to also
happen when called function escapes parameter.

gcc/ChangeLog:

	PR tree-optimization/103182
	* ipa-modref.c (callee_to_caller_flags): Fix merging of flags.
	(modref_eaf_analysis::analyze_ssa_name): Fix merging of flags.

diff --git a/gcc/ipa-modref.c b/gcc/ipa-modref.c
index e999c2c5d1e..90985cc1326 100644
--- a/gcc/ipa-modref.c
+++ b/gcc/ipa-modref.c
@@ -1888,19 +1888,18 @@ callee_to_caller_flags (int call_flags, bool ignore_stores,
      that is not the same as caller returning it.  */
   call_flags |= EAF_NOT_RETURNED_DIRECTLY
 		| EAF_NOT_RETURNED_INDIRECTLY;
-  /* TODO: We miss return value propagation.
-     Be conservative and if value escapes to memory
-     also mark it as escaping.  */
   if (!ignore_stores && !(call_flags & EAF_UNUSED))
     {
+      /* If value escapes we are no longer able to track what happens
+	 with it because we can read it from the escaped location
+	 anytime.  */
       if (!(call_flags & EAF_NO_DIRECT_ESCAPE))
-	lattice.merge (~(EAF_NOT_RETURNED_DIRECTLY
-			 | EAF_NOT_RETURNED_INDIRECTLY
-			 | EAF_NO_DIRECT_READ
-			 | EAF_UNUSED));
-      if (!(call_flags & EAF_NO_INDIRECT_ESCAPE))
+	lattice.merge (0);
+      else if (!(call_flags & EAF_NO_INDIRECT_ESCAPE))
 	lattice.merge (~(EAF_NOT_RETURNED_INDIRECTLY
 			 | EAF_NO_DIRECT_READ
+			 | EAF_NO_INDIRECT_READ
+			 | EAF_NO_INDIRECT_CLOBBER
 			 | EAF_UNUSED));
     }
   else
@@ -2036,18 +2035,17 @@ modref_eaf_analysis::analyze_ssa_name (tree name)
 			 not_returned and escape has same meaning.
 			 However passing arg to return slot is different.  If
 			 the callee's return slot is returned it means that
-			 arg is written to itself which is an escape.  */
+			 arg is written to itself which is an escape.
+			 Since we do not track the memory it is written to we
+			 need to give up on analysisng it.  */
 		      if (!isretslot)
 			{
 			  if (!(call_flags & (EAF_NOT_RETURNED_DIRECTLY
 					      | EAF_UNUSED)))
-			    m_lattice[index].merge (~(EAF_NO_DIRECT_ESCAPE
-						      | EAF_UNUSED));
-			  if (!(call_flags & (EAF_NOT_RETURNED_INDIRECTLY
-					      | EAF_UNUSED)))
-			    m_lattice[index].merge (~(EAF_NO_INDIRECT_ESCAPE
-						      | EAF_NO_DIRECT_READ
-						      | EAF_UNUSED));
+			    m_lattice[index].merge (0);
+			  else gcc_checking_assert
+				(call_flags & (EAF_NOT_RETURNED_INDIRECTLY
+					       | EAF_UNUSED));
 			  call_flags = callee_to_caller_flags
 					   (call_flags, false,
 					    m_lattice[index]);

                 reply	other threads:[~2021-11-13  0:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20211113005206.GA15769@kam.mff.cuni.cz \
    --to=hubicka@kam.mff.cuni.cz \
    --cc=gcc-patches@gcc.gnu.org \
    /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).