From e1502f6e2de6e37603adb0e415a5d9847bfaf990 Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Tue, 24 Oct 2006 08:35:12 +0000 Subject: builtins.c (fold_builtin_floor): Fold floor (x) where x is nonnegative to trunc (x). 2006-10-24 Richard Guenther * 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 --- gcc/ChangeLog | 7 +++++++ gcc/builtins.c | 18 ++++++++++++++++++ gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/builtins-57.c | 16 ++++++++++++++++ 4 files changed, 45 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/builtins-57.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 1505a08..ac9dcf7 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,12 @@ 2006-10-24 Richard Guenther + * 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. + +2006-10-24 Richard Guenther + PR tree-optimization/29567 * tree-vrp.c (register_edge_assert_for_1): Fix wrong logic for TRUTH_NOT_EXPR. Clarify comments. 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); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9136286..98445d5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,9 @@ 2006-10-24 Richard Guenther + * gcc.dg/builtins-57.c: New testcase. + +2006-10-24 Richard Guenther + PR tree-optimization/29567 * gfortran.fortran-torture/compile/vrp_1.f90: New testcase. diff --git a/gcc/testsuite/gcc.dg/builtins-57.c b/gcc/testsuite/gcc.dg/builtins-57.c new file mode 100644 index 0000000..87fbd44 --- /dev/null +++ b/gcc/testsuite/gcc.dg/builtins-57.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-gimple" } */ + +double foo (double x) +{ + return __builtin_floor (__builtin_fabs (x)); +} + +long bar (double x) +{ + return __builtin_lfloor (__builtin_fabs (x)); +} + +/* { dg-final { scan-tree-dump-not "lfloor" "gimple" } } */ +/* { dg-final { scan-tree-dump "trunc" "gimple" } } */ +/* { dg-final { cleanup-tree-dump "gimple" } } */ -- cgit v1.1