This adds a missing check on supportability of a VEC_COND_EXPR
to a match.pd pattern.  The existing conditions, in particular
known_eq of TYPE_VECTOR_SUBPARTS, is not enough to distinguish
VNx4SImode from V4SImode with -msve-vector-bits=128.

Bootstrap and regtest running on x86_64-unknown-linux-gnu.

        PR middle-end/123775
        * match.pd ((view_convert (vec_cond ...))): Make sure the
        resulting vec_cond can be expanded.

        * gcc.target/aarch64/sve2/pr123775.c: New testcase.
---
 gcc/match.pd                                  |  4 +-
 .../gcc.target/aarch64/sve2/pr123775.c        | 37 +++++++++++++++++++
 2 files changed, 40 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.target/aarch64/sve2/pr123775.c

diff --git a/gcc/match.pd b/gcc/match.pd
index e0a2399ca65..155658fe2c8 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -6258,7 +6258,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (if (VECTOR_TYPE_P (type) && VECTOR_TYPE_P (TREE_TYPE (@1))
       && known_eq (TYPE_VECTOR_SUBPARTS (type),
                   TYPE_VECTOR_SUBPARTS (TREE_TYPE (@1)))
-      && tree_nop_conversion_p (TREE_TYPE (type), TREE_TYPE (TREE_TYPE (@1))))
+      && tree_nop_conversion_p (TREE_TYPE (type), TREE_TYPE (TREE_TYPE (@1)))
+      && (expand_vec_cond_expr_p (type, TREE_TYPE (@0))
+         || !expand_vec_cond_expr_p (TREE_TYPE (@1), TREE_TYPE (@0))))
   (vec_cond @0 (view_convert! @1) (view_convert! @2))))
 
 /* Sink binary operation to branches, but only if we can fold it.  */
diff --git a/gcc/testsuite/gcc.target/aarch64/sve2/pr123775.c 
b/gcc/testsuite/gcc.target/aarch64/sve2/pr123775.c
new file mode 100644
index 00000000000..ba292045a18
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/sve2/pr123775.c
@@ -0,0 +1,37 @@
+/* { dg-do run } */
+/* { dg-additional-options "-O3 -march=armv9-a+sve2 -msve-vector-bits=128 
--param aarch64-autovec-preference=sve-only" } */
+
+int main(int argc, char *argv[]) {
+
+    __attribute__((vector_size((4) * sizeof(int)))) int i0;
+    __attribute__((vector_size((4) * sizeof(int)))) int i1;
+    __attribute__((vector_size((4) * sizeof(int)))) int ires;
+    int i;
+
+    i0 = (__attribute__((vector_size((4) * sizeof(int)))) int){(int)argc, 1, 2,
+                                                               10};
+    i1 = (__attribute__((vector_size((4) * sizeof(int)))) int){0, 3, 2,
+                                                               (int)-23};
+    ;
+    do {
+        ires = (i0 > i1);
+        do {
+            int __i;
+            for (__i = 0; __i < 4; __i++) {
+                if ((ires)[__i] != ((i0)[__i] > (i1)[__i] ? -1 : 0)) {
+                    __builtin_printf("%i != (("
+                                     "%i"
+                                     " "
+                                     ">"
+                                     " "
+                                     "%i"
+                                     " ? -1 : 0) ",
+                                     (ires)[__i], (i0)[__i], (i1)[__i]);
+                    __builtin_abort();
+                }
+            }
+        } while (0);
+    } while (0);
+
+    return 0;
+}
-- 
2.51.0

Reply via email to