[PATCH] Add vectorization of sqrt to the i386 backend

Richard Guenther rguenther@suse.de
Mon Nov 27 15:04:00 GMT 2006


This adds vectorization capability of sqrt to the i386 backend and fixes
up the sqrt vectorization testcase from the pattern vectorization 
enhacement.

Bootstrapped & tested on x86_64-unknown-linux-gnu.

Ok for mainline?

Thanks,
Richard.

2006-11-27  Richard Guenther  <rguenther@suse.de>

	* config/i386/i386.c (ix86_builtin_vectorized_function): Declare.
	(TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION): Define.
	(ix86_builtin_vectorized_function): New function to vectorize
	sqrt.

	* gcc.dg/vect/vect.exp: Add support for -fno-math-errno tests.
	* gcc.dg/vect/vect-pow-2.c: Rename to ...
	* gcc.dg/vect/no-math-errno-vect-pow-1.c: ... this.  Restrict
	to x86_64 and i?86.

Index: config/i386/i386.c
===================================================================
--- config/i386/i386.c	(revision 119249)
+++ config/i386/i386.c	(working copy)
@@ -1275,6 +1275,7 @@ static bool ix86_pass_by_reference (CUMU
 				    tree, bool);
 static void ix86_init_builtins (void);
 static rtx ix86_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
+static tree ix86_builtin_vectorized_function (enum built_in_function, tree);
 static const char *ix86_mangle_fundamental_type (tree);
 static tree ix86_stack_protect_fail (void);
 static rtx ix86_internal_arg_pointer (void);
@@ -1339,6 +1340,8 @@ static section *x86_64_elf_select_sectio
 #define TARGET_INIT_BUILTINS ix86_init_builtins
 #undef TARGET_EXPAND_BUILTIN
 #define TARGET_EXPAND_BUILTIN ix86_expand_builtin
+#undef TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION
+#define TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION ix86_builtin_vectorized_function
 
 #undef TARGET_ASM_FUNCTION_EPILOGUE
 #define TARGET_ASM_FUNCTION_EPILOGUE ix86_output_function_epilogue
@@ -16866,6 +16869,41 @@ ix86_expand_builtin (tree exp, rtx targe
   gcc_unreachable ();
 }
 
+/* Returns a function decl for a vectorized version of the builtin function
+   with builtin function code FN and the result vector type TYPE, or NULL_TREE
+   if it is not available.  */
+
+static tree
+ix86_builtin_vectorized_function (enum built_in_function fn, tree type)
+{
+  enum machine_mode el_mode;
+  int n;
+
+  if (TREE_CODE (type) != VECTOR_TYPE)
+    return NULL_TREE;
+
+  el_mode = TYPE_MODE (TREE_TYPE (type));
+  n = TYPE_VECTOR_SUBPARTS (type);
+
+  switch (fn)
+    {
+    case BUILT_IN_SQRT:
+      if (el_mode == DFmode && n == 2)
+	return ix86_builtins[IX86_BUILTIN_SQRTPD];
+      return NULL_TREE;
+
+    case BUILT_IN_SQRTF:
+      if (el_mode == SFmode && n == 4)
+	return ix86_builtins[IX86_BUILTIN_SQRTPS];
+      return NULL_TREE;
+
+    default:
+      ;
+    }
+
+  return NULL_TREE;
+}
+
 /* Store OPERAND to the memory after reload is completed.  This means
    that we can't easily use assign_stack_local.  */
 rtx
Index: testsuite/gcc.dg/vect/vect.exp
===================================================================
--- testsuite/gcc.dg/vect/vect.exp	(revision 119249)
+++ testsuite/gcc.dg/vect/vect.exp	(working copy)
@@ -97,6 +97,12 @@ lappend DEFAULT_VECTCFLAGS "-ffast-math"
 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"
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,5 ****
! /* { dg-do compile } */
! /* { dg-options "-O2 -ftree-vectorize -fno-math-errno -fdump-tree-vect-details" } */
  
  double x[256];
  
--- 1,5 ----
! /* { dg-do compile { target x86_64-*-* i?86-*-* } } */
! /* { dg-require-effective-target vect_double } */
  
  double x[256];
  



More information about the Gcc-patches mailing list