When the SIMD clone mask argument has a vector type with BLKmode we
ICE when attempting to build the respective mask type.  Use
truth_type_for which handles that case just fine and as we are
going to create a all-one constant mask is not an issue if that
were to have BLKmode as well.

I've also filled a hole of mask-mode verification for inbranch
clone use for a not-inbranch use.

Bootstrapped and tested on x86_64-unknown-linux-gnu, queued for pushing.

        PR tree-optimization/128225
        * tree-vect-stmts.cc (vectorizable_simd_clone_call): Use
        truth_type_for instead of build_truth_vector_type_for_mode.
        Check mask_mode of the simdclone is a supported one even
        if the inbranch clone is going to be used for a not-inbranch use.

        * gcc.dg/vect/vect-simd-clone-pr128225.c: New testcase.
---
 .../gcc.dg/vect/vect-simd-clone-pr128225.c         | 14 ++++++++++++++
 gcc/tree-vect-stmts.cc                             |  8 ++++----
 2 files changed, 18 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/vect/vect-simd-clone-pr128225.c

diff --git a/gcc/testsuite/gcc.dg/vect/vect-simd-clone-pr128225.c 
b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-pr128225.c
new file mode 100644
index 00000000000..b7a383ffc12
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-pr128225.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target vect_simd_clones } */
+/* { dg-additional-options "-fopenmp-simd" } */
+/* { dg-additional-options "-mavx2" { target { x86_64-*-* i?86-*-* } } } */
+
+#pragma omp declare simd simdlen(2) inbranch
+extern float clone(double) __attribute__((const));
+
+void use(float *restrict d, const double *restrict a, int n)
+{
+#pragma omp simd
+  for (int i = 0; i < n; i++)
+    d[i] = clone(a[i]);
+}
diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index 38f9ad01e87..d07045e8b72 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -4381,6 +4381,9 @@ vectorizable_simd_clone_call (vec_info *vinfo, 
stmt_vec_info stmt_info,
          {
            gcc_assert (n->simdclone->args[n->simdclone->nargs - 1].arg_type ==
                        SIMD_CLONE_ARG_TYPE_MASK);
+           if (!SCALAR_INT_MODE_P (n->simdclone->mask_mode)
+               && n->simdclone->mask_mode != VOIDmode)
+             continue;
            /* Penalize using a masked SIMD clone in a non-masked loop, that is
               not in a branch, as we'd have to construct an all-true mask.  */
            this_badness += 64;
@@ -4497,10 +4500,7 @@ vectorizable_simd_clone_call (vec_info *vinfo, 
stmt_vec_info stmt_info,
                         should use canonincal types for masks within the
                         vectorizer, hence we construct the related vectype
                         here.  */
-                     masktype
-                       = build_truth_vector_type_for_mode
-                         (TYPE_VECTOR_SUBPARTS (masktype),
-                          TYPE_MODE (masktype));
+                     masktype = truth_type_for (masktype);
                      callee_nelements = TYPE_VECTOR_SUBPARTS (masktype);
                    }
                  if (!masktype)

base-commit: def63f7c26207e4dfefcf5e92c07ea2582474dc5
-- 
2.51.0

Reply via email to