This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH][RFC] Do some vectorizer-friendly canonicalization before vectorization
- From: Dorit Nuzman <DORIT at il dot ibm dot com>
- To: Richard Guenther <rguenther at suse dot de>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Mon, 27 Nov 2006 16:15:27 +0200
- Subject: Re: [PATCH][RFC] Do some vectorizer-friendly canonicalization before vectorization
Richard Guenther <rguenther@suse.de> wrote on 27/11/2006 15:24:45:
> > > I think the cast may be because powf is C99 or the ppc target you are
> > > testing doesn't have it at all?
> >
> > I see the same thing on x86
> >
> > > Does it work for you if you enable
> > > -std=c99?
> > >
> >
> > -std=c99 doesn't make a difference...
>
> Hm, ok. I'm going to restrict this to x86_64 then, where I have
>
...
> (no cast) and i686 (no cast as well) at the point i686 backend
> support for vectorization of sqrt goes in (I'll resubmit it
> after testing now that the generic support for vectorizing
> functions is in).
>
wonder why I see the cast on my system (i386-redhat-linux).
Anyhow, I think better to avoid enabling for specific targets, but use
target keywords instead. It would be good to enable the test for all
relevant targets (say, vec_float), and have it xfail on those that don't
support the math builtins yet.
> Meanwhile the following resolves the pattern issues (leaving the
> above testcase alone for now).
>
> Bootstrapped & tested on x86_64-unknown-linux-gnu.
>
> Ok for mainline?
>
ok with me (given the followup testcase fix)
(though I can't approve).
dorit
> Thanks,
> Richard.
>
> 2006-11-27 Richard Guenther <rguenther@suse.de>
>
> * tree-vectorizer.h (vectorizable_function): Export.
> * tree-vect-transform.c (vectorizable_function): Likewise.
> * tree-vect-patterns.c (vect_recog_pow_pattern): Set
> type_in to scalar type in recognition of squaring.
> Make sure the target can vectorize sqrt in recognition
> of sqrt, set type_in to vector type in this case.
>
> * gcc.dg/vect/vect-pow-1.c: Rename ...
> * gcc.dg/vect/fast-math-vect-pow-1.c: ... to this. Use
> floats instead of doubles, check successful vectorization.
>
> Index: tree-vectorizer.h
> ===================================================================
> *** tree-vectorizer.h (revision 119249)
> --- tree-vectorizer.h (working copy)
> *************** extern bool vectorizable_operation (tree
> *** 398,403 ****
> --- 398,404 ----
> extern bool vectorizable_type_promotion (tree, block_stmt_iterator
> *, tree *);
> extern bool vectorizable_type_demotion (tree, block_stmt_iterator
> *, tree *);
> extern bool vectorizable_assignment (tree, block_stmt_iterator *, tree
*);
> + extern bool vectorizable_function (tree, tree);
> extern bool vectorizable_call (tree, block_stmt_iterator *, tree *);
> extern bool vectorizable_condition (tree, block_stmt_iterator *, tree
*);
> extern bool vectorizable_live_operation (tree, block_stmt_iterator
> *, tree *);
> Index: tree-vect-patterns.c
> ===================================================================
> *** tree-vect-patterns.c (revision 119249)
> --- tree-vect-patterns.c (working copy)
> *************** vect_recog_pow_pattern (tree last_stmt,
> *** 466,472 ****
> /* We now have a pow or powi builtin function call with a constant
> exponent. */
>
> - *type_in = get_vectype_for_scalar_type (TREE_TYPE (base));
> *type_out = NULL_TREE;
>
> /* Catch squaring. */
> --- 466,471 ----
> *************** vect_recog_pow_pattern (tree last_stmt,
> *** 474,480 ****
> && tree_low_cst (exp, 0) == 2)
> || (TREE_CODE (exp) == REAL_CST
> && REAL_VALUES_EQUAL (TREE_REAL_CST (exp), dconst2)))
> ! return build2 (MULT_EXPR, TREE_TYPE (base), base, base);
>
> /* Catch square root. */
> if (TREE_CODE (exp) == REAL_CST
> --- 473,482 ----
> && tree_low_cst (exp, 0) == 2)
> || (TREE_CODE (exp) == REAL_CST
> && REAL_VALUES_EQUAL (TREE_REAL_CST (exp), dconst2)))
> ! {
> ! *type_in = TREE_TYPE (base);
> ! return build2 (MULT_EXPR, TREE_TYPE (base), base, base);
> ! }
>
> /* Catch square root. */
> if (TREE_CODE (exp) == REAL_CST
> *************** vect_recog_pow_pattern (tree last_stmt,
> *** 482,488 ****
> {
> tree newfn = mathfn_built_in (TREE_TYPE (base), BUILT_IN_SQRT);
> tree newarglist = build_tree_list (NULL_TREE, base);
> ! return build_function_call_expr (newfn, newarglist);
> }
>
> return NULL_TREE;
> --- 484,496 ----
> {
> tree newfn = mathfn_built_in (TREE_TYPE (base), BUILT_IN_SQRT);
> tree newarglist = build_tree_list (NULL_TREE, base);
> ! *type_in = get_vectype_for_scalar_type (TREE_TYPE (base));
> ! if (*type_in)
> ! {
> ! newfn = build_function_call_expr (newfn, newarglist);
> ! if (vectorizable_function (newfn, *type_in))
> ! return newfn;
> ! }
> }
>
> return NULL_TREE;
> Index: tree-vect-transform.c
> ===================================================================
> *** tree-vect-transform.c (revision 119249)
> --- tree-vect-transform.c (working copy)
> *************** vectorizable_reduction (tree stmt, block
> *** 1570,1576 ****
> true if the target has a vectorized version of the function,
> or false if the function cannot be vectorized. */
>
> ! static bool
> vectorizable_function (tree call, tree vectype)
> {
> tree fndecl = get_callee_fndecl (call);
> --- 1570,1576 ----
> true if the target has a vectorized version of the function,
> or false if the function cannot be vectorized. */
>
> ! bool
> vectorizable_function (tree call, tree vectype)
> {
> tree fndecl = get_callee_fndecl (call);
> Index: testsuite/gcc.dg/vect/fast-math-vect-pow-1.c
> ===================================================================
> *** testsuite/gcc.dg/vect/fast-math-vect-pow-1.c (revision 119115)
> --- testsuite/gcc.dg/vect/fast-math-vect-pow-1.c (working copy)
> ***************
> *** 1,7 ****
> /* { dg-do compile } */
> ! /* { dg-options "-O2 -ftree-vectorize -ffast-math -fdump-tree-
> vect-details" } */
>
> ! double x[256];
>
> void foo(void)
> {
> --- 1,7 ----
> /* { dg-do compile } */
> ! /* { dg-require-effective-target vect_float } */
>
> ! float x[256];
>
> void foo(void)
> {
> *************** void foo(void)
> *** 10,14 ****
> x[i] = x[i] * x[i];
> }
>
> ! /* { dg-final { scan-tree-dump "pattern recognized" "vect" } } */
> /* { dg-final { cleanup-tree-dump "vect" } } */
> --- 10,14 ----
> x[i] = x[i] * x[i];
> }
>
> ! /* { dg-final { scan-tree-dump "vectorized 1 loops" "vect" } } */
> /* { dg-final { cleanup-tree-dump "vect" } } */