Ilya Leoshkevich <i...@linux.ibm.com> writes: > z13 supports only non-signaling vector comparisons. This means we > cannot vectorize LT, LE, GT, GE and LTGT when compiling for z13. > However, we cannot express this restriction today: the code only checks > whether vcond$a$b optab, which does not contain information about the > operation. > > Introduce a hook that tells whether target supports certain vector > comparison operations with certain modes. > > gcc/ChangeLog: > > 2019-08-09 Ilya Leoshkevich <i...@linux.ibm.com> > > * doc/tm.texi (TARGET_VCOND_SUPPORTED_P): Document. > * doc/tm.texi.in (TARGET_VCOND_SUPPORTED_P): Document. > * optabs-tree.c (expand_vec_cond_expr_p): Use vcond_supported_p > in addition to get_vcond_icode. > * target.def (vcond_supported_p): New hook. > * targhooks.c (default_vcond_supported_p): Likewise. > * targhooks.h (default_vcond_supported_p): Likewise.
IMO it'd be cleaner to have a new optabs-query.[hc] helper that uses the predicate for operand 3 to test whether a particular comparison is supported. I guess this would require a cached rtx to avoid generating too much garbage rtl though (via GTY((cache))). If the general feeling is that we should have a hook instead, I assume the same restrictions would apply to the vec_cmp@var{m}@var{n} optab too, on targets that use that. It might be worth generalising the hook so that it applies to both patterns. > diff --git a/gcc/target.def b/gcc/target.def > index b2332d8215c..4cd2a964c0e 100644 > --- a/gcc/target.def > +++ b/gcc/target.def > @@ -3379,6 +3379,17 @@ the vector element type.", > HOST_WIDE_INT, (const_tree type), > default_vector_alignment) > > +DEFHOOK > +(vcond_supported_p, > + "Define this to restrict which vector comparison operations are supported > by\n\ > +vcond$a$b expander. An operation is represented by its operand machine > mode\n\ Maybe s/vcond$a$b expander/a @code{vcond@var{m}@var{n}} instruction pattern/ for consistency with the .md documentation. > +@code{OP_MODE}, its result machine mode @code{RESULT_MODE} and @code{enum\n\ > +tree_code CODE}. The main use of this hook is to support machines which\n\ > +provide only certain vector comparison instructions, e.g. only > non-signaling\n\ > +ones. The default is that all operations are supported.", ...if the associated pattern exists. > + bool, (machine_mode result_mode, machine_mode op_mode, int code), > + default_vcond_supported_p) > + > DEFHOOK > (array_mode, > "Return the mode that GCC should use for an array that has\n\ > diff --git a/gcc/targhooks.c b/gcc/targhooks.c > index 1d12ec54704..2b9a5d12bab 100644 > --- a/gcc/targhooks.c > +++ b/gcc/targhooks.c > @@ -448,6 +448,18 @@ default_scalar_mode_supported_p (scalar_mode mode) > } > } > > +/* Return true if vcond$a$b expander supports vector comparisons using the > CODE > + of type enum tree_code, in which the operands have machine mode OP_MODE > and > + the result has machine mode RESULT_MODE. */ > + > +bool > +default_vcond_supported_p (machine_mode result_mode ATTRIBUTE_UNUSED, > + machine_mode op_mode ATTRIBUTE_UNUSED, > + int code ATTRIBUTE_UNUSED) No need to repeat the documentation here -- just say which hook it's the default for. Thanks, Richard