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
This commit is contained in:
Richard Guenther 2006-10-24 08:35:12 +00:00 committed by Richard Biener
parent 34fc5065e8
commit e1502f6e2d
4 changed files with 45 additions and 0 deletions

View File

@ -1,3 +1,10 @@
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.
2006-10-24 Richard Guenther <rguenther@suse.de>
PR tree-optimization/29567

View File

@ -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);
}

View File

@ -1,3 +1,7 @@
2006-10-24 Richard Guenther <rguenther@suse.de>
* gcc.dg/builtins-57.c: New testcase.
2006-10-24 Richard Guenther <rguenther@suse.de>
PR tree-optimization/29567

View File

@ -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" } } */