From 27d7d0422ce932e1f531fec5de9b81bced2f369b Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Tue, 24 Oct 2006 09:15:07 +0000 Subject: [PATCH] re PR middle-end/28796 (__builtin_nan() and __builtin_unordered() inconsistent) 2006-10-24 Richard Guenther PR middle-end/28796 * builtins.c (fold_builtin_classify): Use HONOR_INFINITIES and HONOR_NANS instead of MODE_HAS_INFINITIES and MODE_HAS_NANS for deciding optimizations in consistency with fold-const.c (fold_builtin_unordered_cmp): Likewise. * gcc.dg/pr28796-1.c: New testcase. * gcc.dg/pr28796-1.c: Likewise. From-SVN: r118001 --- gcc/ChangeLog | 8 ++++++++ gcc/builtins.c | 14 +++++++------- gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/gcc.dg/pr28796-1.c | 17 +++++++++++++++++ gcc/testsuite/gcc.dg/pr28796-2.c | 21 +++++++++++++++++++++ 5 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr28796-1.c create mode 100644 gcc/testsuite/gcc.dg/pr28796-2.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index ac9dcf7484e8..811fd4c16bc0 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2006-10-24 Richard Guenther + + PR middle-end/28796 + * builtins.c (fold_builtin_classify): Use HONOR_INFINITIES + and HONOR_NANS instead of MODE_HAS_INFINITIES and MODE_HAS_NANS + for deciding optimizations in consistency with fold-const.c + (fold_builtin_unordered_cmp): Likewise. + 2006-10-24 Richard Guenther * builtins.c (fold_builtin_floor): Fold floor (x) where diff --git a/gcc/builtins.c b/gcc/builtins.c index 78fc11f10653..f77f8b24a1a0 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -8776,7 +8776,7 @@ fold_builtin_classify (tree fndecl, tree arglist, int builtin_index) switch (builtin_index) { case BUILT_IN_ISINF: - if (!MODE_HAS_INFINITIES (TYPE_MODE (TREE_TYPE (arg)))) + if (!HONOR_INFINITIES (TYPE_MODE (TREE_TYPE (arg)))) return omit_one_operand (type, integer_zero_node, arg); if (TREE_CODE (arg) == REAL_CST) @@ -8792,8 +8792,8 @@ fold_builtin_classify (tree fndecl, tree arglist, int builtin_index) return NULL_TREE; case BUILT_IN_FINITE: - if (!MODE_HAS_NANS (TYPE_MODE (TREE_TYPE (arg))) - && !MODE_HAS_INFINITIES (TYPE_MODE (TREE_TYPE (arg)))) + if (!HONOR_NANS (TYPE_MODE (TREE_TYPE (arg))) + && !HONOR_INFINITIES (TYPE_MODE (TREE_TYPE (arg)))) return omit_one_operand (type, integer_one_node, arg); if (TREE_CODE (arg) == REAL_CST) @@ -8806,7 +8806,7 @@ fold_builtin_classify (tree fndecl, tree arglist, int builtin_index) return NULL_TREE; case BUILT_IN_ISNAN: - if (!MODE_HAS_NANS (TYPE_MODE (TREE_TYPE (arg)))) + if (!HONOR_NANS (TYPE_MODE (TREE_TYPE (arg)))) return omit_one_operand (type, integer_zero_node, arg); if (TREE_CODE (arg) == REAL_CST) @@ -8889,13 +8889,13 @@ fold_builtin_unordered_cmp (tree fndecl, tree arglist, if (unordered_code == UNORDERED_EXPR) { - if (!MODE_HAS_NANS (TYPE_MODE (TREE_TYPE (arg0)))) + if (!HONOR_NANS (TYPE_MODE (TREE_TYPE (arg0)))) return omit_two_operands (type, integer_zero_node, arg0, arg1); return fold_build2 (UNORDERED_EXPR, type, arg0, arg1); } - code = MODE_HAS_NANS (TYPE_MODE (TREE_TYPE (arg0))) ? unordered_code - : ordered_code; + code = HONOR_NANS (TYPE_MODE (TREE_TYPE (arg0))) ? unordered_code + : ordered_code; return fold_build1 (TRUTH_NOT_EXPR, type, fold_build2 (code, type, arg0, arg1)); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 98445d57ceec..e5533b0fd894 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2006-10-24 Richard Guenther + + PR middle-end/28796 + * gcc.dg/pr28796-1.c: New testcase. + * gcc.dg/pr28796-2.c: Likewise. + 2006-10-24 Richard Guenther * gcc.dg/builtins-57.c: New testcase. diff --git a/gcc/testsuite/gcc.dg/pr28796-1.c b/gcc/testsuite/gcc.dg/pr28796-1.c new file mode 100644 index 000000000000..a762becdafb3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr28796-1.c @@ -0,0 +1,17 @@ +/* { dg-do link } */ +/* { dg-options "-ffinite-math-only" } */ + +float f; + +int main() +{ + if (__builtin_isunordered (f, f) != 0) + link_error (); + if (__builtin_isnan (f) != 0) + link_error (); + if (__builtin_finite (f) != 1) + link_error (); + if (f != f) + link_error (); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/pr28796-2.c b/gcc/testsuite/gcc.dg/pr28796-2.c new file mode 100644 index 000000000000..8847d78df3b9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr28796-2.c @@ -0,0 +1,21 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -funsafe-math-optimizations" } */ + +extern void abort (void); + +void foo(float f) +{ + if (__builtin_isunordered (f, f) != 1) + abort (); + if (__builtin_isnan (f) != 1) + abort (); + if (__builtin_finite (f) != 0) + abort (); +} + +int main() +{ + float f = __builtin_nanf(""); + foo(f); + return 0; +}