summaryrefslogtreecommitdiff
path: root/gcc/convert.c
diff options
context:
space:
mode:
authorUros Bizjak <ubizjak@gmail.com>2009-06-18 13:35:38 +0200
committerUros Bizjak <uros@gcc.gnu.org>2009-06-18 13:35:38 +0200
commit2c2f70e1f266b6582398248096feccaceb2dd70c (patch)
tree904a11ef4efd2cdd11a40d4bba5529efb85e3085 /gcc/convert.c
parentf99098233b944542b3f78de9da395f220fe9d0cf (diff)
downloadgcc-2c2f70e1f266b6582398248096feccaceb2dd70c.tar.gz
convert.c (convert_to_integer): Convert (int)logb() into ilogb().
* convert.c (convert_to_integer): Convert (int)logb() into ilogb(). testsuite/ChangeLog: * gcc.dg/builtins-65.c: New test. From-SVN: r148653
Diffstat (limited to 'gcc/convert.c')
-rw-r--r--gcc/convert.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/gcc/convert.c b/gcc/convert.c
index b6a9d3dc531..8245e1647fb 100644
--- a/gcc/convert.c
+++ b/gcc/convert.c
@@ -482,6 +482,37 @@ convert_to_integer (tree type, tree expr)
}
}
+ /* Convert (int)logb(d) -> ilogb(d). */
+ if (optimize
+ && flag_unsafe_math_optimizations
+ && !flag_trapping_math && !flag_errno_math && flag_finite_math_only
+ && integer_type_node
+ && (outprec > TYPE_PRECISION (integer_type_node)
+ || (outprec == TYPE_PRECISION (integer_type_node)
+ && !TYPE_UNSIGNED (type))))
+ {
+ tree s_expr = strip_float_extensions (expr);
+ tree s_intype = TREE_TYPE (s_expr);
+ const enum built_in_function fcode = builtin_mathfn_code (s_expr);
+ tree fn = 0;
+
+ switch (fcode)
+ {
+ CASE_FLT_FN (BUILT_IN_LOGB):
+ fn = mathfn_built_in (s_intype, BUILT_IN_ILOGB);
+ break;
+
+ default:
+ break;
+ }
+
+ if (fn)
+ {
+ tree newexpr = build_call_expr (fn, 1, CALL_EXPR_ARG (s_expr, 0));
+ return convert_to_integer (type, newexpr);
+ }
+ }
+
switch (TREE_CODE (intype))
{
case POINTER_TYPE: