Commit 27d7d042 by Richard Guenther Committed by Richard Biener

re PR middle-end/28796 (__builtin_nan() and __builtin_unordered() inconsistent)

2006-10-24  Richard Guenther  <rguenther@suse.de>

	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
parent e1502f6e
2006-10-24 Richard Guenther <rguenther@suse.de>
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 <rguenther@suse.de>
* builtins.c (fold_builtin_floor): Fold floor (x) where
x is nonnegative to trunc (x).
(fold_builtin_int_roundingfn): Fold lfloor (x) where x is
......
......@@ -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));
}
......
2006-10-24 Richard Guenther <rguenther@suse.de>
PR middle-end/28796
* gcc.dg/pr28796-1.c: New testcase.
* gcc.dg/pr28796-2.c: Likewise.
2006-10-24 Richard Guenther <rguenther@suse.de>
* gcc.dg/builtins-57.c: New testcase.
2006-10-24 Richard Guenther <rguenther@suse.de>
/* { 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;
}
/* { 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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment