[PATCH][RFC] Do some vectorizer-friendly canonicalization before vectorization

Richard Guenther rguenther@suse.de
Mon Nov 27 13:59:00 GMT 2006


On Sun, 26 Nov 2006, Dorit Nuzman wrote:

> Richard Guenther <rguenther@suse.de> wrote on 24/11/2006 12:00:38:
> 
> ...
> 
> > > (by the way - do you know why we have that cast from float to double?
> I'm
> > > thinking - if this test actually requires support for doubles, we might
> as
> > > well go back and enable this test for vect_double targets only? Anyhow,
> > > while this would work around the ppc failure above, it won't solve the
> > > above failure for x86, for which we also don't reach the "pattern
> > > recognized").
> >
> > 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

  # i_13 = PHI <i_10(5), 0(2)>;
<L0>:;
  D.1962_7 = x[i_13];
  D.1963_8 = __builtin_powf (D.1962_7, 5.0e-1);
  x[i_13] = D.1963_8;
  i_10 = i_13 + 1;
  if (i_10 <= 255) goto <L5>; else goto <L2>;

(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).

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?

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" } } */



More information about the Gcc-patches mailing list