From e034c5c895722e0092d2239cd8c2991db77d6d39 Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>
Date: Sat, 2 Dec 2017 08:54:47 +0100
Subject: [PATCH] re PR target/78643 (ICE in convert_move, at expr.c:230)

	PR target/78643
	PR target/80583
	* expr.c (get_inner_reference): If DECL_MODE of a non-bitfield
	is BLKmode for vector field with vector raw mode, use TYPE_MODE
	instead of DECL_MODE.

	* gcc.target/i386/pr80583.c: New test.

From-SVN: r255353
---
 gcc/ChangeLog                           |  6 ++++++
 gcc/expr.c                              | 11 ++++++++++-
 gcc/testsuite/ChangeLog                 |  6 ++++++
 gcc/testsuite/gcc.target/i386/pr80583.c | 13 +++++++++++++
 4 files changed, 35 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr80583.c

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index de7335efa40c..9536a88b8a9e 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,11 @@
 2017-12-02  Jakub Jelinek  <jakub@redhat.com>
 
+	PR target/78643
+	PR target/80583
+	* expr.c (get_inner_reference): If DECL_MODE of a non-bitfield
+	is BLKmode for vector field with vector raw mode, use TYPE_MODE
+	instead of DECL_MODE.
+
 	* config/i386/i386-protos.h (standard_sse_constant_opcode): Change
 	last argument to rtx pointer.
 	* config/i386/i386.c (standard_sse_constant_opcode): Replace X argument
diff --git a/gcc/expr.c b/gcc/expr.c
index e9d8555c9452..80116381f1b7 100644
--- a/gcc/expr.c
+++ b/gcc/expr.c
@@ -7032,7 +7032,16 @@ get_inner_reference (tree exp, HOST_WIDE_INT *pbitsize,
 	     size.  */
 	mode = TYPE_MODE (DECL_BIT_FIELD_TYPE (field));
       else if (!DECL_BIT_FIELD (field))
-	mode = DECL_MODE (field);
+	{
+	  mode = DECL_MODE (field);
+	  /* For vector fields re-check the target flags, as DECL_MODE
+	     could have been set with different target flags than
+	     the current function has.  */
+	  if (mode == BLKmode
+	      && VECTOR_TYPE_P (TREE_TYPE (field))
+	      && VECTOR_MODE_P (TYPE_MODE_RAW (TREE_TYPE (field))))
+	    mode = TYPE_MODE (TREE_TYPE (field));
+	}
       else if (DECL_MODE (field) == BLKmode)
 	blkmode_bitfield = true;
 
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 8133e8af91a0..49f0409a24aa 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2017-12-02  Jakub Jelinek  <jakub@redhat.com>
+
+	PR target/78643
+	PR target/80583
+	* gcc.target/i386/pr80583.c: New test.
+
 2017-12-01  Segher Boessenkool  <segher@kernel.crashing.org>
 
 	* gcc.target/powerpc/fusion.c: Add -dp to options.  Adjust the expected
diff --git a/gcc/testsuite/gcc.target/i386/pr80583.c b/gcc/testsuite/gcc.target/i386/pr80583.c
new file mode 100644
index 000000000000..6fe3212b65ce
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr80583.c
@@ -0,0 +1,13 @@
+/* PR target/80583 */
+/* { dg-do compile } */
+/* { dg-options "-O0 -mno-avx" } */
+
+typedef int V __attribute__((__vector_size__(32)));
+struct S { V a; };
+
+V __attribute__((target ("avx")))
+foo (struct S *b)
+{
+  V x = b->a;
+  return x;
+}
-- 
GitLab