From 72f52f3081af48ddddcb9e541c33fbbddfb4215d Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Mon, 22 Aug 2016 19:03:59 +0100 Subject: [PATCH] Support __builtin_isinf_sign for new floating-point types (PR middle-end/77269). 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 --- gcc/ChangeLog | 6 +++ gcc/builtins.c | 3 +- gcc/testsuite/ChangeLog | 12 +++++ .../gcc.dg/torture/builtin-isinf_sign-1.c | 4 +- gcc/testsuite/gcc.dg/torture/float128-tg-2.c | 9 ++++ gcc/testsuite/gcc.dg/torture/float128x-tg-2.c | 9 ++++ gcc/testsuite/gcc.dg/torture/float16-tg-2.c | 9 ++++ gcc/testsuite/gcc.dg/torture/float32-tg-2.c | 9 ++++ gcc/testsuite/gcc.dg/torture/float32x-tg-2.c | 9 ++++ gcc/testsuite/gcc.dg/torture/float64-tg-2.c | 9 ++++ gcc/testsuite/gcc.dg/torture/float64x-tg-2.c | 9 ++++ gcc/testsuite/gcc.dg/torture/floatn-tg-2.h | 54 +++++++++++++++++++ 12 files changed, 138 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/float128-tg-2.c create mode 100644 gcc/testsuite/gcc.dg/torture/float128x-tg-2.c create mode 100644 gcc/testsuite/gcc.dg/torture/float16-tg-2.c create mode 100644 gcc/testsuite/gcc.dg/torture/float32-tg-2.c create mode 100644 gcc/testsuite/gcc.dg/torture/float32x-tg-2.c create mode 100644 gcc/testsuite/gcc.dg/torture/float64-tg-2.c create mode 100644 gcc/testsuite/gcc.dg/torture/float64x-tg-2.c create mode 100644 gcc/testsuite/gcc.dg/torture/floatn-tg-2.h diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e62f3313d92..3cb421cfead 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2016-08-22 Joseph Myers + + 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 * print-tree.c (print_node) [VECTOR_CST]: Coalesce the output of diff --git a/gcc/builtins.c b/gcc/builtins.c index cf0cfc711e8..b981bcd281a 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 800a543e8a5..0a82b69d058 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,15 @@ +2016-08-22 Joseph Myers + + 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 * gcc.dg/torture/float128-builtin.c, diff --git a/gcc/testsuite/gcc.dg/torture/builtin-isinf_sign-1.c b/gcc/testsuite/gcc.dg/torture/builtin-isinf_sign-1.c index adfffcdb824..2579c6875ec 100644 --- a/gcc/testsuite/gcc.dg/torture/builtin-isinf_sign-1.c +++ b/gcc/testsuite/gcc.dg/torture/builtin-isinf_sign-1.c @@ -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 index 00000000000..c7a32b176e8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/float128-tg-2.c @@ -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 index 00000000000..e5c1b0c6989 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/float128x-tg-2.c @@ -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 index 00000000000..4236018b0e7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/float16-tg-2.c @@ -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 index 00000000000..80441d720e2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/float32-tg-2.c @@ -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 index 00000000000..897130a280f --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/float32x-tg-2.c @@ -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 index 00000000000..dddaa82122a --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/float64-tg-2.c @@ -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 index 00000000000..647d10406f0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/float64x-tg-2.c @@ -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 index 00000000000..1060da61292 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/floatn-tg-2.h @@ -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 + +#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); +} -- 2.30.2