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]

[PATCH][GCC][mid-end] Add generic test for xorsign (x * copysign (1, y))


Hi All,

Since XORSIGN is a mid-end transformation I'm adding a generic test
to check for targets that support it if the transformation has been
carried out or not in tree.

Regtested on aarch64-none-linux-gnu, arm-none-eabi
and x86_64-pc-linux-gnu with no regressions

Ok for trunk?

gcc/
2017-08-22  Tamar Christina  <tamar.christina@arm.com>

	PR middle-end/19706
	* doc/sourcebuild.texi (Other hardware attributes):
	Document xorsign.


gcc/testsuite
2017-08-22  Tamar Christina  <tamar.christina@arm.com>

	PR middle-end/19706
	* gcc.dg/tree-ssa/pr19706.c: New.
	* lib/target-supports.exp (check_effective_target_xorsign): New.

-- 
diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
index e6313dc031ef5b2b5a72180bccf1e876812efe48..a1ca417b5c810b3e16520bf68944be709e0b8e92 100644
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -1908,6 +1908,9 @@ or @code{EM_SPARCV9} executables.
 @item vect_cmdline_needed
 Target requires a command line argument to enable a SIMD instruction set.
 
+@item xorsign
+Target supports the xorsign optab expansion.
+
 @end table
 
 @subsubsection Environment attributes
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr19706.c b/gcc/testsuite/gcc.dg/tree-ssa/pr19706.c
new file mode 100644
index 0000000000000000000000000000000000000000..92dd5db5a979b57cd7e575bc182f4803d82936d7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr19706.c
@@ -0,0 +1,86 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+/* { dg-require-effective-target xorsign } */
+/* { dg-require-effective-target arm_v8_neon_ok { target { arm*-*-* } } } */
+/* { dg-add-options arm_v8_neon } */
+
+double
+check_d_pos (double x, double y)
+{
+  return x * __builtin_copysign (1.0, y);
+}
+
+float
+check_f_pos (float x, float y)
+{
+  return x * __builtin_copysignf (1.0f, y);
+}
+
+long double
+check_l_pos (long double x, long double y)
+{
+  return x * __builtin_copysignl (1.0, y);
+}
+
+/* --------------- */
+
+double
+check_d_neg (double x, double y)
+{
+  return x * __builtin_copysign (-1.0, y);
+}
+
+float
+check_f_neg (float x, float y)
+{
+  return x * __builtin_copysignf (-1.0f, y);
+}
+
+long double
+check_l_neg (long double x, long double y)
+{
+  return x * __builtin_copysignl (-1.0, y);
+}
+
+/* --------------- */
+
+double
+check_d_pos_rev (double x, double y)
+{
+  return __builtin_copysign (1.0, y) * x;
+}
+
+float
+check_f_pos_rev (float x, float y)
+{
+  return __builtin_copysignf (1.0f, y) * x;
+}
+
+long double
+check_l_pos_rev (long double x, long double y)
+{
+  return __builtin_copysignl (1.0, y) * x;
+}
+
+/* --------------- */
+
+double
+check_d_neg_rev (double x, double y)
+{
+  return __builtin_copysign (-1.0, y) * x;
+}
+
+float
+check_f_neg_rev (float x, float y)
+{
+  return __builtin_copysignf (-1.0f, y) * x;
+}
+
+long double
+check_l_neg_rev (long double x, long double y)
+{
+  return __builtin_copysignl (-1.0, y) * x;
+}
+
+/* { dg-final { scan-tree-dump "XORSIGN" "optimized" } } */
+/* { dg-final { scan-tree-dump-not "copysign" "optimized" } } */
\ No newline at end of file
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index 5219fbf4671e83a6fa7affdab926115e8a23f9cb..db0c0ff089acba29a4c3c177d4ebacd40ce1a631 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -5332,6 +5332,28 @@ proc check_effective_target_vect_perm_short { } {
     return $et_vect_perm_short_saved($et_index)
 }
 
+# Return 1 if the target plus current options supports folding of
+# copysign into XORSIGN.
+#
+# This won't change for different subtargets so cache the result.
+
+proc check_effective_target_xorsign { } {
+    global et_xorsign_saved
+    global et_index
+
+    if [info exists et_xorsign_saved($et_index)] {
+        verbose "check_effective_target_xorsign: using cached result" 2
+    } else {
+	set et_xorsign_saved($et_index) 0
+        if { [istarget aarch64*-*-*] || [istarget arm*-*-*] } {
+	    set et_xorsign_saved($et_index) 1
+        }
+    }
+    verbose "check_effective_target_xorsign:\
+	     returning $et_xorsign_saved($et_index)" 2
+    return $et_xorsign_saved($et_index)
+}
+
 # Return 1 if the target plus current options supports a vector
 # widening summation of *short* args into *int* result, 0 otherwise.
 #


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