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]

[4.1/4.2] fix pr26821, vectors getting in the way of tree-ssa-math-opts.c


This patch fixes PR26821 by supporting reciprocal computation of vectors. We just create a {1.0, 1.0, 1.0, 1.0} vector instead of a single REAL_CST.

Note that the same is not needed for COMPLEX_TYPE, because complex arithmetic is lowered much earlier in the pipeline.

The testcase fits nicely in the vectorizer testsuite.

Bootstrapped/regtested i686-pc-linux-gnu, ok for 4.1 and mainline?

Paolo
2006-03-23  Paolo Bonzini  <bonzini@gnu.org>

	PR tree-optimization/26821
	* tree-ssa-math-opts.c (get_one_constant): New.
	(insert_reciprocals): Use it.

2006-03-23  Paolo Bonzini  <bonzini@gnu.org>

	PR tree-optimization/26821
	* gcc.dg/vect/vect-recip.c: New.

Index: /home/bonzinip/gcc-fwprop/gcc/tree-ssa-math-opts.c
===================================================================
--- /home/bonzinip/gcc-fwprop/gcc/tree-ssa-math-opts.c	(revision 112224)
+++ /home/bonzinip/gcc-fwprop/gcc/tree-ssa-math-opts.c	(working copy)
@@ -279,6 +279,35 @@ is_division_by (tree use_stmt, tree def)
 	 && TREE_OPERAND (TREE_OPERAND (use_stmt, 1), 1) == def;
 }
 
+/* Return the LHS of a RDIV_EXPR that computes a reciprocal in type TYPE.  */
+static tree
+get_one_constant (tree type)
+{
+  tree scalar, cst;
+  int i;
+
+  gcc_assert (FLOAT_TYPE_P (type));
+  switch (TREE_CODE (type))
+    {
+    case REAL_TYPE:
+      return build_real (type, dconst1);
+
+    case VECTOR_TYPE:
+      scalar = build_real (TREE_TYPE (type), dconst1);
+
+      /* Create 'vect_cst_ = {cst,cst,...,cst}'  */
+      cst = NULL_TREE;
+      for (i = TYPE_VECTOR_SUBPARTS (type); --i >= 0; )
+        cst = tree_cons (NULL_TREE, scalar, cst);
+
+      return build_vector (type, cst);
+
+    default:
+      /* Complex operations have been split already.  */
+      gcc_unreachable ();
+    }
+}
+
 /* Walk the subset of the dominator tree rooted at OCC, setting the
    RECIP_DEF field to a definition of 1.0 / DEF that can be used in
    the given basic block.  The field may be left NULL, of course,
@@ -304,8 +333,8 @@ insert_reciprocals (block_stmt_iterator 
       type = TREE_TYPE (def);
       recip_def = make_rename_temp (type, "reciptmp");
       new_stmt = build2 (MODIFY_EXPR, void_type_node, recip_def,
-		         fold_build2 (RDIV_EXPR, type,
-				      build_real (type, dconst1), def));
+		         fold_build2 (RDIV_EXPR, type, get_one_constant (type),
+				      def));
   
   
       if (occ->bb_has_division)


/* { dg-do compile } */
/* { dg-require-effective-target vect_float } */

void f(float *__restrict__ qa, float *__restrict__ qb,
       float *__restrict__ qc, float *__restrict__ rtrms)
{
  int i;
  static double qam[600];
  static double qbm[600];
  static double qcm[600];
  for(i=0;i<600;i++)
  {
    double a = rtrms[i];
    qam[i] = qa[i]/a;
    qbm[i] = qb[i]/a;
    qcm[i] = qc[i]/a;
  }
}

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