https://gcc.gnu.org/g:c06252ee5215bfb58ad97a8636234fc67318e052
commit r17-5667-gc06252ee5215bfb58ad97a8636234fc67318e052 Author: Richard Biener <[email protected]> Date: Wed Oct 28 11:40:37 2026 +0100 tree-optimization/128225 - ICE with OMP inbranch simd clone 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 for !VECTOR_BOOLEAN_TYPE_P 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. For the VECTOR_BOOLEAN_TYPE_P case only re-construct mask types with a vector mode which matches the aarch64 case we do this dance for. I've also filled a hole of mask-mode verification for inbranch clone use for a not-inbranch use. PR tree-optimization/128225 * tree-vect-stmts.cc (vectorizable_simd_clone_call): Only use build_truth_vector_type_for_mode for vector mode vector boolean types. 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. Diff: --- .../gcc.dg/vect/vect-simd-clone-pr128225.c | 14 ++++++++++++ gcc/tree-vect-stmts.cc | 26 ++++++++++++++-------- 2 files changed, 31 insertions(+), 9 deletions(-) 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 000000000000..b7a383ffc12e --- /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 38f9ad01e87b..0a884d491e33 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; @@ -4492,15 +4495,20 @@ vectorizable_simd_clone_call (vec_info *vinfo, stmt_vec_info stmt_info, else { masktype = bestn_inbranch->simdclone->args[i].vector_type; - /* The aarch64 port will add custom attributes to types - for SVE simdclones which make the types different. We - 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)); + if (VECTOR_BOOLEAN_TYPE_P (masktype)) + { + if (VECTOR_MODE_P (TYPE_MODE (masktype))) + /* The aarch64 port will add custom attributes to + types for SVE simdclones which make the types + different. We should use canonincal types for + masks within the vectorizer, hence we + re-construct the vectype from its mode. */ + masktype = build_truth_vector_type_for_mode + (TYPE_VECTOR_SUBPARTS (masktype), + TYPE_MODE (masktype)); + } + else + masktype = truth_type_for (masktype); callee_nelements = TYPE_VECTOR_SUBPARTS (masktype); } if (!masktype)
