* 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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@117998
138bc75d-0d04-0410-961f-
82ee72b054a4
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
* tree-vrp.c (register_edge_assert_for_1): Fix wrong logic
for TRUTH_NOT_EXPR. Clarify comments.
}
}
+ /* 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);
}
}
}
+ 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);
}
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
* gfortran.fortran-torture/compile/vrp_1.f90: New testcase.
--- /dev/null
+/* { 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" } } */