[PATCH] Fix PR46785

Richard Guenther rguenther@suse.de
Mon Dec 6 10:01:00 GMT 2010


This fixes a missed vectorization of reductions with -ffast-math
where we canonicalize x*x as pow(x, 2).  It also will allow
vectorization of function call results if vectorization with a
veclib is possible.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.

Richard.

2010-12-06  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/46785
	* tree-vect-loop.c (vect_is_simple_reduction_1): Also allow
	call statements as operand definition.

	* gcc.dg/vect/fast-math-vect-reduc-9.c: New testcase.

Index: gcc/tree-vect-loop.c
===================================================================
*** gcc/tree-vect-loop.c	(revision 167432)
--- gcc/tree-vect-loop.c	(working copy)
*************** vect_is_simple_reduction_1 (loop_vec_inf
*** 1970,1975 ****
--- 1970,1976 ----
        && (code == COND_EXPR
            || (def1 && flow_bb_inside_loop_p (loop, gimple_bb (def1))
                && (is_gimple_assign (def1)
+ 		  || is_gimple_call (def1)
    	          || STMT_VINFO_DEF_TYPE (vinfo_for_stmt (def1))
                        == vect_induction_def
     	          || (gimple_code (def1) == GIMPLE_PHI
*************** vect_is_simple_reduction_1 (loop_vec_inf
*** 1985,1990 ****
--- 1986,1992 ----
  	   && (code == COND_EXPR
                 || (def2 && flow_bb_inside_loop_p (loop, gimple_bb (def2))
   	           && (is_gimple_assign (def2)
+ 		       || is_gimple_call (def2)
  	               || STMT_VINFO_DEF_TYPE (vinfo_for_stmt (def2))
                             == vect_induction_def
   	               || (gimple_code (def2) == GIMPLE_PHI
Index: gcc/testsuite/gcc.dg/vect/fast-math-vect-reduc-9.c
===================================================================
*** gcc/testsuite/gcc.dg/vect/fast-math-vect-reduc-9.c	(revision 0)
--- gcc/testsuite/gcc.dg/vect/fast-math-vect-reduc-9.c	(revision 0)
***************
*** 0 ****
--- 1,30 ----
+ /* { dg-require-effective-target vect_float } */
+ 
+ #include "tree-vect.h"
+ 
+ float x[1024];
+ float
+ test (void)
+ {
+   int i;
+   float gosa = 0.0;
+   for (i = 0; i < 1024; ++i)
+     {
+       float tem = x[i];
+       gosa += tem * tem;
+     }
+   return gosa;
+ }
+ 
+ int main (void)
+ {
+   check_vect ();
+ 
+   if (test () != 0.0)
+     abort ();
+ 
+   return 0;
+ }
+ 
+ /* { dg-final { scan-tree-dump "vectorized 1 loops" "vect" } } */
+ /* { dg-final { cleanup-tree-dump "vect" } } */



More information about the Gcc-patches mailing list