From fcd2028f676c4e4e87b011a116cfebe104dee486 Mon Sep 17 00:00:00 2001
From: rguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Tue, 5 Dec 2006 15:42:54 +0000
Subject: [PATCH] 2006-12-05  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.  Require
	vect_double, xfail for spu*-*-*.


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@119542 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog                                 |  7 ++++
 gcc/config/i386/i386.c                        | 38 +++++++++++++++++++
 gcc/testsuite/ChangeLog                       |  7 ++++
 ...ect-pow-2.c => no-math-errno-vect-pow-1.c} |  4 +-
 gcc/testsuite/gcc.dg/vect/vect.exp            |  6 +++
 5 files changed, 60 insertions(+), 2 deletions(-)
 rename gcc/testsuite/gcc.dg/vect/{vect-pow-2.c => no-math-errno-vect-pow-1.c} (54%)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 80a47cdc69b9..a9ef3fab670f 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2006-12-05  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.
+
 2006-12-05  Bernd Schmidt  <bernd.schmidt@analog.com>
 
 	* config/bfin/bfin.c (output_file_start): Fix comment which referred to
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 22ed4a9c32c3..40d96a045432 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -1354,6 +1354,7 @@ static bool ix86_pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode,
 				    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);
@@ -1418,6 +1419,8 @@ static section *x86_64_elf_select_section (tree decl, int reloc,
 #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
@@ -17639,6 +17642,41 @@ ix86_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED,
   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
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 4ed0ce6d19a2..0d6d81449024 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2006-12-05  Richard Guenther  <rguenther@suse.de>
+
+	* 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.  Require
+	vect_double, xfail for spu*-*-*.
+
 2006-12-04  Tobias Burnus  <burnus@net-b.de>
 
 	PR fortran/29962
diff --git a/gcc/testsuite/gcc.dg/vect/vect-pow-2.c b/gcc/testsuite/gcc.dg/vect/no-math-errno-vect-pow-1.c
similarity index 54%
rename from gcc/testsuite/gcc.dg/vect/vect-pow-2.c
rename to gcc/testsuite/gcc.dg/vect/no-math-errno-vect-pow-1.c
index dc3e7c0a486a..03de93bf46c6 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-pow-2.c
+++ b/gcc/testsuite/gcc.dg/vect/no-math-errno-vect-pow-1.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -ftree-vectorize -fno-math-errno -fdump-tree-vect-details" } */
+/* { dg-require-effective-target vect_double } */
 
 double x[256];
 
@@ -10,5 +10,5 @@ void foo(void)
     x[i] = __builtin_pow (x[i], 0.5);
 }
 
-/* { dg-final { scan-tree-dump "pattern recognized" "vect" } } */
+/* { dg-final { scan-tree-dump "pattern recognized" "vect" { xfail spu*-*-* } } } */
 /* { dg-final { cleanup-tree-dump "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/vect.exp b/gcc/testsuite/gcc.dg/vect/vect.exp
index 0de2be39a521..ed5693f0964a 100644
--- a/gcc/testsuite/gcc.dg/vect/vect.exp
+++ b/gcc/testsuite/gcc.dg/vect/vect.exp
@@ -102,6 +102,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"
-- 
GitLab