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
This commit is contained in:
Joseph Myers 2016-08-22 19:03:59 +01:00 committed by Joseph Myers
parent 27abac2648
commit 72f52f3081
12 changed files with 138 additions and 4 deletions

View 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

View 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;

View 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,

View 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__

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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);
}