| Message ID | 20261105095002.29325-4-ktkachov@nvidia.com |
|---|---|
| State | New |
| Headers | show |
| Series | [1/5] match.pd: Look through VIEW_CONVERT_EXPR in the C[LT]Z zero select folds | expand |
On Thu, 5 Nov 2026, ktkachov@nvidia.com wrote: > From: Kyrylo Tkachov <ktkachov@nvidia.com> > > The expanders of direct internal functions read a fixed set of call > arguments, but nothing records how many arguments a call must have. > A verifier cannot check the arguments without this data. > > Add the minimum and maximum number of arguments to > direct_internal_fn_info and set them in the TYPE##_direct > initializers. The counts agree with the arguments that the expanders > read and with the calls that the vectorizer and other passes create. > > Some TYPEs are shared by functions with different numbers of > arguments. Give the masked and the length variants of the gather > loads, scatter stores and masked load and store lanes their own > TYPEs. The new TYPEs reuse the expanders and the support checks of > the old TYPEs. IFN_CLZ, IFN_CTZ and IFN_POPCOUNT have an optional > second argument, so give them the new TYPE unary_opt. > > Make the vectorizable field 8 bits wide to make space for the > counts. Assert in expand_direct_optab_fn and expand_convert_optab_fn > that the call has a valid number of arguments. > > Bootstrapped and tested on aarch64-none-linux-gnu and x86_64-linux. > Ok for trunk? Thanks for doing this, it is OK. Richard. > Thanks, > Kyrill > > gcc/ChangeLog: > > * internal-fn.h (struct direct_internal_fn_info): Make vectorizable > 8 bits wide. Add nargs_min and nargs_max. > (direct_internal_fn_nargs_ok_p): New function. > * internal-fn.cc (not_direct, mask_load_direct, load_lanes_direct) > (mask_load_lanes_direct, gather_load_direct, strided_load_direct) > (len_load_direct, mask_len_load_direct, mask_store_direct) > (store_lanes_direct, mask_store_lanes_direct, vec_cond_mask_direct) > (vec_cond_mask_len_direct, vec_cond_direct, scatter_store_direct) > (strided_store_direct, len_store_direct, mask_len_store_direct) > (vec_set_direct, vec_extract_direct, unary_direct) > (unary_convert_direct, binary_direct, ternary_direct) > (cond_unary_direct, cond_binary_direct, cond_ternary_direct) > (cond_len_unary_direct, cond_len_binary_direct) > (cond_len_ternary_direct, while_direct, fold_extract_direct) > (fold_len_extract_direct, fold_left_direct, mask_fold_left_direct) > (mask_len_fold_left_direct, check_ptrs_direct, crc_direct) > (reduc_sbool_direct, select_vl_direct): Add the number of > arguments. > (mask_len_load_lanes_direct, mask_gather_load_direct) > (mask_len_gather_load_direct, mask_len_store_lanes_direct) > (mask_scatter_store_direct, mask_len_scatter_store_direct) > (unary_opt_direct): New macros. > (expand_mask_len_load_lanes_optab_fn) > (expand_mask_len_store_lanes_optab_fn) > (expand_mask_scatter_store_optab_fn) > (expand_mask_len_scatter_store_optab_fn) > (expand_mask_gather_load_optab_fn) > (expand_mask_len_gather_load_optab_fn, expand_unary_opt_optab_fn) > (direct_unary_opt_optab_supported_p) > (direct_mask_len_load_lanes_optab_supported_p) > (direct_mask_gather_load_optab_supported_p) > (direct_mask_len_gather_load_optab_supported_p) > (direct_mask_len_store_lanes_optab_supported_p) > (direct_mask_scatter_store_optab_supported_p) > (direct_mask_len_scatter_store_optab_supported_p): New macros. > (expand_direct_optab_fn, expand_convert_optab_fn): Assert that the > call has a valid number of arguments. > * internal-fn.def: Document that TYPE gives the number of > arguments. Document mask_gather_load, mask_len_gather_load, > mask_scatter_store, mask_len_scatter_store and unary_opt. > (MASK_LEN_LOAD_LANES): Use mask_len_load_lanes. > (MASK_GATHER_LOAD): Use mask_gather_load. > (MASK_LEN_GATHER_LOAD): Use mask_len_gather_load. > (MASK_SCATTER_STORE): Use mask_scatter_store. > (MASK_LEN_SCATTER_STORE): Use mask_len_scatter_store. > (MASK_LEN_STORE_LANES): Use mask_len_store_lanes. > (CLZ, CTZ, POPCOUNT): Use unary_opt. > > Signed-off-by: Kyrylo Tkachov <ktkachov@nvidia.com> > --- > gcc/internal-fn.cc | 111 ++++++++++++++++++++++++++++---------------- > gcc/internal-fn.def | 31 ++++++++----- > gcc/internal-fn.h | 18 ++++++- > 3 files changed, 106 insertions(+), 54 deletions(-) > > diff --git a/gcc/internal-fn.cc b/gcc/internal-fn.cc > index 40fe58dc4f6..88bd3f037b0 100644 > --- a/gcc/internal-fn.cc > +++ b/gcc/internal-fn.cc > @@ -156,46 +156,53 @@ init_internal_fns () > > /* Create static initializers for the information returned by > direct_internal_fn. */ > -#define not_direct { -2, -2, false } > -#define mask_load_direct { -1, 2, false } > -#define load_lanes_direct { -1, -1, false } > -#define mask_load_lanes_direct { -1, -1, false } > -#define gather_load_direct { 3, 1, false } > -#define strided_load_direct { -1, -1, false } > -#define len_load_direct { -1, -1, false } > -#define mask_len_load_direct { -1, 4, false } > -#define mask_store_direct { 3, 2, false } > -#define store_lanes_direct { 0, 0, false } > -#define mask_store_lanes_direct { 0, 0, false } > -#define vec_cond_mask_direct { 1, 0, false } > -#define vec_cond_mask_len_direct { 1, 1, false } > -#define vec_cond_direct { 2, 0, false } > -#define scatter_store_direct { 3, 1, false } > -#define strided_store_direct { 1, 1, false } > -#define len_store_direct { 3, 3, false } > -#define mask_len_store_direct { 4, 5, false } > -#define vec_set_direct { 3, 3, false } > -#define vec_extract_direct { 0, -1, false } > -#define unary_direct { 0, 0, true } > -#define unary_convert_direct { -1, 0, true } > -#define binary_direct { 0, 0, true } > -#define ternary_direct { 0, 0, true } > -#define cond_unary_direct { 1, 1, true } > -#define cond_binary_direct { 1, 1, true } > -#define cond_ternary_direct { 1, 1, true } > -#define cond_len_unary_direct { 1, 1, true } > -#define cond_len_binary_direct { 1, 1, true } > -#define cond_len_ternary_direct { 1, 1, true } > -#define while_direct { 0, 2, false } > -#define fold_extract_direct { 2, 2, false } > -#define fold_len_extract_direct { 2, 2, false } > -#define fold_left_direct { 1, 1, false } > -#define mask_fold_left_direct { 1, 1, false } > -#define mask_len_fold_left_direct { 1, 1, false } > -#define check_ptrs_direct { 0, 0, false } > -#define crc_direct { 1, -1, true } > -#define reduc_sbool_direct { 0, 0, true } > -#define select_vl_direct { 2, 0, false } > +#define not_direct { -2, -2, false, 0, 0 } > +#define mask_load_direct { -1, 2, false, 4, 4 } > +#define load_lanes_direct { -1, -1, false, 1, 1 } > +#define mask_load_lanes_direct { -1, -1, false, 4, 4 } > +#define mask_len_load_lanes_direct { -1, -1, false, 6, 6 } > +#define gather_load_direct { 3, 1, false, 5, 5 } > +#define mask_gather_load_direct { 3, 1, false, 7, 7 } > +#define mask_len_gather_load_direct { 3, 1, false, 9, 9 } > +#define strided_load_direct { -1, -1, false, 7, 7 } > +#define len_load_direct { -1, -1, false, 5, 5 } > +#define mask_len_load_direct { -1, 4, false, 6, 6 } > +#define mask_store_direct { 3, 2, false, 4, 4 } > +#define store_lanes_direct { 0, 0, false, 1, 1 } > +#define mask_store_lanes_direct { 0, 0, false, 4, 4 } > +#define mask_len_store_lanes_direct { 0, 0, false, 6, 6 } > +#define vec_cond_mask_direct { 1, 0, false, 3, 3 } > +#define vec_cond_mask_len_direct { 1, 1, false, 5, 5 } > +#define vec_cond_direct { 2, 0, false, 5, 5 } > +#define scatter_store_direct { 3, 1, false, 5, 5 } > +#define mask_scatter_store_direct { 3, 1, false, 6, 6 } > +#define mask_len_scatter_store_direct { 3, 1, false, 8, 8 } > +#define strided_store_direct { 1, 1, false, 6, 6 } > +#define len_store_direct { 3, 3, false, 5, 5 } > +#define mask_len_store_direct { 4, 5, false, 6, 6 } > +#define vec_set_direct { 3, 3, false, 3, 3 } > +#define vec_extract_direct { 0, -1, false, 2, 2 } > +#define unary_direct { 0, 0, true, 1, 1 } > +#define unary_opt_direct { 0, 0, true, 1, 2 } > +#define unary_convert_direct { -1, 0, true, 1, 1 } > +#define binary_direct { 0, 0, true, 2, 2 } > +#define ternary_direct { 0, 0, true, 3, 3 } > +#define cond_unary_direct { 1, 1, true, 3, 3 } > +#define cond_binary_direct { 1, 1, true, 4, 4 } > +#define cond_ternary_direct { 1, 1, true, 5, 5 } > +#define cond_len_unary_direct { 1, 1, true, 5, 5 } > +#define cond_len_binary_direct { 1, 1, true, 6, 6 } > +#define cond_len_ternary_direct { 1, 1, true, 7, 7 } > +#define while_direct { 0, 2, false, 3, 3 } > +#define fold_extract_direct { 2, 2, false, 3, 3 } > +#define fold_len_extract_direct { 2, 2, false, 5, 5 } > +#define fold_left_direct { 1, 1, false, 2, 2 } > +#define mask_fold_left_direct { 1, 1, false, 3, 3 } > +#define mask_len_fold_left_direct { 1, 1, false, 5, 5 } > +#define check_ptrs_direct { 0, 0, false, 4, 4 } > +#define crc_direct { 1, -1, true, 3, 3 } > +#define reduc_sbool_direct { 0, 0, true, 1, 1 } > +#define select_vl_direct { 2, 0, false, 3, 3 } > > const direct_internal_fn_info direct_internal_fn_array[IFN_LAST + 1] = { > #define DEF_INTERNAL_FN(CODE, FLAGS, FNSPEC) not_direct, > @@ -3218,6 +3225,7 @@ expand_partial_load_optab_fn (internal_fn ifn, gcall *stmt, convert_optab optab) > > #define expand_mask_load_optab_fn expand_partial_load_optab_fn > #define expand_mask_load_lanes_optab_fn expand_mask_load_optab_fn > +#define expand_mask_len_load_lanes_optab_fn expand_mask_load_optab_fn > #define expand_len_load_optab_fn expand_partial_load_optab_fn > #define expand_mask_len_load_optab_fn expand_partial_load_optab_fn > > @@ -3262,6 +3270,7 @@ expand_partial_store_optab_fn (internal_fn ifn, gcall *stmt, convert_optab optab > > #define expand_mask_store_optab_fn expand_partial_store_optab_fn > #define expand_mask_store_lanes_optab_fn expand_mask_store_optab_fn > +#define expand_mask_len_store_lanes_optab_fn expand_mask_store_optab_fn > #define expand_len_store_optab_fn expand_partial_store_optab_fn > #define expand_mask_len_store_optab_fn expand_partial_store_optab_fn > > @@ -3863,6 +3872,9 @@ expand_scatter_store_optab_fn (internal_fn, gcall *stmt, direct_optab optab) > expand_insn (icode, i, ops); > } > > +#define expand_mask_scatter_store_optab_fn expand_scatter_store_optab_fn > +#define expand_mask_len_scatter_store_optab_fn expand_scatter_store_optab_fn > + > /* Expand {MASK_,}GATHER_LOAD call CALL using optab OPTAB. */ > > static void > @@ -3892,6 +3904,9 @@ expand_gather_load_optab_fn (internal_fn ifn, gcall *stmt, direct_optab optab) > assign_call_lhs (lhs, lhs_rtx, &ops[0]); > } > > +#define expand_mask_gather_load_optab_fn expand_gather_load_optab_fn > +#define expand_mask_len_gather_load_optab_fn expand_gather_load_optab_fn > + > /* Expand MASK_LEN_STRIDED_LOAD call CALL by optab OPTAB. */ > > static void > @@ -4139,6 +4154,8 @@ static void > expand_direct_optab_fn (internal_fn fn, gcall *stmt, direct_optab optab, > unsigned int nargs) > { > + gcc_checking_assert (direct_internal_fn_nargs_ok_p > + (fn, gimple_call_num_args (stmt))); > tree_pair types = direct_internal_fn_types (fn, stmt); > insn_code icode = direct_optab_handler (optab, TYPE_MODE (types.first)); > expand_fn_using_insn (stmt, icode, 1, nargs); > @@ -4193,6 +4210,8 @@ static void > expand_convert_optab_fn (internal_fn fn, gcall *stmt, convert_optab optab, > unsigned int nargs) > { > + gcc_checking_assert (direct_internal_fn_nargs_ok_p > + (fn, gimple_call_num_args (stmt))); > tree_pair types = direct_internal_fn_types (fn, stmt); > insn_code icode = convert_optab_handler (optab, TYPE_MODE (types.first), > TYPE_MODE (types.second)); > @@ -4327,6 +4346,8 @@ expand_reduc_sbool_optab_fn (internal_fn fn, gcall *stmt, direct_optab optab) > #define expand_unary_optab_fn(FN, STMT, OPTAB) \ > expand_direct_optab_fn (FN, STMT, OPTAB, 1) > > +#define expand_unary_opt_optab_fn expand_unary_optab_fn > + > #define expand_binary_optab_fn(FN, STMT, OPTAB) \ > expand_direct_optab_fn (FN, STMT, OPTAB, 2) > > @@ -4452,6 +4473,7 @@ multi_vector_optab_supported_p (convert_optab optab, tree_pair types, > } > > #define direct_unary_optab_supported_p direct_optab_supported_p > +#define direct_unary_opt_optab_supported_p direct_optab_supported_p > #define direct_unary_convert_optab_supported_p convert_optab_supported_p > #define direct_binary_optab_supported_p direct_optab_supported_p > #define direct_ternary_optab_supported_p direct_optab_supported_p > @@ -4465,16 +4487,25 @@ multi_vector_optab_supported_p (convert_optab optab, tree_pair types, > #define direct_mask_load_optab_supported_p convert_optab_supported_p > #define direct_load_lanes_optab_supported_p multi_vector_optab_supported_p > #define direct_mask_load_lanes_optab_supported_p multi_vector_optab_supported_p > +#define direct_mask_len_load_lanes_optab_supported_p \ > + multi_vector_optab_supported_p > #define direct_gather_load_optab_supported_p convert_optab_supported_p > +#define direct_mask_gather_load_optab_supported_p convert_optab_supported_p > +#define direct_mask_len_gather_load_optab_supported_p convert_optab_supported_p > #define direct_strided_load_optab_supported_p direct_optab_supported_p > #define direct_len_load_optab_supported_p direct_optab_supported_p > #define direct_mask_len_load_optab_supported_p convert_optab_supported_p > #define direct_mask_store_optab_supported_p convert_optab_supported_p > #define direct_store_lanes_optab_supported_p multi_vector_optab_supported_p > #define direct_mask_store_lanes_optab_supported_p multi_vector_optab_supported_p > +#define direct_mask_len_store_lanes_optab_supported_p \ > + multi_vector_optab_supported_p > #define direct_vec_cond_mask_optab_supported_p convert_optab_supported_p > #define direct_vec_cond_optab_supported_p convert_optab_supported_p > #define direct_scatter_store_optab_supported_p convert_optab_supported_p > +#define direct_mask_scatter_store_optab_supported_p convert_optab_supported_p > +#define direct_mask_len_scatter_store_optab_supported_p \ > + convert_optab_supported_p > #define direct_strided_store_optab_supported_p direct_optab_supported_p > #define direct_len_store_optab_supported_p direct_optab_supported_p > #define direct_mask_len_store_optab_supported_p convert_optab_supported_p > diff --git a/gcc/internal-fn.def b/gcc/internal-fn.def > index 7feb236d802..47b5dd84918 100644 > --- a/gcc/internal-fn.def > +++ b/gcc/internal-fn.def > @@ -51,13 +51,16 @@ along with GCC; see the file COPYING3. If not see > set of types if the associated optab is available for the modes > of those types. OPTAB says what optab to use (without the trailing > "_optab") and TYPE categorizes the optab based on its inputs and > - outputs. The possible types of optab are: > + outputs. TYPE also gives the number of arguments of a call to the > + function. The possible types of optab are: > > - mask_load: currently just maskload > - load_lanes: currently just vec_load_lanes > - mask_load_lanes: currently just vec_mask_load_lanes > - mask_len_load_lanes: currently just vec_mask_len_load_lanes > - - gather_load: used for {mask_,mask_len_,}gather_load > + - gather_load: currently just gather_load > + - mask_gather_load: currently just mask_gather_load > + - mask_len_gather_load: currently just mask_len_gather_load > - strided_load: currently just mask_len_strided_load > - len_load: currently just len_load > - mask_len_load: currently just mask_len_load > @@ -66,12 +69,16 @@ along with GCC; see the file COPYING3. If not see > - store_lanes: currently just vec_store_lanes > - mask_store_lanes: currently just vec_mask_store_lanes > - mask_len_store_lanes: currently just vec_mask_len_store_lanes > - - scatter_store: used for {mask_,mask_len_,}scatter_store > + - scatter_store: currently just scatter_store > + - mask_scatter_store: currently just mask_scatter_store > + - mask_len_scatter_store: currently just mask_len_scatter_store > - strided_store: currently just mask_len_strided_store > - len_store: currently just len_store > - mask_len_store: currently just mask_len_store > > - unary: a normal unary optab, such as vec_reverse_<mode> > + - unary_opt: a normal unary optab for a function that has an optional > + second argument, such as clz<mode>2 > - binary: a normal binary optab, such as vec_interleave_lo_<mode> > - ternary: a normal ternary optab, such as fma<mode>4 > > @@ -229,13 +236,13 @@ DEF_INTERNAL_OPTAB_FN (LOAD_LANES, ECF_CONST, vec_load_lanes, load_lanes) > DEF_INTERNAL_OPTAB_FN (MASK_LOAD_LANES, ECF_PURE, > vec_mask_load_lanes, mask_load_lanes) > DEF_INTERNAL_OPTAB_FN (MASK_LEN_LOAD_LANES, ECF_PURE, > - vec_mask_len_load_lanes, mask_load_lanes) > + vec_mask_len_load_lanes, mask_len_load_lanes) > > DEF_INTERNAL_OPTAB_FN (GATHER_LOAD, ECF_PURE, gather_load, gather_load) > DEF_INTERNAL_OPTAB_FN (MASK_GATHER_LOAD, ECF_PURE, > - mask_gather_load, gather_load) > + mask_gather_load, mask_gather_load) > DEF_INTERNAL_OPTAB_FN (MASK_LEN_GATHER_LOAD, ECF_PURE, > - mask_len_gather_load, gather_load) > + mask_len_gather_load, mask_len_gather_load) > DEF_INTERNAL_OPTAB_FN (MASK_LEN_STRIDED_LOAD, ECF_PURE, > mask_len_strided_load, strided_load) > > @@ -244,9 +251,9 @@ DEF_INTERNAL_OPTAB_FN (MASK_LEN_LOAD, ECF_PURE, mask_len_load, mask_len_load) > > DEF_INTERNAL_OPTAB_FN (SCATTER_STORE, 0, scatter_store, scatter_store) > DEF_INTERNAL_OPTAB_FN (MASK_SCATTER_STORE, 0, > - mask_scatter_store, scatter_store) > + mask_scatter_store, mask_scatter_store) > DEF_INTERNAL_OPTAB_FN (MASK_LEN_SCATTER_STORE, 0, > - mask_len_scatter_store, scatter_store) > + mask_len_scatter_store, mask_len_scatter_store) > DEF_INTERNAL_OPTAB_FN (MASK_LEN_STRIDED_STORE, 0, > mask_len_strided_store, strided_store) > > @@ -255,7 +262,7 @@ DEF_INTERNAL_OPTAB_FN (STORE_LANES, ECF_CONST, vec_store_lanes, store_lanes) > DEF_INTERNAL_OPTAB_FN (MASK_STORE_LANES, 0, > vec_mask_store_lanes, mask_store_lanes) > DEF_INTERNAL_OPTAB_FN (MASK_LEN_STORE_LANES, 0, > - vec_mask_len_store_lanes, mask_store_lanes) > + vec_mask_len_store_lanes, mask_len_store_lanes) > > DEF_INTERNAL_OPTAB_FN (VCOND_MASK, ECF_CONST | ECF_NOTHROW, > vcond_mask, vec_cond_mask) > @@ -486,11 +493,11 @@ DEF_INTERNAL_OPTAB_FN (COMPLEX_FMS_CONJ, ECF_CONST, cmls_conj, ternary) > > /* Unary integer ops. */ > DEF_INTERNAL_INT_EXT_FN (CLRSB, ECF_CONST | ECF_NOTHROW, clrsb, unary) > -DEF_INTERNAL_INT_EXT_FN (CLZ, ECF_CONST | ECF_NOTHROW, clz, unary) > -DEF_INTERNAL_INT_EXT_FN (CTZ, ECF_CONST | ECF_NOTHROW, ctz, unary) > +DEF_INTERNAL_INT_EXT_FN (CLZ, ECF_CONST | ECF_NOTHROW, clz, unary_opt) > +DEF_INTERNAL_INT_EXT_FN (CTZ, ECF_CONST | ECF_NOTHROW, ctz, unary_opt) > DEF_INTERNAL_INT_EXT_FN (FFS, ECF_CONST | ECF_NOTHROW, ffs, unary) > DEF_INTERNAL_INT_EXT_FN (PARITY, ECF_CONST | ECF_NOTHROW, parity, unary) > -DEF_INTERNAL_INT_EXT_FN (POPCOUNT, ECF_CONST | ECF_NOTHROW, popcount, unary) > +DEF_INTERNAL_INT_EXT_FN (POPCOUNT, ECF_CONST | ECF_NOTHROW, popcount, unary_opt) > DEF_INTERNAL_INTSZ_EXT_FN (BSWAP, ECF_CONST | ECF_NOTHROW, bswap, unary) > DEF_INTERNAL_INTSZ_EXT_FN (BITREVERSE, ECF_CONST | ECF_NOTHROW, bitreverse, > unary) > diff --git a/gcc/internal-fn.h b/gcc/internal-fn.h > index 30930f388b0..c1503e51f10 100644 > --- a/gcc/internal-fn.h > +++ b/gcc/internal-fn.h > @@ -157,9 +157,13 @@ struct direct_internal_fn_info > same number of elements. E.g. we can vectorize an IFN_SQRT on > floats as an IFN_SQRT on vectors of N floats. > > - This only needs 1 bit, but occupies the full 16 to ensure a nice > + This only needs 1 bit, but occupies the full 8 to ensure a nice > layout. */ > - unsigned int vectorizable : 16; > + unsigned int vectorizable : 8; > + /* The minimum and maximum number of arguments of a call to the > + function. */ > + unsigned int nargs_min : 4; > + unsigned int nargs_max : 4; > }; > > extern const direct_internal_fn_info direct_internal_fn_array[IFN_LAST + 1]; > @@ -193,6 +197,16 @@ direct_internal_fn (internal_fn fn) > return direct_internal_fn_array[fn]; > } > > +/* Return true if a call to FN can have NARGS arguments. FN must satisfy > + direct_internal_fn_p. */ > + > +inline bool > +direct_internal_fn_nargs_ok_p (internal_fn fn, unsigned int nargs) > +{ > + const direct_internal_fn_info &info = direct_internal_fn (fn); > + return nargs >= info.nargs_min && nargs <= info.nargs_max; > +} > + > extern tree_pair direct_internal_fn_types (internal_fn, tree, tree *); > extern tree_pair direct_internal_fn_types (internal_fn, gcall *); > extern bool direct_internal_fn_supported_p (internal_fn, tree_pair, >
diff --git a/gcc/internal-fn.cc b/gcc/internal-fn.cc index 40fe58dc4f6..88bd3f037b0 100644 --- a/gcc/internal-fn.cc +++ b/gcc/internal-fn.cc @@ -156,46 +156,53 @@ init_internal_fns () /* Create static initializers for the information returned by direct_internal_fn. */ -#define not_direct { -2, -2, false } -#define mask_load_direct { -1, 2, false } -#define load_lanes_direct { -1, -1, false } -#define mask_load_lanes_direct { -1, -1, false } -#define gather_load_direct { 3, 1, false } -#define strided_load_direct { -1, -1, false } -#define len_load_direct { -1, -1, false } -#define mask_len_load_direct { -1, 4, false } -#define mask_store_direct { 3, 2, false } -#define store_lanes_direct { 0, 0, false } -#define mask_store_lanes_direct { 0, 0, false } -#define vec_cond_mask_direct { 1, 0, false } -#define vec_cond_mask_len_direct { 1, 1, false } -#define vec_cond_direct { 2, 0, false } -#define scatter_store_direct { 3, 1, false } -#define strided_store_direct { 1, 1, false } -#define len_store_direct { 3, 3, false } -#define mask_len_store_direct { 4, 5, false } -#define vec_set_direct { 3, 3, false } -#define vec_extract_direct { 0, -1, false } -#define unary_direct { 0, 0, true } -#define unary_convert_direct { -1, 0, true } -#define binary_direct { 0, 0, true } -#define ternary_direct { 0, 0, true } -#define cond_unary_direct { 1, 1, true } -#define cond_binary_direct { 1, 1, true } -#define cond_ternary_direct { 1, 1, true } -#define cond_len_unary_direct { 1, 1, true } -#define cond_len_binary_direct { 1, 1, true } -#define cond_len_ternary_direct { 1, 1, true } -#define while_direct { 0, 2, false } -#define fold_extract_direct { 2, 2, false } -#define fold_len_extract_direct { 2, 2, false } -#define fold_left_direct { 1, 1, false } -#define mask_fold_left_direct { 1, 1, false } -#define mask_len_fold_left_direct { 1, 1, false } -#define check_ptrs_direct { 0, 0, false } -#define crc_direct { 1, -1, true } -#define reduc_sbool_direct { 0, 0, true } -#define select_vl_direct { 2, 0, false } +#define not_direct { -2, -2, false, 0, 0 } +#define mask_load_direct { -1, 2, false, 4, 4 } +#define load_lanes_direct { -1, -1, false, 1, 1 } +#define mask_load_lanes_direct { -1, -1, false, 4, 4 } +#define mask_len_load_lanes_direct { -1, -1, false, 6, 6 } +#define gather_load_direct { 3, 1, false, 5, 5 } +#define mask_gather_load_direct { 3, 1, false, 7, 7 } +#define mask_len_gather_load_direct { 3, 1, false, 9, 9 } +#define strided_load_direct { -1, -1, false, 7, 7 } +#define len_load_direct { -1, -1, false, 5, 5 } +#define mask_len_load_direct { -1, 4, false, 6, 6 } +#define mask_store_direct { 3, 2, false, 4, 4 } +#define store_lanes_direct { 0, 0, false, 1, 1 } +#define mask_store_lanes_direct { 0, 0, false, 4, 4 } +#define mask_len_store_lanes_direct { 0, 0, false, 6, 6 } +#define vec_cond_mask_direct { 1, 0, false, 3, 3 } +#define vec_cond_mask_len_direct { 1, 1, false, 5, 5 } +#define vec_cond_direct { 2, 0, false, 5, 5 } +#define scatter_store_direct { 3, 1, false, 5, 5 } +#define mask_scatter_store_direct { 3, 1, false, 6, 6 } +#define mask_len_scatter_store_direct { 3, 1, false, 8, 8 } +#define strided_store_direct { 1, 1, false, 6, 6 } +#define len_store_direct { 3, 3, false, 5, 5 } +#define mask_len_store_direct { 4, 5, false, 6, 6 } +#define vec_set_direct { 3, 3, false, 3, 3 } +#define vec_extract_direct { 0, -1, false, 2, 2 } +#define unary_direct { 0, 0, true, 1, 1 } +#define unary_opt_direct { 0, 0, true, 1, 2 } +#define unary_convert_direct { -1, 0, true, 1, 1 } +#define binary_direct { 0, 0, true, 2, 2 } +#define ternary_direct { 0, 0, true, 3, 3 } +#define cond_unary_direct { 1, 1, true, 3, 3 } +#define cond_binary_direct { 1, 1, true, 4, 4 } +#define cond_ternary_direct { 1, 1, true, 5, 5 } +#define cond_len_unary_direct { 1, 1, true, 5, 5 } +#define cond_len_binary_direct { 1, 1, true, 6, 6 } +#define cond_len_ternary_direct { 1, 1, true, 7, 7 } +#define while_direct { 0, 2, false, 3, 3 } +#define fold_extract_direct { 2, 2, false, 3, 3 } +#define fold_len_extract_direct { 2, 2, false, 5, 5 } +#define fold_left_direct { 1, 1, false, 2, 2 } +#define mask_fold_left_direct { 1, 1, false, 3, 3 } +#define mask_len_fold_left_direct { 1, 1, false, 5, 5 } +#define check_ptrs_direct { 0, 0, false, 4, 4 } +#define crc_direct { 1, -1, true, 3, 3 } +#define reduc_sbool_direct { 0, 0, true, 1, 1 } +#define select_vl_direct { 2, 0, false, 3, 3 } const direct_internal_fn_info direct_internal_fn_array[IFN_LAST + 1] = { #define DEF_INTERNAL_FN(CODE, FLAGS, FNSPEC) not_direct, @@ -3218,6 +3225,7 @@ expand_partial_load_optab_fn (internal_fn ifn, gcall *stmt, convert_optab optab) #define expand_mask_load_optab_fn expand_partial_load_optab_fn #define expand_mask_load_lanes_optab_fn expand_mask_load_optab_fn +#define expand_mask_len_load_lanes_optab_fn expand_mask_load_optab_fn #define expand_len_load_optab_fn expand_partial_load_optab_fn #define expand_mask_len_load_optab_fn expand_partial_load_optab_fn @@ -3262,6 +3270,7 @@ expand_partial_store_optab_fn (internal_fn ifn, gcall *stmt, convert_optab optab #define expand_mask_store_optab_fn expand_partial_store_optab_fn #define expand_mask_store_lanes_optab_fn expand_mask_store_optab_fn +#define expand_mask_len_store_lanes_optab_fn expand_mask_store_optab_fn #define expand_len_store_optab_fn expand_partial_store_optab_fn #define expand_mask_len_store_optab_fn expand_partial_store_optab_fn @@ -3863,6 +3872,9 @@ expand_scatter_store_optab_fn (internal_fn, gcall *stmt, direct_optab optab) expand_insn (icode, i, ops); } +#define expand_mask_scatter_store_optab_fn expand_scatter_store_optab_fn +#define expand_mask_len_scatter_store_optab_fn expand_scatter_store_optab_fn + /* Expand {MASK_,}GATHER_LOAD call CALL using optab OPTAB. */ static void @@ -3892,6 +3904,9 @@ expand_gather_load_optab_fn (internal_fn ifn, gcall *stmt, direct_optab optab) assign_call_lhs (lhs, lhs_rtx, &ops[0]); } +#define expand_mask_gather_load_optab_fn expand_gather_load_optab_fn +#define expand_mask_len_gather_load_optab_fn expand_gather_load_optab_fn + /* Expand MASK_LEN_STRIDED_LOAD call CALL by optab OPTAB. */ static void @@ -4139,6 +4154,8 @@ static void expand_direct_optab_fn (internal_fn fn, gcall *stmt, direct_optab optab, unsigned int nargs) { + gcc_checking_assert (direct_internal_fn_nargs_ok_p + (fn, gimple_call_num_args (stmt))); tree_pair types = direct_internal_fn_types (fn, stmt); insn_code icode = direct_optab_handler (optab, TYPE_MODE (types.first)); expand_fn_using_insn (stmt, icode, 1, nargs); @@ -4193,6 +4210,8 @@ static void expand_convert_optab_fn (internal_fn fn, gcall *stmt, convert_optab optab, unsigned int nargs) { + gcc_checking_assert (direct_internal_fn_nargs_ok_p + (fn, gimple_call_num_args (stmt))); tree_pair types = direct_internal_fn_types (fn, stmt); insn_code icode = convert_optab_handler (optab, TYPE_MODE (types.first), TYPE_MODE (types.second)); @@ -4327,6 +4346,8 @@ expand_reduc_sbool_optab_fn (internal_fn fn, gcall *stmt, direct_optab optab) #define expand_unary_optab_fn(FN, STMT, OPTAB) \ expand_direct_optab_fn (FN, STMT, OPTAB, 1) +#define expand_unary_opt_optab_fn expand_unary_optab_fn + #define expand_binary_optab_fn(FN, STMT, OPTAB) \ expand_direct_optab_fn (FN, STMT, OPTAB, 2) @@ -4452,6 +4473,7 @@ multi_vector_optab_supported_p (convert_optab optab, tree_pair types, } #define direct_unary_optab_supported_p direct_optab_supported_p +#define direct_unary_opt_optab_supported_p direct_optab_supported_p #define direct_unary_convert_optab_supported_p convert_optab_supported_p #define direct_binary_optab_supported_p direct_optab_supported_p #define direct_ternary_optab_supported_p direct_optab_supported_p @@ -4465,16 +4487,25 @@ multi_vector_optab_supported_p (convert_optab optab, tree_pair types, #define direct_mask_load_optab_supported_p convert_optab_supported_p #define direct_load_lanes_optab_supported_p multi_vector_optab_supported_p #define direct_mask_load_lanes_optab_supported_p multi_vector_optab_supported_p +#define direct_mask_len_load_lanes_optab_supported_p \ + multi_vector_optab_supported_p #define direct_gather_load_optab_supported_p convert_optab_supported_p +#define direct_mask_gather_load_optab_supported_p convert_optab_supported_p +#define direct_mask_len_gather_load_optab_supported_p convert_optab_supported_p #define direct_strided_load_optab_supported_p direct_optab_supported_p #define direct_len_load_optab_supported_p direct_optab_supported_p #define direct_mask_len_load_optab_supported_p convert_optab_supported_p #define direct_mask_store_optab_supported_p convert_optab_supported_p #define direct_store_lanes_optab_supported_p multi_vector_optab_supported_p #define direct_mask_store_lanes_optab_supported_p multi_vector_optab_supported_p +#define direct_mask_len_store_lanes_optab_supported_p \ + multi_vector_optab_supported_p #define direct_vec_cond_mask_optab_supported_p convert_optab_supported_p #define direct_vec_cond_optab_supported_p convert_optab_supported_p #define direct_scatter_store_optab_supported_p convert_optab_supported_p +#define direct_mask_scatter_store_optab_supported_p convert_optab_supported_p +#define direct_mask_len_scatter_store_optab_supported_p \ + convert_optab_supported_p #define direct_strided_store_optab_supported_p direct_optab_supported_p #define direct_len_store_optab_supported_p direct_optab_supported_p #define direct_mask_len_store_optab_supported_p convert_optab_supported_p diff --git a/gcc/internal-fn.def b/gcc/internal-fn.def index 7feb236d802..47b5dd84918 100644 --- a/gcc/internal-fn.def +++ b/gcc/internal-fn.def @@ -51,13 +51,16 @@ along with GCC; see the file COPYING3. If not see set of types if the associated optab is available for the modes of those types. OPTAB says what optab to use (without the trailing "_optab") and TYPE categorizes the optab based on its inputs and - outputs. The possible types of optab are: + outputs. TYPE also gives the number of arguments of a call to the + function. The possible types of optab are: - mask_load: currently just maskload - load_lanes: currently just vec_load_lanes - mask_load_lanes: currently just vec_mask_load_lanes - mask_len_load_lanes: currently just vec_mask_len_load_lanes - - gather_load: used for {mask_,mask_len_,}gather_load + - gather_load: currently just gather_load + - mask_gather_load: currently just mask_gather_load + - mask_len_gather_load: currently just mask_len_gather_load - strided_load: currently just mask_len_strided_load - len_load: currently just len_load - mask_len_load: currently just mask_len_load @@ -66,12 +69,16 @@ along with GCC; see the file COPYING3. If not see - store_lanes: currently just vec_store_lanes - mask_store_lanes: currently just vec_mask_store_lanes - mask_len_store_lanes: currently just vec_mask_len_store_lanes - - scatter_store: used for {mask_,mask_len_,}scatter_store + - scatter_store: currently just scatter_store + - mask_scatter_store: currently just mask_scatter_store + - mask_len_scatter_store: currently just mask_len_scatter_store - strided_store: currently just mask_len_strided_store - len_store: currently just len_store - mask_len_store: currently just mask_len_store - unary: a normal unary optab, such as vec_reverse_<mode> + - unary_opt: a normal unary optab for a function that has an optional + second argument, such as clz<mode>2 - binary: a normal binary optab, such as vec_interleave_lo_<mode> - ternary: a normal ternary optab, such as fma<mode>4 @@ -229,13 +236,13 @@ DEF_INTERNAL_OPTAB_FN (LOAD_LANES, ECF_CONST, vec_load_lanes, load_lanes) DEF_INTERNAL_OPTAB_FN (MASK_LOAD_LANES, ECF_PURE, vec_mask_load_lanes, mask_load_lanes) DEF_INTERNAL_OPTAB_FN (MASK_LEN_LOAD_LANES, ECF_PURE, - vec_mask_len_load_lanes, mask_load_lanes) + vec_mask_len_load_lanes, mask_len_load_lanes) DEF_INTERNAL_OPTAB_FN (GATHER_LOAD, ECF_PURE, gather_load, gather_load) DEF_INTERNAL_OPTAB_FN (MASK_GATHER_LOAD, ECF_PURE, - mask_gather_load, gather_load) + mask_gather_load, mask_gather_load) DEF_INTERNAL_OPTAB_FN (MASK_LEN_GATHER_LOAD, ECF_PURE, - mask_len_gather_load, gather_load) + mask_len_gather_load, mask_len_gather_load) DEF_INTERNAL_OPTAB_FN (MASK_LEN_STRIDED_LOAD, ECF_PURE, mask_len_strided_load, strided_load) @@ -244,9 +251,9 @@ DEF_INTERNAL_OPTAB_FN (MASK_LEN_LOAD, ECF_PURE, mask_len_load, mask_len_load) DEF_INTERNAL_OPTAB_FN (SCATTER_STORE, 0, scatter_store, scatter_store) DEF_INTERNAL_OPTAB_FN (MASK_SCATTER_STORE, 0, - mask_scatter_store, scatter_store) + mask_scatter_store, mask_scatter_store) DEF_INTERNAL_OPTAB_FN (MASK_LEN_SCATTER_STORE, 0, - mask_len_scatter_store, scatter_store) + mask_len_scatter_store, mask_len_scatter_store) DEF_INTERNAL_OPTAB_FN (MASK_LEN_STRIDED_STORE, 0, mask_len_strided_store, strided_store) @@ -255,7 +262,7 @@ DEF_INTERNAL_OPTAB_FN (STORE_LANES, ECF_CONST, vec_store_lanes, store_lanes) DEF_INTERNAL_OPTAB_FN (MASK_STORE_LANES, 0, vec_mask_store_lanes, mask_store_lanes) DEF_INTERNAL_OPTAB_FN (MASK_LEN_STORE_LANES, 0, - vec_mask_len_store_lanes, mask_store_lanes) + vec_mask_len_store_lanes, mask_len_store_lanes) DEF_INTERNAL_OPTAB_FN (VCOND_MASK, ECF_CONST | ECF_NOTHROW, vcond_mask, vec_cond_mask) @@ -486,11 +493,11 @@ DEF_INTERNAL_OPTAB_FN (COMPLEX_FMS_CONJ, ECF_CONST, cmls_conj, ternary) /* Unary integer ops. */ DEF_INTERNAL_INT_EXT_FN (CLRSB, ECF_CONST | ECF_NOTHROW, clrsb, unary) -DEF_INTERNAL_INT_EXT_FN (CLZ, ECF_CONST | ECF_NOTHROW, clz, unary) -DEF_INTERNAL_INT_EXT_FN (CTZ, ECF_CONST | ECF_NOTHROW, ctz, unary) +DEF_INTERNAL_INT_EXT_FN (CLZ, ECF_CONST | ECF_NOTHROW, clz, unary_opt) +DEF_INTERNAL_INT_EXT_FN (CTZ, ECF_CONST | ECF_NOTHROW, ctz, unary_opt) DEF_INTERNAL_INT_EXT_FN (FFS, ECF_CONST | ECF_NOTHROW, ffs, unary) DEF_INTERNAL_INT_EXT_FN (PARITY, ECF_CONST | ECF_NOTHROW, parity, unary) -DEF_INTERNAL_INT_EXT_FN (POPCOUNT, ECF_CONST | ECF_NOTHROW, popcount, unary) +DEF_INTERNAL_INT_EXT_FN (POPCOUNT, ECF_CONST | ECF_NOTHROW, popcount, unary_opt) DEF_INTERNAL_INTSZ_EXT_FN (BSWAP, ECF_CONST | ECF_NOTHROW, bswap, unary) DEF_INTERNAL_INTSZ_EXT_FN (BITREVERSE, ECF_CONST | ECF_NOTHROW, bitreverse, unary) diff --git a/gcc/internal-fn.h b/gcc/internal-fn.h index 30930f388b0..c1503e51f10 100644 --- a/gcc/internal-fn.h +++ b/gcc/internal-fn.h @@ -157,9 +157,13 @@ struct direct_internal_fn_info same number of elements. E.g. we can vectorize an IFN_SQRT on floats as an IFN_SQRT on vectors of N floats. - This only needs 1 bit, but occupies the full 16 to ensure a nice + This only needs 1 bit, but occupies the full 8 to ensure a nice layout. */ - unsigned int vectorizable : 16; + unsigned int vectorizable : 8; + /* The minimum and maximum number of arguments of a call to the + function. */ + unsigned int nargs_min : 4; + unsigned int nargs_max : 4; }; extern const direct_internal_fn_info direct_internal_fn_array[IFN_LAST + 1]; @@ -193,6 +197,16 @@ direct_internal_fn (internal_fn fn) return direct_internal_fn_array[fn]; } +/* Return true if a call to FN can have NARGS arguments. FN must satisfy + direct_internal_fn_p. */ + +inline bool +direct_internal_fn_nargs_ok_p (internal_fn fn, unsigned int nargs) +{ + const direct_internal_fn_info &info = direct_internal_fn (fn); + return nargs >= info.nargs_min && nargs <= info.nargs_max; +} + extern tree_pair direct_internal_fn_types (internal_fn, tree, tree *); extern tree_pair direct_internal_fn_types (internal_fn, gcall *); extern bool direct_internal_fn_supported_p (internal_fn, tree_pair,