aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPrathamesh Kulkarni <prathamesh.kulkarni@linaro.org>2016-07-27 15:09:10 +0000
committerPrathamesh Kulkarni <prathamesh3492@gcc.gnu.org>2016-07-27 15:09:10 +0000
commit8c6961cab006c59be0e4632b21e829c9b3fa9a50 (patch)
tree5b760477f103aff90ce4176e8d8ee2085e644d87 /gcc
parent81a12b7606c58a7d6bea3151be426ef3e91b45ea (diff)
downloadgcc-8c6961cab006c59be0e4632b21e829c9b3fa9a50.zip
gcc-8c6961cab006c59be0e4632b21e829c9b3fa9a50.tar.gz
gcc-8c6961cab006c59be0e4632b21e829c9b3fa9a50.tar.bz2
re PR middle-end/71078 (x/abs(x) -> sign(1.0,x))
2016-07-27 Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org> PR middle-end/71078 * match.pd (x / abs(x) -> copysign(1.0, x)): New pattern. testsuite/ * gcc.dg/tree-ssa/pr71078-1.c: New test-case. * gcc.dg/tree-ssa/pr71078-2.c: Likewise. * gcc.dg/tree-ssa/pr71078-3.c: Likewise. From-SVN: r238787
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/match.pd14
-rw-r--r--gcc/testsuite/ChangeLog7
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/pr71078-1.c29
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/pr71078-2.c29
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/pr71078-3.c12
6 files changed, 96 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index e00b2c4..e6abaea 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2016-07-27 Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org>
+
+ PR middle-end/71078
+ * match.pd (x / abs(x) -> copysign(1.0, x)): New pattern.
+
2016-07-27 David Malcolm <dmalcolm@redhat.com>
* system.h (STATIC_ASSERT): Use static_assert if building
diff --git a/gcc/match.pd b/gcc/match.pd
index 6c2ec82..2380d90d 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -195,6 +195,20 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
&& ! HONOR_INFINITIES (type))
{ build_minus_one_cst (type); }))
+/* PR71078: x / abs(x) -> copysign (1.0, x) */
+(simplify
+ (rdiv:C (convert? @0) (convert? (abs @0)))
+ (if (SCALAR_FLOAT_TYPE_P (type)
+ && ! HONOR_NANS (type)
+ && ! HONOR_INFINITIES (type))
+ (switch
+ (if (types_match (type, float_type_node))
+ (BUILT_IN_COPYSIGNF { build_one_cst (type); } (convert @0)))
+ (if (types_match (type, double_type_node))
+ (BUILT_IN_COPYSIGN { build_one_cst (type); } (convert @0)))
+ (if (types_match (type, long_double_type_node))
+ (BUILT_IN_COPYSIGNL { build_one_cst (type); } (convert @0))))))
+
/* In IEEE floating point, x/1 is not equivalent to x for snans. */
(simplify
(rdiv @0 real_onep)
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 3f8129a..3f7e5a7 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2016-07-27 Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org>
+
+ PR middle-end/71078
+ * gcc.dg/tree-ssa/pr71078-1.c: New test-case.
+ * gcc.dg/tree-ssa/pr71078-2.c: Likewise.
+ * gcc.dg/tree-ssa/pr71078-3.c: Likewise.
+
2016-07-27 Richard Biener <rguenther@suse.de>
* gcc.dg/vect/costmodel/x86_64/costmodel-pr68961.c: Remove.
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr71078-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr71078-1.c
new file mode 100644
index 0000000..6204c14
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr71078-1.c
@@ -0,0 +1,29 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -ffast-math -fdump-tree-forwprop-details" } */
+
+#include <math.h>
+
+float f1(float x)
+{
+ float t1 = fabsf (x);
+ float t2 = x / t1;
+ return t2;
+}
+
+double f2(double x)
+{
+ double t1 = fabs (x);
+ double t2 = x / t1;
+ return t2;
+}
+
+long double f3 (long double x)
+{
+ long double t1 = fabsl (x);
+ long double t2 = x / t1;
+ return t2;
+}
+
+/* { dg-final { scan-tree-dump "__builtin_copysignf" "forwprop1" } } */
+/* { dg-final { scan-tree-dump "__builtin_copysign" "forwprop1" } } */
+/* { dg-final { scan-tree-dump "__builtin_copysignl" "forwprop1" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr71078-2.c b/gcc/testsuite/gcc.dg/tree-ssa/pr71078-2.c
new file mode 100644
index 0000000..96485af
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr71078-2.c
@@ -0,0 +1,29 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -ffast-math -fdump-tree-forwprop-details" } */
+
+#include <math.h>
+
+float f1(float x)
+{
+ float t1 = fabsf (x);
+ float t2 = t1 / x;
+ return t2;
+}
+
+double f2(double x)
+{
+ double t1 = fabs (x);
+ double t2 = t1 / x;
+ return t2;
+}
+
+long double f3 (long double x)
+{
+ long double t1 = fabsl (x);
+ long double t2 = t1 / x;
+ return t2;
+}
+
+/* { dg-final { scan-tree-dump "__builtin_copysignf" "forwprop1" } } */
+/* { dg-final { scan-tree-dump "__builtin_copysign" "forwprop1" } } */
+/* { dg-final { scan-tree-dump "__builtin_copysignl" "forwprop1" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr71078-3.c b/gcc/testsuite/gcc.dg/tree-ssa/pr71078-3.c
new file mode 100644
index 0000000..8780b6a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr71078-3.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -ffast-math -fdump-tree-forwprop-details" } */
+
+#include <math.h>
+double f(float f)
+{
+ double t1 = fabs(f);
+ double t2 = f / t1;
+ return t2;
+}
+
+/* { dg-final { scan-tree-dump "__builtin_copysign" "forwprop1" } } */