Support __builtin_isinf_sign for new floating-point types (PR middle-end/77269).
authorJoseph Myers <joseph@codesourcery.com>
Mon, 22 Aug 2016 18:03:59 +0000 (19:03 +0100)
committerJoseph Myers <jsm28@gcc.gnu.org>
Mon, 22 Aug 2016 18:03:59 +0000 (19:03 +0100)
The __builtin_isinf_sign folding uses a type-specific signbit built-in
function, meaning it only works for the types float, double and long
double, not for types such as _FloatN, _FloatNx, __float128.  Since
the signbit built-in function is now type-generic, that can be used
unconditionally, much as the code uses the type-generic isinf built-in
function unconditionally, and this patch makes it do so, thereby
enabling __builtin_isinf_sign (which glibc uses to expand the isinf
macro since that macro in glibc traditionally provided the stronger
guarantees about the return value given by __builtin_isinf_sign) to
work for all floating-point types.

The test gcc.dg/torture/builtin-isinf_sign-1.c needs updating because
it tests that comparisons of calls to __builtin_isinf_sign to
conditional expressions involving __builtin_isinf and
__builtin_signbit* get optimized away, and with a change of what
particular built-in function for signbit is used, GCC doesn't notice
the expressions with type-generic and non-type-generic built-in
functions are equivalent at -O0 or -O1 (it does optimize away the
original test at -O2).

Bootstrapped with no regressions on x86_64-pc-linux-gnu.

PR middle-end/77269
gcc:
* builtins.c (fold_builtin_classify): Use builtin_decl_explicit
(BUILT_IN_SIGNBIT) to expand __builtin_isinf_sign.

gcc/testsuite:
* gcc.dg/torture/builtin-isinf_sign-1.c: Use __builtin_signbit not
__builtin_signbitf and __builtin_signbitl in expected generic
expansion.
* gcc.dg/torture/float128-tg-2.c, gcc.dg/torture/float128x-tg-2.c,
gcc.dg/torture/float16-tg-2.c, gcc.dg/torture/float32-tg-2.c,
gcc.dg/torture/float32x-tg-2.c, gcc.dg/torture/float64-tg-2.c,
gcc.dg/torture/float64x-tg-2.c, gcc.dg/torture/floatn-tg-2.h: New
tests.

From-SVN: r239665

12 files changed:
gcc/ChangeLog
gcc/builtins.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/builtin-isinf_sign-1.c
gcc/testsuite/gcc.dg/torture/float128-tg-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/float128x-tg-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/float16-tg-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/float32-tg-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/float32x-tg-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/float64-tg-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/float64x-tg-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/floatn-tg-2.h [new file with mode: 0644]

index e62f3313d927294c1e1a2790f352ff2dbd84c468..3cb421cfead5dc2dcbda2e146646b900938a1594 100644 (file)
@@ -1,3 +1,9 @@
+2016-08-22  Joseph Myers  <joseph@codesourcery.com>
+
+       PR middle-end/77269
+       * builtins.c (fold_builtin_classify): Use builtin_decl_explicit
+       (BUILT_IN_SIGNBIT) to expand __builtin_isinf_sign.
+
 2016-08-22  Patrick Palka  <ppalka@gcc.gnu.org>
 
        * print-tree.c (print_node) [VECTOR_CST]: Coalesce the output of
index cf0cfc711e8f3d0aef6afb8a46df709e0979adf6..b981bcd281af29cdbb1d6bcc1e9f93b769708897 100644 (file)
@@ -7881,8 +7881,7 @@ fold_builtin_classify (location_t loc, tree fndecl, tree arg, int builtin_index)
        /* In a boolean context, GCC will fold the inner COND_EXPR to
           1.  So e.g. "if (isinf_sign(x))" would be folded to just
           "if (isinf(x) ? 1 : 0)" which becomes "if (isinf(x))". */
-       tree signbit_fn = mathfn_built_in_1
-         (TREE_TYPE (arg), CFN_BUILT_IN_SIGNBIT, 0);
+       tree signbit_fn = builtin_decl_explicit (BUILT_IN_SIGNBIT);
        tree isinf_fn = builtin_decl_explicit (BUILT_IN_ISINF);
        tree tmp = NULL_TREE;
 
index 800a543e8a597b8634ab6d0da7fa5bb65b18ab79..0a82b69d0586faa5e7332844fe10c6ccaeedfe12 100644 (file)
@@ -1,3 +1,15 @@
+2016-08-22  Joseph Myers  <joseph@codesourcery.com>
+
+       PR middle-end/77269
+       * gcc.dg/torture/builtin-isinf_sign-1.c: Use __builtin_signbit not
+       __builtin_signbitf and __builtin_signbitl in expected generic
+       expansion.
+       * gcc.dg/torture/float128-tg-2.c, gcc.dg/torture/float128x-tg-2.c,
+       gcc.dg/torture/float16-tg-2.c, gcc.dg/torture/float32-tg-2.c,
+       gcc.dg/torture/float32x-tg-2.c, gcc.dg/torture/float64-tg-2.c,
+       gcc.dg/torture/float64x-tg-2.c, gcc.dg/torture/floatn-tg-2.h: New
+       tests.
+
 2016-08-22  Joseph Myers  <joseph@codesourcery.com>
 
        * gcc.dg/torture/float128-builtin.c,
index adfffcdb824ef1b4cb0a37a71017adc1fd441de8..2579c6875ec20b12a706ebe44dd41cd98a678b23 100644 (file)
@@ -15,13 +15,13 @@ foo (float f, double d, long double ld)
   /* Test the generic expansion of isinf_sign.  */
 
   if (__builtin_isinf_sign(f)
-      != (__builtin_isinf(f) ? (__builtin_signbitf(f) ? -1 : 1) : 0))
+      != (__builtin_isinf(f) ? (__builtin_signbit(f) ? -1 : 1) : 0))
     link_error (__LINE__);
   if (__builtin_isinf_sign(d)
       != (__builtin_isinf(d) ? (__builtin_signbit(d) ? -1 : 1) : 0))
     link_error (__LINE__);
   if (__builtin_isinf_sign(ld)
-      != (__builtin_isinf(ld) ? (__builtin_signbitl(ld) ? -1 : 1) : 0))
+      != (__builtin_isinf(ld) ? (__builtin_signbit(ld) ? -1 : 1) : 0))
     link_error (__LINE__);
 
 #ifdef __OPTIMIZE__
diff --git a/gcc/testsuite/gcc.dg/torture/float128-tg-2.c b/gcc/testsuite/gcc.dg/torture/float128-tg-2.c
new file mode 100644 (file)
index 0000000..c7a32b1
--- /dev/null
@@ -0,0 +1,9 @@
+/* Test _Float128 type-generic built-in functions: __builtin_isinf_sign.  */
+/* { dg-do run } */
+/* { dg-options "" } */
+/* { dg-add-options float128 } */
+/* { dg-require-effective-target float128_runtime } */
+
+#define WIDTH 128
+#define EXT 0
+#include "floatn-tg-2.h"
diff --git a/gcc/testsuite/gcc.dg/torture/float128x-tg-2.c b/gcc/testsuite/gcc.dg/torture/float128x-tg-2.c
new file mode 100644 (file)
index 0000000..e5c1b0c
--- /dev/null
@@ -0,0 +1,9 @@
+/* Test _Float128x type-generic built-in functions: __builtin_isinf_sign.  */
+/* { dg-do run } */
+/* { dg-options "" } */
+/* { dg-add-options float128x } */
+/* { dg-require-effective-target float128x_runtime } */
+
+#define WIDTH 128
+#define EXT 1
+#include "floatn-tg-2.h"
diff --git a/gcc/testsuite/gcc.dg/torture/float16-tg-2.c b/gcc/testsuite/gcc.dg/torture/float16-tg-2.c
new file mode 100644 (file)
index 0000000..4236018
--- /dev/null
@@ -0,0 +1,9 @@
+/* Test _Float16 type-generic built-in functions: __builtin_isinf_sign.  */
+/* { dg-do run } */
+/* { dg-options "" } */
+/* { dg-add-options float16 } */
+/* { dg-require-effective-target float16_runtime } */
+
+#define WIDTH 16
+#define EXT 0
+#include "floatn-tg-2.h"
diff --git a/gcc/testsuite/gcc.dg/torture/float32-tg-2.c b/gcc/testsuite/gcc.dg/torture/float32-tg-2.c
new file mode 100644 (file)
index 0000000..80441d7
--- /dev/null
@@ -0,0 +1,9 @@
+/* Test _Float32 type-generic built-in functions: __builtin_isinf_sign.  */
+/* { dg-do run } */
+/* { dg-options "" } */
+/* { dg-add-options float32 } */
+/* { dg-require-effective-target float32_runtime } */
+
+#define WIDTH 32
+#define EXT 0
+#include "floatn-tg-2.h"
diff --git a/gcc/testsuite/gcc.dg/torture/float32x-tg-2.c b/gcc/testsuite/gcc.dg/torture/float32x-tg-2.c
new file mode 100644 (file)
index 0000000..897130a
--- /dev/null
@@ -0,0 +1,9 @@
+/* Test _Float32x type-generic built-in functions: __builtin_isinf_sign.  */
+/* { dg-do run } */
+/* { dg-options "" } */
+/* { dg-add-options float32x } */
+/* { dg-require-effective-target float32x_runtime } */
+
+#define WIDTH 32
+#define EXT 1
+#include "floatn-tg-2.h"
diff --git a/gcc/testsuite/gcc.dg/torture/float64-tg-2.c b/gcc/testsuite/gcc.dg/torture/float64-tg-2.c
new file mode 100644 (file)
index 0000000..dddaa82
--- /dev/null
@@ -0,0 +1,9 @@
+/* Test _Float64 type-generic built-in functions: __builtin_isinf_sign.  */
+/* { dg-do run } */
+/* { dg-options "" } */
+/* { dg-add-options float64 } */
+/* { dg-require-effective-target float64_runtime } */
+
+#define WIDTH 64
+#define EXT 0
+#include "floatn-tg-2.h"
diff --git a/gcc/testsuite/gcc.dg/torture/float64x-tg-2.c b/gcc/testsuite/gcc.dg/torture/float64x-tg-2.c
new file mode 100644 (file)
index 0000000..647d104
--- /dev/null
@@ -0,0 +1,9 @@
+/* Test _Float64x type-generic built-in functions: __builtin_isinf_sign.  */
+/* { dg-do run } */
+/* { dg-options "" } */
+/* { dg-add-options float64x } */
+/* { dg-require-effective-target float64x_runtime } */
+
+#define WIDTH 64
+#define EXT 1
+#include "floatn-tg-2.h"
diff --git a/gcc/testsuite/gcc.dg/torture/floatn-tg-2.h b/gcc/testsuite/gcc.dg/torture/floatn-tg-2.h
new file mode 100644 (file)
index 0000000..1060da6
--- /dev/null
@@ -0,0 +1,54 @@
+/* Tests for _FloatN / _FloatNx types: compile and execution tests for
+   type-generic built-in functions: __builtin_isinf_sign.  Before
+   including this file, define WIDTH as the value N; define EXT to 1
+   for _FloatNx and 0 for _FloatN.  */
+
+#define __STDC_WANT_IEC_60559_TYPES_EXT__
+#include <float.h>
+
+#define CONCATX(X, Y) X ## Y
+#define CONCAT(X, Y) CONCATX (X, Y)
+#define CONCAT3(X, Y, Z) CONCAT (CONCAT (X, Y), Z)
+#define CONCAT4(W, X, Y, Z) CONCAT (CONCAT (CONCAT (W, X), Y), Z)
+
+#if EXT
+# define TYPE CONCAT3 (_Float, WIDTH, x)
+# define CST(C) CONCAT4 (C, f, WIDTH, x)
+# define MAX CONCAT3 (FLT, WIDTH, X_MAX)
+#else
+# define TYPE CONCAT (_Float, WIDTH)
+# define CST(C) CONCAT3 (C, f, WIDTH)
+# define MAX CONCAT3 (FLT, WIDTH, _MAX)
+#endif
+
+extern void exit (int);
+extern void abort (void);
+
+volatile TYPE inf = __builtin_inf (), nanval = __builtin_nan ("");
+volatile TYPE neginf = -__builtin_inf (), negnanval = -__builtin_nan ("");
+volatile TYPE zero = CST (0.0), negzero = -CST (0.0), one = CST (1.0);
+volatile TYPE max = MAX, negmax = -MAX;
+
+int
+main (void)
+{
+  if (__builtin_isinf_sign (inf) != 1)
+    abort ();
+  if (__builtin_isinf_sign (neginf) != -1)
+    abort ();
+  if (__builtin_isinf_sign (nanval) != 0)
+    abort ();
+  if (__builtin_isinf_sign (negnanval) != 0)
+    abort ();
+  if (__builtin_isinf_sign (zero) != 0)
+    abort ();
+  if (__builtin_isinf_sign (negzero) != 0)
+    abort ();
+  if (__builtin_isinf_sign (one) != 0)
+    abort ();
+  if (__builtin_isinf_sign (max) != 0)
+    abort ();
+  if (__builtin_isinf_sign (negmax) != 0)
+    abort ();
+  exit (0);
+}