On Thu, Jun 16, 2011 at 10:00 AM, Richard Guenther <richard.guent...@gmail.com> wrote: > On Thu, Jun 16, 2011 at 8:54 AM, Ira Rosen <ira.ro...@linaro.org> wrote: >> Hi, >> >> For >> >> unsigned char in[N]; >> int out[N]; >> for (i = 0; i < N; i++) >> out[i] = in[i] * 300; >> >> in[i] is first promoted to int and then multiplied by 300. This >> over-promotion prevents the vectorizer from using the widen-mult >> pattern here. >> >> This patch checks if a constant fits an intermediate type (short in >> this example) and generates widen-mult operation on that type. I.e., >> the following sequence: >> >> type a_t; >> TYPE a_T, prod_T; >> >> S1 a_t = ; >> S3 a_T = (TYPE) a_t; >> S5 prod_T = a_T * CONST; >> >> is marked as: >> >> type a_t; >> interm_type a_it; >> TYPE a_T, prod_T, prod_T'; >> >> S1 a_t = ; >> S3 a_T = (TYPE) a_t; >> '--> a_it = (interm_type) a_t; >> S5 prod_T = a_T * CONST; >> '--> prod_T' = a_it w* CONST; >> >> >> by the pattern detection (and later vectorized using the new statements). >> >> Bootstrapped and tested on powerpc64-suse-linux. >> Comments are welcome. > > + && TREE_CODE (half_type1) == INTEGER_TYPE) > + { > + if (int_fits_type_p (oprnd0, half_type1)) > > I believe you need to check that oprnd0 is a INTEGER_CST before calling > int_fits_type_p. > > + { > + /* OPRND0 is a constant of HALF_TYPE1. */ > > The whole following block is repeated twice, nearly identical - that asks > for factoring it out. > > Otherwise the patch looks reasonable.
Oh ... + /* TYPE is 4 times bigger than HALF_TYPE1, try widen-mult for + a type 2 times bigger than HALF_TYPE1. */ + new_type = lang_hooks.types.type_for_size ( + TYPE_PRECISION (type) / 2, + TYPE_UNSIGNED (type)); don't use lang-hooks but instead use build_nonstandard_integer_type here. Richard. > Thanks, > Richard. > >> Thanks, >> Ira >> >> >> ChangeLog: >> >> * tree-vectorizer.h (vect_recog_func_ptr): Change the first >> argument to be a VEC of statements. >> * tree-vect-loop.c (vect_determine_vectorization_factor): >> Remove the assert that pattern statements have to have their >> vector type set. >> * tree-vect-patterns.c (langhooks.h): Include. >> (vect_recog_widen_sum_pattern): Change the first argument >> to be a VEC of statements. Update documentation. >> (vect_recog_dot_prod_pattern, vect_recog_pow_pattern): >> Likewise. >> (vect_recog_widen_mult_pattern): Likewise and support >> multiplication by a constant that fits an intermediate type. >> Use int_fits_type_p instead of comparing to types max and >> min values. >> (vect_pattern_recog_1): Update vect_recog_func_ptr and its >> call. Handle additional pattern statements if necessary. >> * Makefile.in (tree-vect-patterns.c): Add dependency on >> langhooks.h. >> >> testsuite/ChangeLog: >> >> * gcc.dg/vect/vect-widen-mult-half-u8.c: New test. >> >