aboutsummaryrefslogtreecommitdiff
path: root/gcc/builtins.c
diff options
context:
space:
mode:
authorRichard Guenther <rguenther@suse.de>2006-10-24 08:35:12 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2006-10-24 08:35:12 +0000
commite1502f6e2de6e37603adb0e415a5d9847bfaf990 (patch)
treee6f6ab1c1097626958f15e10fe8bd68d769702e3 /gcc/builtins.c
parent34fc5065e86dc46498da98d3dca4607464a1469b (diff)
downloadgcc-e1502f6e2de6e37603adb0e415a5d9847bfaf990.zip
gcc-e1502f6e2de6e37603adb0e415a5d9847bfaf990.tar.gz
gcc-e1502f6e2de6e37603adb0e415a5d9847bfaf990.tar.bz2
builtins.c (fold_builtin_floor): Fold floor (x) where x is nonnegative to trunc (x).
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 nonnegative to FIX_TRUNC_EXPR. * gcc.dg/builtins-57.c: New testcase. From-SVN: r117998
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r--gcc/builtins.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c
index c165e34..78fc11f 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -7355,6 +7355,12 @@ fold_builtin_floor (tree fndecl, tree arglist)
}
}
+ /* Fold floor (x) where x is nonnegative to trunc (x). */
+ if (tree_expr_nonnegative_p (arg))
+ return build_function_call_expr (mathfn_built_in (TREE_TYPE (arg),
+ BUILT_IN_TRUNC),
+ arglist);
+
return fold_trunc_transparent_mathfn (fndecl, arglist);
}
@@ -7473,6 +7479,18 @@ fold_builtin_int_roundingfn (tree fndecl, tree arglist)
}
}
+ switch (DECL_FUNCTION_CODE (fndecl))
+ {
+ CASE_FLT_FN (BUILT_IN_LFLOOR):
+ CASE_FLT_FN (BUILT_IN_LLFLOOR):
+ /* Fold lfloor (x) where x is nonnegative to FIX_TRUNC (x). */
+ if (tree_expr_nonnegative_p (arg))
+ return fold_build1 (FIX_TRUNC_EXPR, TREE_TYPE (TREE_TYPE (fndecl)),
+ arg);
+ break;
+ default:;
+ }
+
return fold_fixed_mathfn (fndecl, arglist);
}