public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Andreas Krebbel <krebbel@linux.ibm.com>
To: gcc-patches@gcc.gnu.org
Cc: Jakub Jelinek <jakub@redhat.com>
Subject: [Committed] s390x: Fix vec_xl/vec_xst type aliasing [PR114676]
Date: Tue, 23 Apr 2024 10:18:47 +0200	[thread overview]
Message-ID: <20240423081847.28312-1-krebbel@linux.ibm.com> (raw)

The requirements of the vec_xl/vec_xst intrinsincs wrt aliasing of the
pointer argument are not really documented.  As it turns out, users
are likely to get it wrong.  With this patch we let the pointer
argument alias everything in order to make it more robust for users.

Committed to mainline. Will be cherry-picked for stable branches as well.

gcc/ChangeLog:

	PR target/114676
	* config/s390/s390-c.cc (s390_expand_overloaded_builtin): Use a
	MEM_REF with an addend of type ptr_type_node.

gcc/testsuite/ChangeLog:

	PR target/114676
	* gcc.target/s390/zvector/pr114676.c: New test.

Suggested-by: Jakub Jelinek <jakub@redhat.com>
---
 gcc/config/s390/s390-c.cc                     | 16 +++++++++-------
 .../gcc.target/s390/zvector/pr114676.c        | 19 +++++++++++++++++++
 2 files changed, 28 insertions(+), 7 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/s390/zvector/pr114676.c

diff --git a/gcc/config/s390/s390-c.cc b/gcc/config/s390/s390-c.cc
index 8d3d1a467a8..1bb6e810766 100644
--- a/gcc/config/s390/s390-c.cc
+++ b/gcc/config/s390/s390-c.cc
@@ -498,11 +498,11 @@ s390_expand_overloaded_builtin (location_t loc,
 	/* Build a vector type with the alignment of the source
 	   location in order to enable correct alignment hints to be
 	   generated for vl.  */
-	tree mem_type = build_aligned_type (return_type,
-					    TYPE_ALIGN (TREE_TYPE (TREE_TYPE ((*arglist)[1]))));
+	unsigned align = TYPE_ALIGN (TREE_TYPE (TREE_TYPE ((*arglist)[1])));
+	tree mem_type = build_aligned_type (return_type, align);
 	return build2 (MEM_REF, mem_type,
 		       fold_build_pointer_plus ((*arglist)[1], (*arglist)[0]),
-		       build_int_cst (TREE_TYPE ((*arglist)[1]), 0));
+		       build_int_cst (ptr_type_node, 0));
       }
     case S390_OVERLOADED_BUILTIN_s390_vec_xst:
     case S390_OVERLOADED_BUILTIN_s390_vec_xstd2:
@@ -511,11 +511,13 @@ s390_expand_overloaded_builtin (location_t loc,
 	/* Build a vector type with the alignment of the target
 	   location in order to enable correct alignment hints to be
 	   generated for vst.  */
-	tree mem_type = build_aligned_type (TREE_TYPE((*arglist)[0]),
-					    TYPE_ALIGN (TREE_TYPE (TREE_TYPE ((*arglist)[2]))));
+	unsigned align = TYPE_ALIGN (TREE_TYPE (TREE_TYPE ((*arglist)[2])));
+	tree mem_type = build_aligned_type (TREE_TYPE ((*arglist)[0]), align);
 	return build2 (MODIFY_EXPR, mem_type,
-		       build1 (INDIRECT_REF, mem_type,
-			       fold_build_pointer_plus ((*arglist)[2], (*arglist)[1])),
+		       build2 (MEM_REF, mem_type,
+			       fold_build_pointer_plus ((*arglist)[2],
+							(*arglist)[1]),
+			       build_int_cst (ptr_type_node, 0)),
 		       (*arglist)[0]);
       }
     case S390_OVERLOADED_BUILTIN_s390_vec_load_pair:
diff --git a/gcc/testsuite/gcc.target/s390/zvector/pr114676.c b/gcc/testsuite/gcc.target/s390/zvector/pr114676.c
new file mode 100644
index 00000000000..bdc66b2920a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/zvector/pr114676.c
@@ -0,0 +1,19 @@
+/* { dg-do run { target { s390*-*-* } } } */
+/* { dg-options "-O3 -mzarch -march=z14 -mzvector" } */
+
+#include <vecintrin.h>
+
+void __attribute__((noinline)) foo (int *mem)
+{
+  vec_xst ((vector float){ 1.0f, 2.0f, 3.0f, 4.0f }, 0, (float*)mem);
+}
+
+int
+main ()
+{
+  int m[4] = { 0 };
+  foo (m);
+  if (m[3] == 0)
+    __builtin_abort ();
+  return 0;
+}
-- 
2.44.0


                 reply	other threads:[~2024-04-23  8:18 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=20240423081847.28312-1-krebbel@linux.ibm.com \
    --to=krebbel@linux.ibm.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    /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).