This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


On Thu, 23 Nov 2006, Dorit Nuzman wrote:

> Richard Guenther <rguenther@suse.de> wrote on 23/11/2006 12:39:40:
> 
> > The following passes for me on x86_64-unknown-linux-gnu.  Can you check
> > it works on ppc?
> >
> 
> sure:
> 
> the fast-math test passes, but the second test ICEs:
> 
> /home/dorit/mainline_dn/build/gcc/xgcc -B/home/dorit/mainline_dn/build/gcc/
> /home/dorit/mainline_dn/gcc/gcc/testsuite/gcc.dg/vect/no-math-errno-vect-pow-2.c
>    -O2 -ftree-vectorize -maltivec -fdump-tree-vect-details -fno-math-errno
> -fno-show-column -S  -o no-math-errno-vect-pow-2.s
> /home/dorit/mainline_dn/gcc/gcc/testsuite/gcc.dg/vect/no-math-errno-vect-pow-2.c:
>  In function ?foo?:
> /home/dorit/mainline_dn/gcc/gcc/testsuite/gcc.dg/vect/no-math-errno-vect-pow-2.c:7:
>  internal compiler error: Segmentation fault
> 
> gdb:
> Program received signal SIGSEGV, Segmentation fault.
> 0x104f9460 in vect_pattern_recog (loop_vinfo=Variable "loop_vinfo" is not
> available.
> ) at ../../gcc/gcc/tree-vect-patterns.c:631
> 631       if (VECTOR_MODE_P (TYPE_MODE (type_in)))
> (gdb)
> 
> This is because 'base' (in vect_recog_pow_pattern) is actually of type
> 'double' (not 'float' as we would have expected), because there's a cast to
> double - this is the dump before the vectorizer:
> 
> foo ()
> {
>   unsigned int ivtmp.34;
>   int pretmp.27;
>   int i;
>   float D.1999;
>   double D.1998;
>   double D.1997;
>   float D.1996;
> 
> <bb 2>:
> 
>   # ivtmp.34_1 = PHI <ivtmp.34_2(4), 256(2)>;
>   # i_15 = PHI <i_12(4), 0(2)>;
> <L0>:;
>   D.1996_7 = x[i_15];
>   D.1997_8 = (double) D.1996_7;
>   D.1998_9 = __builtin_pow (D.1997_8, 5.0e-1);
>   D.1999_10 = (float) D.1998_9;
>   x[i_15] = D.1999_10;
>   i_12 = i_15 + 1;
>   ivtmp.34_2 = ivtmp.34_1 - 1;
>   if (ivtmp.34_2 != 0) goto <L5>; else goto <L2>;
> 
> <L5>:;
>   goto <bb 3> (<L0>);
> 
> <L2>:;
>   return;
> 
> 
> So this line probably fails to find a vectype:
> *type_in = get_vectype_for_scalar_type (TREE_TYPE (base));
> and we don't check for that...
> 
> We need to check for target-support even if it's not a new tree-code, like
> it's done in the other vect_recog_X_pattern functions.

Ok, so consider the pow (x, 0.5) pattern matching removed until the
function vectorizing is approved (where we then can check for support).

Richard.

> 
> Gotta run now,
> 
> dorit
> 
> 
> > Thanks,
> > Richard.
> >
> > 2006-11-23  Richard Guenther  <rguenther@suse.de>
> >
> >    * tree-vect-patterns.c (vect_recog_pow_pattern): Set
> >    type_in to scalar type in recognition of squaring.
> >
> >    * gcc.dg/vect/vect.exp: Add support for -fno-math-errno tests.
> >    * 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.
> >    * gcc.dg/vect/vect-pow-2.c: Rename ...
> >    * gcc.dg/vect/no-math-errno-vect-pow-1.c: .. to this.  Use
> >    floats instead of doubles.
> >
> > Index: tree-vect-patterns.c
> > ===================================================================
> > *** tree-vect-patterns.c   (revision 119115)
> > --- 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,487 ****
> > --- 484,490 ----
> >       {
> >         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));
> >         return build_function_call_expr (newfn, newarglist);
> >       }
> 
> upto here it
> >
> > Index: testsuite/gcc.dg/vect/vect-pow-1.c
> > ===================================================================
> > *** testsuite/gcc.dg/vect/vect-pow-1.c   (revision 119115)
> > --- testsuite/gcc.dg/vect/vect-pow-1.c   (working copy)
> > ***************
> > *** 1,14 ****
> > - /* { dg-do compile } */
> > - /* { dg-options "-O2 -ftree-vectorize -ffast-math -fdump-tree-
> > vect-details" } */
> > -
> > - double x[256];
> > -
> > - void foo(void)
> > - {
> > -   int i;
> > -   for (i=0; i<256; ++i)
> > -     x[i] = x[i] * x[i];
> > - }
> > -
> > - /* { dg-final { scan-tree-dump "pattern recognized" "vect" } } */
> > - /* { dg-final { cleanup-tree-dump "vect" } } */
> > --- 0 ----
> > Index: testsuite/gcc.dg/vect/vect-pow-2.c
> > ===================================================================
> > *** testsuite/gcc.dg/vect/vect-pow-2.c   (revision 119115)
> > --- testsuite/gcc.dg/vect/vect-pow-2.c   (working copy)
> > ***************
> > *** 1,14 ****
> > - /* { dg-do compile } */
> > - /* { dg-options "-O2 -ftree-vectorize -fno-math-errno -fdump-tree-
> > vect-details" } */
> > -
> > - double x[256];
> > -
> > - void foo(void)
> > - {
> > -   int i;
> > -   for (i=0; i<256; ++i)
> > -     x[i] = __builtin_pow (x[i], 0.5);
> > - }
> > -
> > - /* { dg-final { scan-tree-dump "pattern recognized" "vect" } } */
> > - /* { dg-final { cleanup-tree-dump "vect" } } */
> > --- 0 ----
> > 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" } } */
> > Index: testsuite/gcc.dg/vect/no-math-errno-vect-pow-1.c
> > ===================================================================
> > *** testsuite/gcc.dg/vect/no-math-errno-vect-pow-1.c   (revision 119115)
> > --- testsuite/gcc.dg/vect/no-math-errno-vect-pow-1.c   (working copy)
> > ***************
> > *** 1,13 ****
> >   /* { dg-do compile } */
> > ! /* { dg-options "-O2 -ftree-vectorize -fno-math-errno -fdump-tree-
> > vect-details" } */
> >
> > ! double x[256];
> >
> >   void foo(void)
> >   {
> >     int i;
> >     for (i=0; i<256; ++i)
> > !     x[i] = __builtin_pow (x[i], 0.5);
> >   }
> >
> >   /* { dg-final { scan-tree-dump "pattern recognized" "vect" } } */
> > --- 1,13 ----
> >   /* { dg-do compile } */
> > ! /* { dg-require-effective-target vect_float } */
> >
> > ! float x[256];
> >
> >   void foo(void)
> >   {
> >     int i;
> >     for (i=0; i<256; ++i)
> > !     x[i] = __builtin_powf (x[i], 0.5);
> >   }
> >
> >   /* { dg-final { scan-tree-dump "pattern recognized" "vect" } } */
> > Index: testsuite/gcc.dg/vect/vect.exp
> > ===================================================================
> > *** testsuite/gcc.dg/vect/vect.exp   (revision 119115)
> > --- testsuite/gcc.dg/vect/vect.exp   (working copy)
> > *************** lappend DEFAULT_VECTCFLAGS "-ffast-math"
> > *** 97,102 ****
> > --- 97,108 ----
> >   dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/fast-math-
> > vect*.\[cS\]]]  \
> >      "" $DEFAULT_VECTCFLAGS
> >
> > + # -fno-math-errno tests
> > + set DEFAULT_VECTCFLAGS $SAVED_DEFAULT_VECTCFLAGS
> > + lappend DEFAULT_VECTCFLAGS "-fno-math-errno"
> > + dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/no-math-errno-
> > vect*.\[cS\]]]  \
> > +    "" $DEFAULT_VECTCFLAGS
> > +
> >   # -fwrapv tests
> >   set DEFAULT_VECTCFLAGS $SAVED_DEFAULT_VECTCFLAGS
> >   lappend DEFAULT_VECTCFLAGS "-fwrapv"

--
Richard Guenther <rguenther@suse.de>
Novell / SUSE Labs


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]