Skip to content

Commit f4658e0

Browse files
zhongjuzheIncarnation-p-lee
authored andcommitted
VECT: Add LEN_FOLD_EXTRACT_LAST pattern
Hi, Richard and Richi. This is the last autovec pattern I want to add for RVV (length loop control). This patch is supposed to handled this following case: int __attribute__ ((noinline, noclone)) condition_reduction (int *a, int min_v, int n) { int last = 66; /* High start value. */ for (int i = 0; i < n; i++) if (a[i] < min_v) last = i; return last; } ARM SVE IR: ... mask__7.11_39 = vect__4.10_37 < vect_cst__38; _40 = loop_mask_36 & mask__7.11_39; last_5 = .FOLD_EXTRACT_LAST (last_15, _40, vect_vec_iv_.7_32); ... RVV IR, we want to see: ... loop_len = SELECT_VL mask__7.11_39 = vect__4.10_37 < vect_cst__38; last_5 = .LEN_FOLD_EXTRACT_LAST (last_15, _40, vect_vec_iv_.7_32, loop_len, bias); ... gcc/ChangeLog: * doc/md.texi: Add LEN_FOLD_EXTRACT_LAST pattern. * internal-fn.cc (fold_len_extract_direct): Ditto. (expand_fold_len_extract_optab_fn): Ditto. (direct_fold_len_extract_optab_supported_p): Ditto. * internal-fn.def (LEN_FOLD_EXTRACT_LAST): Ditto. * optabs.def (OPTAB_D): Ditto.
1 parent 2c27600 commit f4658e0

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

gcc/doc/md.texi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5636,6 +5636,12 @@ has mode @var{m} and operands 0 and 1 have the mode appropriate for
56365636
one element of @var{m}. Operand 2 has the usual mask mode for vectors
56375637
of mode @var{m}; see @code{TARGET_VECTORIZE_GET_MASK_MODE}.
56385638

5639+
@cindex @code{len_fold_extract_last_@var{m}} instruction pattern
5640+
@item @code{len_fold_extract_last_@var{m}}
5641+
Like @samp{fold_extract_last_@var{m}}, but takes an extra length operand as
5642+
operand 4 and an extra bias operand as operand 5. The last associated element
5643+
is extracted should have the index i < len (operand 4) + bias (operand 5).
5644+
56395645
@cindex @code{fold_left_plus_@var{m}} instruction pattern
56405646
@item @code{fold_left_plus_@var{m}}
56415647
Take scalar operand 1 and successively add each element from vector

gcc/internal-fn.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ init_internal_fns ()
188188
#define cond_len_ternary_direct { 1, 1, true }
189189
#define while_direct { 0, 2, false }
190190
#define fold_extract_direct { 2, 2, false }
191+
#define fold_len_extract_direct { 2, 2, false }
191192
#define fold_left_direct { 1, 1, false }
192193
#define mask_fold_left_direct { 1, 1, false }
193194
#define mask_len_fold_left_direct { 1, 1, false }
@@ -3863,6 +3864,9 @@ expand_convert_optab_fn (internal_fn fn, gcall *stmt, convert_optab optab,
38633864
#define expand_fold_extract_optab_fn(FN, STMT, OPTAB) \
38643865
expand_direct_optab_fn (FN, STMT, OPTAB, 3)
38653866

3867+
#define expand_fold_len_extract_optab_fn(FN, STMT, OPTAB) \
3868+
expand_direct_optab_fn (FN, STMT, OPTAB, 5)
3869+
38663870
#define expand_fold_left_optab_fn(FN, STMT, OPTAB) \
38673871
expand_direct_optab_fn (FN, STMT, OPTAB, 2)
38683872

@@ -3980,6 +3984,7 @@ multi_vector_optab_supported_p (convert_optab optab, tree_pair types,
39803984
#define direct_mask_len_store_optab_supported_p convert_optab_supported_p
39813985
#define direct_while_optab_supported_p convert_optab_supported_p
39823986
#define direct_fold_extract_optab_supported_p direct_optab_supported_p
3987+
#define direct_fold_len_extract_optab_supported_p direct_optab_supported_p
39833988
#define direct_fold_left_optab_supported_p direct_optab_supported_p
39843989
#define direct_mask_fold_left_optab_supported_p direct_optab_supported_p
39853990
#define direct_mask_len_fold_left_optab_supported_p direct_optab_supported_p

gcc/internal-fn.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ DEF_INTERNAL_OPTAB_FN (EXTRACT_LAST, ECF_CONST | ECF_NOTHROW,
312312
DEF_INTERNAL_OPTAB_FN (FOLD_EXTRACT_LAST, ECF_CONST | ECF_NOTHROW,
313313
fold_extract_last, fold_extract)
314314

315+
DEF_INTERNAL_OPTAB_FN (LEN_FOLD_EXTRACT_LAST, ECF_CONST | ECF_NOTHROW,
316+
len_fold_extract_last, fold_len_extract)
317+
315318
DEF_INTERNAL_OPTAB_FN (FOLD_LEFT_PLUS, ECF_CONST | ECF_NOTHROW,
316319
fold_left_plus, fold_left)
317320

gcc/optabs.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ OPTAB_D (mask_len_fold_left_plus_optab, "mask_len_fold_left_plus_$a")
393393

394394
OPTAB_D (extract_last_optab, "extract_last_$a")
395395
OPTAB_D (fold_extract_last_optab, "fold_extract_last_$a")
396+
OPTAB_D (len_fold_extract_last_optab, "len_fold_extract_last_$a")
396397

397398
OPTAB_D (uabd_optab, "uabd$a3")
398399
OPTAB_D (sabd_optab, "sabd$a3")

0 commit comments

Comments
 (0)