aboutsummaryrefslogtreecommitdiff
path: root/gcc/builtins.c
diff options
context:
space:
mode:
authorKaveh R. Ghazi <ghazi@caip.rutgers.edu>2006-11-26 14:35:54 +0000
committerKaveh Ghazi <ghazi@gcc.gnu.org>2006-11-26 14:35:54 +0000
commita8e3bad42b9636e20442b52a3924c914dc34dd82 (patch)
tree734a8de765f4b48ee96ae36a16bd7acbc013212e /gcc/builtins.c
parentd19c0f4fa6599e454c1c7b12917252f6f34852e7 (diff)
downloadgcc-a8e3bad42b9636e20442b52a3924c914dc34dd82.zip
gcc-a8e3bad42b9636e20442b52a3924c914dc34dd82.tar.gz
gcc-a8e3bad42b9636e20442b52a3924c914dc34dd82.tar.bz2
builtins.c (fold_builtin_fmin_fmax): Handle NaN arguments.
* builtins.c (fold_builtin_fmin_fmax): Handle NaN arguments. testsuite: * gcc.dg/torture/builtin-minmax-1.c: Test NaN in fmin/fmax. Don't ever inline the testcase. From-SVN: r119224
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r--gcc/builtins.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c
index 75b47fb..b2964de 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -8734,6 +8734,20 @@ fold_builtin_fmin_fmax (tree arglist, tree type, bool max)
if (res)
return res;
+ /* If either argument is NaN, return the other one. Avoid the
+ transformation if we get (and honor) a signalling NaN. Using
+ omit_one_operand() ensures we create a non-lvalue. */
+ if (TREE_CODE (arg0) == REAL_CST
+ && real_isnan (&TREE_REAL_CST (arg0))
+ && (! HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg0)))
+ || ! TREE_REAL_CST (arg0).signalling))
+ return omit_one_operand (type, arg1, arg0);
+ if (TREE_CODE (arg1) == REAL_CST
+ && real_isnan (&TREE_REAL_CST (arg1))
+ && (! HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg1)))
+ || ! TREE_REAL_CST (arg1).signalling))
+ return omit_one_operand (type, arg0, arg1);
+
/* Transform fmin/fmax(x,x) -> x. */
if (operand_equal_p (arg0, arg1, OEP_PURE_SAME))
return omit_one_operand (type, arg0, arg1);