Tighten check for vector types in fold_convertible_p (PR 92741)
authorRichard Sandiford <richard.sandiford@arm.com>
Mon, 2 Dec 2019 17:51:08 +0000 (17:51 +0000)
committerRichard Sandiford <rsandifo@gcc.gnu.org>
Mon, 2 Dec 2019 17:51:08 +0000 (17:51 +0000)
In this PR, IPA-CP was misled into using NOP_EXPR rather than
VIEW_CONVERT_EXPR to reinterpret a vector of 4 shorts as a vector
of 2 ints.  This tripped the tree-cfg.c assert I'd added in r278245.

2019-12-02  Richard Sandiford  <richard.sandiford@arm.com>

gcc/
PR middle-end/92741
* fold-const.c (fold_convertible_p): Check vector types more
thoroughly.

gcc/testsuite/
PR middle-end/92741
* gcc.dg/pr92741.c: New test.

From-SVN: r278910

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr92741.c [new file with mode: 0644]

index b7d3cc632bcb6ddf2780fc3154e2a9a23e4519c4..824e6356607439f9c33cff7bf813a4de9f7e8ffa 100644 (file)
@@ -1,3 +1,9 @@
+2019-12-02  Richard Sandiford  <richard.sandiford@arm.com>
+
+       PR middle-end/92741
+       * fold-const.c (fold_convertible_p): Check vector types more
+       thoroughly.
+
 2019-12-02  Richard Sandiford  <richard.sandiford@arm.com>
 
        * config/aarch64/aarch64.c (aarch64_report_sve_required): New function.
index 02daacdb36b889ece2f9415095c448c454e084fc..d7a77a9848a7551105302ab8960ba7acade9a9b7 100644 (file)
@@ -2375,10 +2375,15 @@ fold_convertible_p (const_tree type, const_tree arg)
 
     case REAL_TYPE:
     case FIXED_POINT_TYPE:
-    case VECTOR_TYPE:
     case VOID_TYPE:
       return TREE_CODE (type) == TREE_CODE (orig);
 
+    case VECTOR_TYPE:
+      return (VECTOR_TYPE_P (orig)
+             && known_eq (TYPE_VECTOR_SUBPARTS (type),
+                          TYPE_VECTOR_SUBPARTS (orig))
+             && fold_convertible_p (TREE_TYPE (type), TREE_TYPE (orig)));
+
     default:
       return false;
     }
index f4a5bb24e1a7cf5d13a2de4dd80d55a207ebbdb7..8dd2633d6437a33aedbaaa9821c394b9a072d5e1 100644 (file)
@@ -1,3 +1,8 @@
+2019-12-02  Richard Sandiford  <richard.sandiford@arm.com>
+
+       PR middle-end/92741
+       * gcc.dg/pr92741.c: New test.
+
 2019-12-02  Richard Sandiford  <richard.sandiford@arm.com>
 
        * gcc.target/aarch64/sve/acle/general/nosve_4.c: New test.
diff --git a/gcc/testsuite/gcc.dg/pr92741.c b/gcc/testsuite/gcc.dg/pr92741.c
new file mode 100644 (file)
index 0000000..8524c86
--- /dev/null
@@ -0,0 +1,19 @@
+/* { dg-options "-O2 -fexceptions -fnon-call-exceptions -fno-inline" } */
+
+typedef int vh __attribute__ ((__vector_size__ (2 * sizeof (int))));
+typedef short int cq __attribute__ ((__vector_size__ (4 * sizeof (short int))));
+
+static void
+id (int *r8, vh *tu)
+{
+  *(vh *) r8 = *tu;
+}
+
+void
+mr (void)
+{
+  int r8;
+  cq he = { 0, };
+
+  id (&r8, (vh *) &he);
+}