https://gcc.gnu.org/g:2362a925323974dcf00b0bf57ab246e5efcdb2b6

commit r17-5410-g2362a925323974dcf00b0bf57ab246e5efcdb2b6
Author: Richard Biener <[email protected]>
Date:   Tue Oct 20 13:57:37 2026 +0200

    tree-optimization/127978 - OMP simdclone call codegen issue
    
    The accounting of a vector CTOR we have to materialize when
    emitting a simdclone call where the result type differs from
    the chosen vector type is off for the array case.  Simplify it.
    
            PR tree-optimization/127978
            * tree-vect-stmts.cc (vectorizable_simd_clone_call): Simplify
            vector CTOR filling accounting.
    
            * gcc.dg/vect/vect-simd-21.c: New testcase.

Diff:
---
 gcc/testsuite/gcc.dg/vect/vect-simd-21.c | 14 ++++++++++++++
 gcc/tree-vect-stmts.cc                   |  5 +++--
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/vect/vect-simd-21.c 
b/gcc/testsuite/gcc.dg/vect/vect-simd-21.c
new file mode 100644
index 000000000000..3a71e17de7b5
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/vect-simd-21.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-fopenmp-simd" } */
+/* { dg-additional-options "-mavx512vl -mavx512bw -mprefer-vector-width=512" { 
target { avx512bw && avx512vl } } } */
+
+#pragma omp declare simd simdlen(32)
+signed char f(signed char) __attribute__((const));
+
+void g(signed char *d, signed char *a, int *m, int n)
+{
+#pragma omp simd
+  for (int i = 0; i < n; i++)
+    if (m[i])
+      d[i] = f(a[i]);
+}
diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index 785dac775385..b58d974921a4 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -5025,7 +5025,7 @@ vectorizable_simd_clone_call (vec_info *vinfo, 
stmt_vec_info stmt_info,
                                        TYPE_VECTOR_SUBPARTS (rtype), &k))
                gcc_unreachable ();
              gcc_assert ((k & (k - 1)) == 0);
-             if ((j & (k - 1)) == 0)
+             if (!ret_ctor_elts)
                vec_alloc (ret_ctor_elts, k);
              if (ratype)
                {
@@ -5047,12 +5047,13 @@ vectorizable_simd_clone_call (vec_info *vinfo, 
stmt_vec_info stmt_info,
                }
              else
                CONSTRUCTOR_APPEND_ELT (ret_ctor_elts, NULL_TREE, new_temp);
-             if ((j & (k - 1)) != k - 1)
+             if (ret_ctor_elts->length () != k)
                continue;
              vec_oprnd0 = build_constructor (vectype, ret_ctor_elts);
              new_stmt
                = gimple_build_assign (make_ssa_name (vec_dest), vec_oprnd0);
              vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
+             ret_ctor_elts = NULL;
 
              SLP_TREE_VEC_DEFS (slp_node)
                .quick_push (gimple_assign_lhs (new_stmt));

Reply via email to