public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] Add alias disambiguation for vectorizer load/store IFNs
Date: Thu, 21 Jul 2022 09:01:07 +0200 (CEST)	[thread overview]
Message-ID: <20220721070107.95AEC139FC@imap2.suse-dmz.suse.de> (raw)

The following adds support for MASK_STORE, MASK_LOAD and friends
to call_may_clobber_ref_p and ref_maybe_used_by_call_p.  Since
they all use a special argument to specify TBAA they are not really
suited for fnspec handling thus the manual support.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

PR106365 shows this can be important though in many cases seen there
we miss PTA info.

	* tree-ssa-alias.cc (ref_maybe_used_by_call_p_1): Special-case
	store internal functions and IFN_MASK_LOAD, IFN_LEN_LOAD
	and IFN_MASK_LOAD_LANES.
	(call_may_clobber_ref_p_1): Special-case IFN_MASK_STORE,
	IFN_LEN_STORE and IFN_MASK_STORE_LANES.
---
 gcc/tree-ssa-alias.cc | 49 +++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 47 insertions(+), 2 deletions(-)

diff --git a/gcc/tree-ssa-alias.cc b/gcc/tree-ssa-alias.cc
index 782266bdad8..390cd875074 100644
--- a/gcc/tree-ssa-alias.cc
+++ b/gcc/tree-ssa-alias.cc
@@ -47,6 +47,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "print-tree.h"
 #include "tree-ssa-alias-compare.h"
 #include "builtins.h"
+#include "internal-fn.h"
 
 /* Broad overview of how alias analysis on gimple works:
 
@@ -2793,8 +2794,38 @@ ref_maybe_used_by_call_p_1 (gcall *call, ao_ref *ref, bool tbaa_p)
   if (ref->volatile_p)
     return true;
 
-  callee = gimple_call_fndecl (call);
+  if (gimple_call_internal_p (call))
+    switch (gimple_call_internal_fn (call))
+      {
+      case IFN_MASK_STORE:
+      case IFN_SCATTER_STORE:
+      case IFN_MASK_SCATTER_STORE:
+      case IFN_LEN_STORE:
+	return false;
+      case IFN_MASK_STORE_LANES:
+	goto process_args;
+      case IFN_MASK_LOAD:
+      case IFN_LEN_LOAD:
+      case IFN_MASK_LOAD_LANES:
+	{
+	  ao_ref rhs_ref;
+	  tree lhs = gimple_call_lhs (call);
+	  if (lhs)
+	    {
+	      ao_ref_init_from_ptr_and_size (&rhs_ref,
+					     gimple_call_arg (call, 0),
+					     TYPE_SIZE_UNIT (TREE_TYPE (lhs)));
+	      rhs_ref.ref_alias_set = rhs_ref.base_alias_set
+		= tbaa_p ? get_deref_alias_set (TREE_TYPE
+					(gimple_call_arg (call, 1))) : 0;
+	      return refs_may_alias_p_1 (ref, &rhs_ref, tbaa_p);
+	    }
+	  break;
+	}
+      default:;
+      }
 
+  callee = gimple_call_fndecl (call);
   if (callee != NULL_TREE)
     {
       struct cgraph_node *node = cgraph_node::get (callee);
@@ -3005,7 +3036,7 @@ call_may_clobber_ref_p_1 (gcall *call, ao_ref *ref, bool tbaa_p)
       & (ECF_PURE|ECF_CONST|ECF_LOOPING_CONST_OR_PURE|ECF_NOVOPS))
     return false;
   if (gimple_call_internal_p (call))
-    switch (gimple_call_internal_fn (call))
+    switch (auto fn = gimple_call_internal_fn (call))
       {
 	/* Treat these internal calls like ECF_PURE for aliasing,
 	   they don't write to any memory the program should care about.
@@ -3018,6 +3049,20 @@ call_may_clobber_ref_p_1 (gcall *call, ao_ref *ref, bool tbaa_p)
       case IFN_UBSAN_PTR:
       case IFN_ASAN_CHECK:
 	return false;
+      case IFN_MASK_STORE:
+      case IFN_LEN_STORE:
+      case IFN_MASK_STORE_LANES:
+	{
+	  tree rhs = gimple_call_arg (call,
+				      internal_fn_stored_value_index (fn));
+	  ao_ref lhs_ref;
+	  ao_ref_init_from_ptr_and_size (&lhs_ref, gimple_call_arg (call, 0),
+					 TYPE_SIZE_UNIT (TREE_TYPE (rhs)));
+	  lhs_ref.ref_alias_set = lhs_ref.base_alias_set
+	    = tbaa_p ? get_deref_alias_set
+				   (TREE_TYPE (gimple_call_arg (call, 1))) : 0;
+	  return refs_may_alias_p_1 (ref, &lhs_ref, tbaa_p);
+	}
       default:
 	break;
       }
-- 
2.35.3

                 reply	other threads:[~2022-07-21  7:01 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=20220721070107.95AEC139FC@imap2.suse-dmz.suse.de \
    --to=rguenther@suse.de \
    --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).