Move ldexp, scalbn and scalbln folds to match.pd
authorRichard Sandiford <richard.sandiford@arm.com>
Tue, 27 Oct 2015 12:00:34 +0000 (12:00 +0000)
committerRichard Sandiford <rsandifo@gcc.gnu.org>
Tue, 27 Oct 2015 12:00:34 +0000 (12:00 +0000)
Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi.

gcc/
* builtins.c (fold_builtin_load_exponent): Rename to...
(fold_const_builtin_load_exponent): ...this and only handle
constant arguments.
(fold_builtin_2): Update accordingly.
* match.pd: Add rules previously handled by fold_builtin_load_exponent.

gcc/testsuite/
* gcc.dg/torture/builtin-ldexp-1.c: Skip at -O9,

From-SVN: r229434

gcc/ChangeLog
gcc/builtins.c
gcc/match.pd
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/builtin-ldexp-1.c

index 8711203c3d7de27addfe556909c842d54c167854..8880e994361fccdd6a401388d3dca5d2f81a1007 100644 (file)
@@ -1,3 +1,11 @@
+2015-10-27  Richard Sandiford  <richard.sandiford@arm.com>
+
+       * builtins.c (fold_builtin_load_exponent): Rename to...
+       (fold_const_builtin_load_exponent): ...this and only handle
+       constant arguments.
+       (fold_builtin_2): Update accordingly.
+       * match.pd: Add rules previously handled by fold_builtin_load_exponent.
+
 2015-10-27  Richard Sandiford  <richard.sandiford@arm.com>
 
        * builtins.c (fold_builtin_logb): Rename to...
index 260b66d7810b814dcc79930fd030e019f804f9cf..248c00997c551fd9a377ed56cb2f95d6b4c68210 100644 (file)
@@ -8060,20 +8060,11 @@ fold_builtin_frexp (location_t loc, tree arg0, tree arg1, tree rettype)
    check the mode of the TYPE parameter in certain cases.  */
 
 static tree
-fold_builtin_load_exponent (location_t loc, tree arg0, tree arg1,
-                           tree type, bool ldexp)
+fold_const_builtin_load_exponent (tree arg0, tree arg1,
+                                 tree type, bool ldexp)
 {
   if (validate_arg (arg0, REAL_TYPE) && validate_arg (arg1, INTEGER_TYPE))
     {
-      STRIP_NOPS (arg0);
-      STRIP_NOPS (arg1);
-
-      /* If arg0 is 0, Inf or NaN, or if arg1 is 0, then return arg0.  */
-      if (real_zerop (arg0) || integer_zerop (arg1)
-         || (TREE_CODE (arg0) == REAL_CST
-             && !real_isfinite (&TREE_REAL_CST (arg0))))
-       return omit_one_operand_loc (loc, type, arg0, arg1);
-
       /* If both arguments are constant, then try to evaluate it.  */
       if ((ldexp || REAL_MODE_FORMAT (TYPE_MODE (type))->b == 2)
          && TREE_CODE (arg0) == REAL_CST && !TREE_OVERFLOW (arg0)
@@ -9126,11 +9117,12 @@ fold_builtin_2 (location_t loc, tree fndecl, tree arg0, tree arg1)
     break;
 
     CASE_FLT_FN (BUILT_IN_LDEXP):
-      return fold_builtin_load_exponent (loc, arg0, arg1, type, /*ldexp=*/true);
+      return fold_const_builtin_load_exponent (arg0, arg1, type,
+                                              /*ldexp=*/true);
     CASE_FLT_FN (BUILT_IN_SCALBN):
     CASE_FLT_FN (BUILT_IN_SCALBLN):
-      return fold_builtin_load_exponent (loc, arg0, arg1,
-                                        type, /*ldexp=*/false);
+      return fold_const_builtin_load_exponent (arg0, arg1, type,
+                                              /*ldexp=*/false);
 
     CASE_FLT_FN (BUILT_IN_FREXP):
       return fold_builtin_frexp (loc, arg0, arg1, type);
index 73090066d3a67be371009c78ab8cb1543be32855..1d6dde19f47deb2a15ede5205b32b88e64ec5856 100644 (file)
@@ -105,6 +105,9 @@ DEFINE_MATH_FN (NEARBYINT)
 DEFINE_MATH_FN (SIGNBIT)
 DEFINE_MATH_FN (FMIN)
 DEFINE_MATH_FN (FMAX)
+DEFINE_MATH_FN (LDEXP)
+DEFINE_MATH_FN (SCALBN)
+DEFINE_MATH_FN (SCALBLN)
 
 DEFINE_INT_AND_FLOAT_ROUND_FN (FLOOR)
 DEFINE_INT_AND_FLOAT_ROUND_FN (CEIL)
@@ -2598,6 +2601,21 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (COPYSIGN @0 tree_expr_nonnegative_p@1)
  (abs @0))
 
+(for scale (LDEXP SCALBN SCALBLN)
+ /* ldexp(0, x) -> 0.  */
+ (simplify
+  (scale real_zerop@0 @1)
+  @0)
+ /* ldexp(x, 0) -> x.  */
+ (simplify
+  (scale @0 integer_zerop@1)
+  @0)
+ /* ldexp(x, y) -> x if x is +-Inf or NaN.  */
+ (simplify
+  (scale REAL_CST@0 @1)
+  (if (!real_isfinite (TREE_REAL_CST_PTR (@0)))
+   @0)))
+
 /* Canonicalization of sequences of math builtins.  These rules represent
    IL simplifications but are not necessarily optimizations.
 
index 355059c09e1e1b8bd27066c8ed3c6ba3a9beadbe..5a99607884f18e8e6ecc490b7618cd5f3acb8c59 100644 (file)
@@ -1,3 +1,7 @@
+2015-10-27  Richard Sandiford  <richard.sandiford@arm.com>
+
+       * gcc.dg/torture/builtin-ldexp-1.c: Skip at -O9,
+
 2015-10-27  Richard Sandiford  <richard.sandiford@arm.com>
 
        PR tree-optimization/68097
index 94560a8abb42c0ffdf650643d383f0cfc7991144..64122747570df48dc4e0d2493b2a978e8de5578a 100644 (file)
@@ -7,6 +7,7 @@
 
 /* { dg-do link } */
 /* { dg-options "-fno-finite-math-only" { target sh*-*-* } } */
+/* { dg-skip-if "" { *-*-* } { "-O0" } { "" } } */
 
 extern void link_error(int);