+ enum built_in_function fcode = builtin_mathfn_code (expr);
+ tree itype = TREE_TYPE (expr);
+
+ /* Disable until we figure out how to decide whether the functions are
+ present in runtime. */
+ /* Convert (float)sqrt((double)x) where x is float into sqrtf(x) */
+ if (optimize
+ && (fcode == BUILT_IN_SQRT
+ || fcode == BUILT_IN_SQRTL
+ || fcode == BUILT_IN_SIN
+ || fcode == BUILT_IN_SINL
+ || fcode == BUILT_IN_COS
+ || fcode == BUILT_IN_COSL
+ || fcode == BUILT_IN_EXP
+ || fcode == BUILT_IN_EXPL
+ || fcode == BUILT_IN_LOG
+ || fcode == BUILT_IN_LOGL)
+ && (TYPE_MODE (type) == TYPE_MODE (double_type_node)
+ || TYPE_MODE (type) == TYPE_MODE (float_type_node)))
+ {
+ tree arg0 = strip_float_extensions (TREE_VALUE (TREE_OPERAND (expr, 1)));
+ tree newtype = type;
+
+ /* We have (outertype)sqrt((innertype)x). Choose the wider mode from
+ the both as the safe type for operation. */
+ if (TYPE_PRECISION (TREE_TYPE (arg0)) > TYPE_PRECISION (type))
+ newtype = TREE_TYPE (arg0);
+
+ /* Be careful about integer to fp conversions.
+ These may overflow still. */
+ if (FLOAT_TYPE_P (TREE_TYPE (arg0))
+ && TYPE_PRECISION (newtype) < TYPE_PRECISION (itype)
+ && (TYPE_MODE (newtype) == TYPE_MODE (double_type_node)
+ || TYPE_MODE (newtype) == TYPE_MODE (float_type_node)))
+ {
+ tree arglist;
+ tree fn = mathfn_built_in (newtype, fcode);
+
+ if (fn)
+ {
+ arglist = build_tree_list (NULL_TREE, fold (convert_to_real (newtype, arg0)));
+ expr = build_function_call_expr (fn, arglist);
+ if (newtype == type)
+ return expr;
+ }
+ }
+ }
+ if (optimize
+ && (((fcode == BUILT_IN_FLOORL
+ || fcode == BUILT_IN_CEILL
+ || fcode == BUILT_IN_ROUND
+ || fcode == BUILT_IN_TRUNC
+ || fcode == BUILT_IN_NEARBYINT)
+ && (TYPE_MODE (type) == TYPE_MODE (double_type_node)
+ || TYPE_MODE (type) == TYPE_MODE (float_type_node)))
+ || ((fcode == BUILT_IN_FLOOR
+ || fcode == BUILT_IN_CEIL
+ || fcode == BUILT_IN_ROUND
+ || fcode == BUILT_IN_TRUNC
+ || fcode == BUILT_IN_NEARBYINT)
+ && (TYPE_MODE (type) == TYPE_MODE (float_type_node)))))
+ {
+ tree fn = mathfn_built_in (type, fcode);
+
+ if (fn)
+ {
+ tree arg0 = strip_float_extensions (TREE_VALUE (TREE_OPERAND (expr,
+ 1)));
+ tree arglist = build_tree_list (NULL_TREE,
+ fold (convert_to_real (type, arg0)));
+
+ return build_function_call_expr (fn, arglist);
+ }
+ }
+
+ /* Propagate the cast into the operation. */
+ if (itype != type && FLOAT_TYPE_P (type))
+ switch (TREE_CODE (expr))
+ {
+ /* Convert (float)-x into -(float)x. This is always safe. */
+ case ABS_EXPR:
+ case NEGATE_EXPR:
+ if (TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (expr)))
+ return build1 (TREE_CODE (expr), type,
+ fold (convert_to_real (type,
+ TREE_OPERAND (expr, 0))));
+ break;
+ /* Convert (outertype)((innertype0)a+(innertype1)b)
+ into ((newtype)a+(newtype)b) where newtype
+ is the widest mode from all of these. */
+ case PLUS_EXPR:
+ case MINUS_EXPR:
+ case MULT_EXPR:
+ case RDIV_EXPR:
+ {
+ tree arg0 = strip_float_extensions (TREE_OPERAND (expr, 0));
+ tree arg1 = strip_float_extensions (TREE_OPERAND (expr, 1));
+
+ if (FLOAT_TYPE_P (TREE_TYPE (arg0))
+ && FLOAT_TYPE_P (TREE_TYPE (arg1)))
+ {
+ tree newtype = type;
+ if (TYPE_PRECISION (TREE_TYPE (arg0)) > TYPE_PRECISION (newtype))
+ newtype = TREE_TYPE (arg0);
+ if (TYPE_PRECISION (TREE_TYPE (arg1)) > TYPE_PRECISION (newtype))
+ newtype = TREE_TYPE (arg1);
+ if (TYPE_PRECISION (newtype) < TYPE_PRECISION (itype))
+ {
+ expr = build (TREE_CODE (expr), newtype,
+ fold (convert_to_real (newtype, arg0)),
+ fold (convert_to_real (newtype, arg1)));
+ if (newtype == type)
+ return expr;
+ }
+ }
+ }
+ break;
+ default:
+ break;
+ }
+