diff mbox

[PR71078] x / abs(x) -> copysign (1.0, x)

Message ID CAAgBjMn73aCK=Dwy5QCqumZDbnZo80W4YumJWkJz=yH1n9=Kyg@mail.gmail.com
State New
Headers show

Commit Message

Prathamesh Kulkarni Aug. 1, 2016, 6:03 a.m. UTC
On 30 July 2016 at 02:57, Joseph Myers <joseph@codesourcery.com> wrote:
> On Tue, 26 Jul 2016, Richard Sandiford wrote:

>

>> (which are really just extended tree codes).  I suppose copysign is

>> a special case since we can always open code it, but in general we

>> shouldn't fall back to something that could generate a call.

>

> We can't always open code copysign (IBM long double, see PR 58797).

Hi,
Thanks for pointing that out.
The attached patch doesn't transform x/abs(x) -> copysign(1.0, x)
for long double.
OK for trunk ?

Thanks,
Prathamesh
>

> --

> Joseph S. Myers

> joseph@codesourcery.com
2016-08-01  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>

	* match.pd (x/abs(x) -> copysign(1.0, x)): Don't transform for
	long double.

testsuite/
	* gcc.dg/tree-ssa/pr71078-1.c: Remove f3.
	* gcc.dg/tree-ssa/pr71078-2.c: Likewise.
diff mbox

Patch

diff --git a/gcc/match.pd b/gcc/match.pd
index 2fd898a..3b6aaeb 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -198,17 +198,18 @@  DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 /* PR71078: x / abs(x) -> copysign (1.0, x) */
 (simplify
  (rdiv:C (convert? @0) (convert? (abs @0)))
+  /* We can't always transform to copysign for long double.
+     See PR58797.  */
   (if (SCALAR_FLOAT_TYPE_P (type)
+       && ! types_match (type, long_double_type_node)
        && ! 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))))))
-
+     (BUILT_IN_COPYSIGN { 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/gcc.dg/tree-ssa/pr71078-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr71078-1.c
index 6204c14..4606b2b 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/pr71078-1.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr71078-1.c
@@ -17,13 +17,5 @@  double f2(double x)
   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
index 96485af..eaff4cc 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/pr71078-2.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr71078-2.c
@@ -17,13 +17,5 @@  double f2(double 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" } } */