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 b7d3cc6..824e635 100644 (file)
@@ -1,5 +1,11 @@
 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.
        (aarch64_expand_mov_immediate): Use it when attempting to measure
        the length of an SVE vector.
index 02daacd..d7a77a9 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 f4a5bb2..8dd2633 100644 (file)
@@ -1,5 +1,10 @@
 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.
        * gcc.target/aarch64/sve/acle/general/nosve_5.c: Likewise.
        * gcc.target/aarch64/sve/pcs/nosve_4.c: Expected a second error
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);
+}