public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Sandiford <richard.sandiford@linaro.org>
To: gcc-patches@gcc.gnu.org
Subject: Fixed incorrect TARGET_MEM_REF alignment (PR 84419)
Date: Tue, 20 Feb 2018 09:43:00 -0000	[thread overview]
Message-ID: <87po50ro6r.fsf@linaro.org> (raw)

expand_call_mem_ref checks for TARGET_MEM_REFs that have compatible
type, but it didn't then go on to install the specific type we need,
which might have different alignment due to:

  if (TYPE_ALIGN (type) != align)
    type = build_aligned_type (type, align);

This was causing masked stores to be incorrectly marked as
aligned on AVX512.

Tested on aarch64-linux-gnu, x86_64-linux-gnu and powerpc64-linux-gnu.
Also tested by Alexander on AVX512 hw.  OK to install?

Richard


2018-02-20  Richard Sandiford  <richard.sandiford@linaro.org>

gcc/
	PR tree-optimization/84419
	* internal-fn.c (expand_call_mem_ref): Create a TARGET_MEM_REF
	with the required type if its current type is compatible but
	different.

gcc/testsuite/
	PR tree-optimization/84419
	* gcc.dg/vect/pr84419.c: New test.

Index: gcc/internal-fn.c
===================================================================
--- gcc/internal-fn.c	2018-01-13 18:01:51.235735290 +0000
+++ gcc/internal-fn.c	2018-02-20 09:40:47.547217244 +0000
@@ -2444,11 +2444,14 @@ expand_call_mem_ref (tree type, gcall *s
 	  && types_compatible_p (TREE_TYPE (mem), type))
 	{
 	  tree offset = TMR_OFFSET (mem);
-	  if (alias_ptr_type != TREE_TYPE (offset) || !integer_zerop (offset))
+	  if (type != TREE_TYPE (mem)
+	      || alias_ptr_type != TREE_TYPE (offset)
+	      || !integer_zerop (offset))
 	    {
 	      mem = copy_node (mem);
 	      TMR_OFFSET (mem) = wide_int_to_tree (alias_ptr_type,
 						   wi::to_poly_wide (offset));
+	      TREE_TYPE (mem) = type;
 	    }
 	  return mem;
 	}
Index: gcc/testsuite/gcc.dg/vect/pr84419.c
===================================================================
--- /dev/null	2018-02-19 19:34:42.906488063 +0000
+++ gcc/testsuite/gcc.dg/vect/pr84419.c	2018-02-20 09:40:47.548217201 +0000
@@ -0,0 +1,21 @@
+#include <string.h>
+
+#define SIZE 400
+
+int  foo[SIZE];
+char bar[SIZE];
+
+void __attribute__ ((noinline)) foo_func(void)
+{
+  int i;
+  for (i = 1; i < SIZE; i++)
+    if (bar[i])
+      foo[i] = 1;
+}
+
+int main()
+{
+  memset(bar, 1, sizeof(bar));
+  foo_func();
+  return 0;
+}

             reply	other threads:[~2018-02-20  9:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-20  9:43 Richard Sandiford [this message]
2018-02-20 13:25 ` Richard Biener

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=87po50ro6r.fsf@linaro.org \
    --to=richard.sandiford@linaro.org \
    --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).