And for completeness, here the ANY_ACTIVE ifn patch:
Regards
Robin
Subject: [PATCH] ifn/optabs: Add IFN_COND_LEN_ANY_ACTIVE.
This adds a COND_LEN_ANY_ACTIVE internal function that we need for RVV
early-break support. As the scope is currently narrow, I only added the
COND_LEN variant and not the UNCOND or COND variants.
COND_LEN_ANY_ACTIVE is used to reduce a vector mask to a boolean 0 or 1.
Its result is supposed to be used in an early-break loop-exit branch
like
loop:
mask = vec_data CMP key
any_active = COND_LEN_ANY_ACTIVE (mask)
if (any_active)
goto exit1;
gcc/ChangeLog:
* doc/md.texi: Document.
* internal-fn.cc (internal_fn_len_index): Add
COND_LEN_ANY_ACTIVE.
(internal_fn_mask_index): Ditto.
* internal-fn.def (COND_LEN_ANY_ACTIVE): Define.
* optabs.def (OPTAB_D): New optab.
---
gcc/doc/md.texi | 8 ++++++++
gcc/internal-fn.cc | 2 ++
gcc/internal-fn.def | 2 ++
gcc/optabs.def | 1 +
4 files changed, 13 insertions(+)
diff --git a/gcc/doc/md.texi b/gcc/doc/md.texi
index d9b824c6a60..1be79a95eeb 100644
--- a/gcc/doc/md.texi
+++ b/gcc/doc/md.texi
@@ -8840,6 +8840,14 @@ elements whose index is greater than or equal to the sum
of operands 3
and 4. Operand 3 has whichever integer mode the target prefers, and
operand 4 is a bias.
+@mdindex cond_len_any_active_@var{mode}
+@item @samp{cond_len_any_active_@var{mode}}
+Set scalar integer operand 0 to 1 if at least one element of operand 2 is
+active under the mask in operand 1 and has an index less than the sum of
+operands 3 and 4, and to 0 otherwise. Operands 1 and 2 have mode
+@var{mode}, operand 3 has whichever integer mode the target prefers, and
+operand 4 is a bias.
+
@mdindex cond_take_incl_active_@var{mode}
@item @samp{cond_take_incl_active_@var{mode}}
Find the first element that is active in both operands 1 and 2. Under the
diff --git a/gcc/internal-fn.cc b/gcc/internal-fn.cc
index cab2d48b9f5..5f541a64155 100644
--- a/gcc/internal-fn.cc
+++ b/gcc/internal-fn.cc
@@ -5341,6 +5341,7 @@ internal_fn_len_index (internal_fn fn)
case IFN_COND_LEN_COUNT_ACTIVE:
case IFN_COND_LEN_INDEX_FIRST_ACTIVE:
+ case IFN_COND_LEN_ANY_ACTIVE:
return 2;
case IFN_COND_LEN_TAKE_INCL_ACTIVE:
@@ -5491,6 +5492,7 @@ internal_fn_mask_index (internal_fn fn)
case IFN_COND_LEN_COUNT_ACTIVE:
case IFN_COND_INDEX_FIRST_ACTIVE:
case IFN_COND_LEN_INDEX_FIRST_ACTIVE:
+ case IFN_COND_LEN_ANY_ACTIVE:
return 0;
case IFN_COND_VEC_CMP:
diff --git a/gcc/internal-fn.def b/gcc/internal-fn.def
index 257e53a0c6b..4e49851151a 100644
--- a/gcc/internal-fn.def
+++ b/gcc/internal-fn.def
@@ -359,6 +359,8 @@ DEF_INTERNAL_OPTAB_FN (COND_INDEX_FIRST_ACTIVE, ECF_CONST,
cond_index_first_active, cond_mask_unary)
DEF_INTERNAL_OPTAB_FN (COND_LEN_INDEX_FIRST_ACTIVE, ECF_CONST,
cond_len_index_first_active, cond_len_mask_unary)
+DEF_INTERNAL_OPTAB_FN (COND_LEN_ANY_ACTIVE, ECF_CONST,
+ cond_len_any_active, cond_len_mask_unary)
DEF_INTERNAL_OPTAB_FN (TAKE_INCL_ACTIVE, ECF_CONST, take_incl_active, unary)
DEF_INTERNAL_OPTAB_FN (COND_TAKE_INCL_ACTIVE, ECF_CONST,
cond_take_incl_active, cond_unary)
diff --git a/gcc/optabs.def b/gcc/optabs.def
index 1e15e994df9..71433638585 100644
--- a/gcc/optabs.def
+++ b/gcc/optabs.def
@@ -441,6 +441,7 @@ OPTAB_D (cond_len_count_active_optab,
"cond_len_count_active_$a")
OPTAB_D (index_first_active_optab, "index_first_active_$a")
OPTAB_D (cond_index_first_active_optab, "cond_index_first_active_$a")
OPTAB_D (cond_len_index_first_active_optab, "cond_len_index_first_active_$a")
+OPTAB_D (cond_len_any_active_optab, "cond_len_any_active_$a")
OPTAB_D (fold_extract_last_optab, "fold_extract_last_$a")
OPTAB_D (len_fold_extract_last_optab, "len_fold_extract_last_$a")
OPTAB_D (take_incl_active_optab, "take_incl_active_$a")
--
2.56.0