+2011-08-12 Uros Bizjak <ubizjak@gmail.com>
+
+ * builtins.def (BUILT_IN_ICEIL{,F,L}, BUILT_IN_IFLOOR{,F,L}
+ BUILT_IN_IRINT{,F,L}, BUILT_IN_IROUND{,F,L}: New builtin definitions.
+ * convert.c (convert_to_integer): Convert to BUILT_IN_ICEIL,
+ BUILT_IN_IFLOOR, BUILT_IN_IRINT or BUILT_INT_IROUND when converting
+ to integer_type_node.
+ * fold-const.c (tree_call_nonnegative_warnv_p): Handle BUILT_IN_ICEIL,
+ BUILT_IN_IFLOOR, BUILT_IN_IRINT and BUILT_INT_IROUND.
+ * builtins.c (expand_builtin_in): Ditto.
+ (mathfn_built_in_1): Ditto.
+ (expand_builtin_int_roundingfn): Handle BUILT_IN_ICEIL and
+ BUILT_IN_IFLOOR.
+ (expand_builtin_int_roundingfn_2): Handle BUILT_IN_IRINT and
+ BUILT_IN_IROUND.
+ (fold_fixed_mathfn): Canonicalize BUILT_IN_ICEIL, BUILTIN_IN_IFLOOR
+ BUILT_IN_IRINT and BUILT_IN_IROUND to BUILT_IN_LCEIL,
+ BUILTIN_IN_LFLOOR, BUILT_IN_LRINT and BUILT_IN_LROUND on ILP32 targets.
+
2011-08-12 Richard Guenther <rguenther@suse.de>
* tree-vrp.c (extract_range_from_unary_expr_1): Implement
CASE_MATHFN (BUILT_IN_HUGE_VAL)
CASE_MATHFN (BUILT_IN_HYPOT)
CASE_MATHFN (BUILT_IN_ILOGB)
+ CASE_MATHFN (BUILT_IN_ICEIL)
+ CASE_MATHFN (BUILT_IN_IFLOOR)
CASE_MATHFN (BUILT_IN_INF)
+ CASE_MATHFN (BUILT_IN_IRINT)
+ CASE_MATHFN (BUILT_IN_IROUND)
CASE_MATHFN (BUILT_IN_ISINF)
CASE_MATHFN (BUILT_IN_J0)
CASE_MATHFN (BUILT_IN_J1)
switch (DECL_FUNCTION_CODE (fndecl))
{
+ CASE_FLT_FN (BUILT_IN_ICEIL):
CASE_FLT_FN (BUILT_IN_LCEIL):
CASE_FLT_FN (BUILT_IN_LLCEIL):
builtin_optab = lceil_optab;
fallback_fn = BUILT_IN_CEIL;
break;
+ CASE_FLT_FN (BUILT_IN_IFLOOR):
CASE_FLT_FN (BUILT_IN_LFLOOR):
CASE_FLT_FN (BUILT_IN_LLFLOOR):
builtin_optab = lfloor_optab;
switch (DECL_FUNCTION_CODE (fndecl))
{
+ case BUILT_IN_ICEIL:
case BUILT_IN_LCEIL:
case BUILT_IN_LLCEIL:
name = "ceil";
break;
+ case BUILT_IN_ICEILF:
case BUILT_IN_LCEILF:
case BUILT_IN_LLCEILF:
name = "ceilf";
break;
+ case BUILT_IN_ICEILL:
case BUILT_IN_LCEILL:
case BUILT_IN_LLCEILL:
name = "ceill";
break;
+ case BUILT_IN_IFLOOR:
case BUILT_IN_LFLOOR:
case BUILT_IN_LLFLOOR:
name = "floor";
break;
+ case BUILT_IN_IFLOORF:
case BUILT_IN_LFLOORF:
case BUILT_IN_LLFLOORF:
name = "floorf";
break;
+ case BUILT_IN_IFLOORL:
case BUILT_IN_LFLOORL:
case BUILT_IN_LLFLOORL:
name = "floorl";
switch (DECL_FUNCTION_CODE (fndecl))
{
+ CASE_FLT_FN (BUILT_IN_IRINT):
CASE_FLT_FN (BUILT_IN_LRINT):
CASE_FLT_FN (BUILT_IN_LLRINT):
builtin_optab = lrint_optab; break;
+
+ CASE_FLT_FN (BUILT_IN_IROUND):
CASE_FLT_FN (BUILT_IN_LROUND):
CASE_FLT_FN (BUILT_IN_LLROUND):
builtin_optab = lround_optab; break;
+
default:
gcc_unreachable ();
}
return target;
break;
+ CASE_FLT_FN (BUILT_IN_ICEIL):
CASE_FLT_FN (BUILT_IN_LCEIL):
CASE_FLT_FN (BUILT_IN_LLCEIL):
CASE_FLT_FN (BUILT_IN_LFLOOR):
+ CASE_FLT_FN (BUILT_IN_IFLOOR):
CASE_FLT_FN (BUILT_IN_LLFLOOR):
target = expand_builtin_int_roundingfn (exp, target);
if (target)
return target;
break;
+ CASE_FLT_FN (BUILT_IN_IRINT):
CASE_FLT_FN (BUILT_IN_LRINT):
CASE_FLT_FN (BUILT_IN_LLRINT):
+ CASE_FLT_FN (BUILT_IN_IROUND):
CASE_FLT_FN (BUILT_IN_LROUND):
CASE_FLT_FN (BUILT_IN_LLROUND):
target = expand_builtin_int_roundingfn_2 (exp, target);
fold_convert_loc (loc, newtype, arg0));
}
+ /* Canonicalize iround (x) to lround (x) on ILP32 targets where
+ sizeof (int) == sizeof (long). */
+ if (TYPE_PRECISION (integer_type_node)
+ == TYPE_PRECISION (long_integer_type_node))
+ {
+ tree newfn = NULL_TREE;
+ switch (fcode)
+ {
+ CASE_FLT_FN (BUILT_IN_ICEIL):
+ newfn = mathfn_built_in (TREE_TYPE (arg), BUILT_IN_LCEIL);
+ break;
+
+ CASE_FLT_FN (BUILT_IN_IFLOOR):
+ newfn = mathfn_built_in (TREE_TYPE (arg), BUILT_IN_LFLOOR);
+ break;
+
+ CASE_FLT_FN (BUILT_IN_IROUND):
+ newfn = mathfn_built_in (TREE_TYPE (arg), BUILT_IN_LROUND);
+ break;
+
+ CASE_FLT_FN (BUILT_IN_IRINT):
+ newfn = mathfn_built_in (TREE_TYPE (arg), BUILT_IN_LRINT);
+ break;
+
+ default:
+ break;
+ }
+
+ if (newfn)
+ {
+ tree newcall = build_call_expr_loc (loc, newfn, 1, arg);
+ return fold_convert_loc (loc,
+ TREE_TYPE (TREE_TYPE (fndecl)), newcall);
+ }
+ }
+
/* Canonicalize llround (x) to lround (x) on LP64 targets where
sizeof (long long) == sizeof (long). */
if (TYPE_PRECISION (long_long_integer_type_node)
switch (DECL_FUNCTION_CODE (fndecl))
{
+ CASE_FLT_FN (BUILT_IN_IFLOOR):
CASE_FLT_FN (BUILT_IN_LFLOOR):
CASE_FLT_FN (BUILT_IN_LLFLOOR):
real_floor (&r, TYPE_MODE (ftype), &x);
break;
+ CASE_FLT_FN (BUILT_IN_ICEIL):
CASE_FLT_FN (BUILT_IN_LCEIL):
CASE_FLT_FN (BUILT_IN_LLCEIL):
real_ceil (&r, TYPE_MODE (ftype), &x);
break;
+ CASE_FLT_FN (BUILT_IN_IROUND):
CASE_FLT_FN (BUILT_IN_LROUND):
CASE_FLT_FN (BUILT_IN_LLROUND):
real_round (&r, TYPE_MODE (ftype), &x);
CASE_FLT_FN (BUILT_IN_RINT):
return fold_trunc_transparent_mathfn (loc, fndecl, arg0);
+ CASE_FLT_FN (BUILT_IN_ICEIL):
CASE_FLT_FN (BUILT_IN_LCEIL):
CASE_FLT_FN (BUILT_IN_LLCEIL):
CASE_FLT_FN (BUILT_IN_LFLOOR):
+ CASE_FLT_FN (BUILT_IN_IFLOOR):
CASE_FLT_FN (BUILT_IN_LLFLOOR):
+ CASE_FLT_FN (BUILT_IN_IROUND):
CASE_FLT_FN (BUILT_IN_LROUND):
CASE_FLT_FN (BUILT_IN_LLROUND):
return fold_builtin_int_roundingfn (loc, fndecl, arg0);
+ CASE_FLT_FN (BUILT_IN_IRINT):
CASE_FLT_FN (BUILT_IN_LRINT):
CASE_FLT_FN (BUILT_IN_LLRINT):
return fold_fixed_mathfn (loc, fndecl, arg0);
DEF_C99_BUILTIN (BUILT_IN_HYPOT, "hypot", BT_FN_DOUBLE_DOUBLE_DOUBLE, ATTR_MATHFN_FPROUNDING_ERRNO)
DEF_C99_BUILTIN (BUILT_IN_HYPOTF, "hypotf", BT_FN_FLOAT_FLOAT_FLOAT, ATTR_MATHFN_FPROUNDING_ERRNO)
DEF_C99_BUILTIN (BUILT_IN_HYPOTL, "hypotl", BT_FN_LONGDOUBLE_LONGDOUBLE_LONGDOUBLE, ATTR_MATHFN_FPROUNDING_ERRNO)
+DEF_GCC_BUILTIN (BUILT_IN_ICEIL, "iceil", BT_FN_INT_DOUBLE, ATTR_CONST_NOTHROW_LEAF_LIST)
+DEF_GCC_BUILTIN (BUILT_IN_ICEILF, "iceilf", BT_FN_INT_FLOAT, ATTR_CONST_NOTHROW_LEAF_LIST)
+DEF_GCC_BUILTIN (BUILT_IN_ICEILL, "iceill", BT_FN_INT_LONGDOUBLE, ATTR_CONST_NOTHROW_LEAF_LIST)
+DEF_GCC_BUILTIN (BUILT_IN_IFLOOR, "ifloor", BT_FN_INT_DOUBLE, ATTR_CONST_NOTHROW_LEAF_LIST)
+DEF_GCC_BUILTIN (BUILT_IN_IFLOORF, "ifloorf", BT_FN_INT_FLOAT, ATTR_CONST_NOTHROW_LEAF_LIST)
+DEF_GCC_BUILTIN (BUILT_IN_IFLOORL, "ifloorl", BT_FN_INT_LONGDOUBLE, ATTR_CONST_NOTHROW_LEAF_LIST)
DEF_C99_BUILTIN (BUILT_IN_ILOGB, "ilogb", BT_FN_INT_DOUBLE, ATTR_MATHFN_FPROUNDING_ERRNO)
DEF_C99_BUILTIN (BUILT_IN_ILOGBF, "ilogbf", BT_FN_INT_FLOAT, ATTR_MATHFN_FPROUNDING_ERRNO)
DEF_C99_BUILTIN (BUILT_IN_ILOGBL, "ilogbl", BT_FN_INT_LONGDOUBLE, ATTR_MATHFN_FPROUNDING_ERRNO)
DEF_GCC_BUILTIN (BUILT_IN_INFD32, "infd32", BT_FN_DFLOAT32, ATTR_CONST_NOTHROW_LEAF_LIST)
DEF_GCC_BUILTIN (BUILT_IN_INFD64, "infd64", BT_FN_DFLOAT64, ATTR_CONST_NOTHROW_LEAF_LIST)
DEF_GCC_BUILTIN (BUILT_IN_INFD128, "infd128", BT_FN_DFLOAT128, ATTR_CONST_NOTHROW_LEAF_LIST)
+DEF_GCC_BUILTIN (BUILT_IN_IRINT, "irint", BT_FN_INT_DOUBLE, ATTR_MATHFN_FPROUNDING_ERRNO)
+DEF_GCC_BUILTIN (BUILT_IN_IRINTF, "irintf", BT_FN_INT_FLOAT, ATTR_MATHFN_FPROUNDING_ERRNO)
+DEF_GCC_BUILTIN (BUILT_IN_IRINTL, "irintl", BT_FN_INT_LONGDOUBLE, ATTR_MATHFN_FPROUNDING_ERRNO)
+DEF_GCC_BUILTIN (BUILT_IN_IROUND, "iround", BT_FN_INT_DOUBLE, ATTR_MATHFN_ERRNO)
+DEF_GCC_BUILTIN (BUILT_IN_IROUNDF, "iroundf", BT_FN_INT_FLOAT, ATTR_MATHFN_ERRNO)
+DEF_GCC_BUILTIN (BUILT_IN_IROUNDL, "iroundl", BT_FN_INT_LONGDOUBLE, ATTR_MATHFN_ERRNO)
DEF_EXT_LIB_BUILTIN (BUILT_IN_J0, "j0", BT_FN_DOUBLE_DOUBLE, ATTR_MATHFN_FPROUNDING_ERRNO)
DEF_EXT_LIB_BUILTIN (BUILT_IN_J0F, "j0f", BT_FN_FLOAT_FLOAT, ATTR_MATHFN_FPROUNDING_ERRNO)
DEF_EXT_LIB_BUILTIN (BUILT_IN_J0L, "j0l", BT_FN_LONGDOUBLE_LONGDOUBLE, ATTR_MATHFN_FPROUNDING_ERRNO)
/* Only convert in ISO C99 mode. */
if (!TARGET_C99_FUNCTIONS)
break;
- if (outprec < TYPE_PRECISION (long_integer_type_node)
- || (outprec == TYPE_PRECISION (long_integer_type_node)
+ if (outprec < TYPE_PRECISION (integer_type_node)
+ || (outprec == TYPE_PRECISION (integer_type_node)
&& !TYPE_UNSIGNED (type)))
+ fn = mathfn_built_in (s_intype, BUILT_IN_ICEIL);
+ else if (outprec == TYPE_PRECISION (long_integer_type_node)
+ && !TYPE_UNSIGNED (type))
fn = mathfn_built_in (s_intype, BUILT_IN_LCEIL);
else if (outprec == TYPE_PRECISION (long_long_integer_type_node)
&& !TYPE_UNSIGNED (type))
/* Only convert in ISO C99 mode. */
if (!TARGET_C99_FUNCTIONS)
break;
- if (outprec < TYPE_PRECISION (long_integer_type_node)
- || (outprec == TYPE_PRECISION (long_integer_type_node)
+ if (outprec < TYPE_PRECISION (integer_type_node)
+ || (outprec == TYPE_PRECISION (integer_type_node)
&& !TYPE_UNSIGNED (type)))
+ fn = mathfn_built_in (s_intype, BUILT_IN_IFLOOR);
+ else if (outprec == TYPE_PRECISION (long_integer_type_node)
+ && !TYPE_UNSIGNED (type))
fn = mathfn_built_in (s_intype, BUILT_IN_LFLOOR);
else if (outprec == TYPE_PRECISION (long_long_integer_type_node)
&& !TYPE_UNSIGNED (type))
break;
CASE_FLT_FN (BUILT_IN_ROUND):
- if (outprec < TYPE_PRECISION (long_integer_type_node)
- || (outprec == TYPE_PRECISION (long_integer_type_node)
+ if (outprec < TYPE_PRECISION (integer_type_node)
+ || (outprec == TYPE_PRECISION (integer_type_node)
&& !TYPE_UNSIGNED (type)))
+ fn = mathfn_built_in (s_intype, BUILT_IN_IROUND);
+ else if (outprec == TYPE_PRECISION (long_integer_type_node)
+ && !TYPE_UNSIGNED (type))
fn = mathfn_built_in (s_intype, BUILT_IN_LROUND);
else if (outprec == TYPE_PRECISION (long_long_integer_type_node)
&& !TYPE_UNSIGNED (type))
break;
/* ... Fall through ... */
CASE_FLT_FN (BUILT_IN_RINT):
- if (outprec < TYPE_PRECISION (long_integer_type_node)
- || (outprec == TYPE_PRECISION (long_integer_type_node)
+ if (outprec < TYPE_PRECISION (integer_type_node)
+ || (outprec == TYPE_PRECISION (integer_type_node)
&& !TYPE_UNSIGNED (type)))
+ fn = mathfn_built_in (s_intype, BUILT_IN_IRINT);
+ else if (outprec < TYPE_PRECISION (long_integer_type_node)
+ && !TYPE_UNSIGNED (type))
fn = mathfn_built_in (s_intype, BUILT_IN_LRINT);
else if (outprec == TYPE_PRECISION (long_long_integer_type_node)
&& !TYPE_UNSIGNED (type))
CASE_FLT_FN (BUILT_IN_FLOOR):
CASE_FLT_FN (BUILT_IN_FMOD):
CASE_FLT_FN (BUILT_IN_FREXP):
+ CASE_FLT_FN (BUILT_IN_ICEIL):
+ CASE_FLT_FN (BUILT_IN_IFLOOR):
+ CASE_FLT_FN (BUILT_IN_IRINT):
+ CASE_FLT_FN (BUILT_IN_IROUND):
CASE_FLT_FN (BUILT_IN_LCEIL):
CASE_FLT_FN (BUILT_IN_LDEXP):
CASE_FLT_FN (BUILT_IN_LFLOOR):
+2011-08-12 Uros Bizjak <ubizjak@gmail.com>
+
+ * gcc.dg/builtins-67.c: New test.
+ * gcc.target/i386/conversion.c: Ditto.
+
2011-08-11 Romain Geissler <romain.geissler@gmail.com>
Brian Hackett <bhackett1024@gmail.com>
--- /dev/null
+/* Check that conversion functions link correctly with -ffast-math. */
+
+/* { dg-do link } */
+/* { dg-options "-ffast-math -lm" } */
+
+#include "builtins-config.h"
+
+double floor (double);
+float floorf (float);
+long double floorl (long double);
+
+double ceil (double);
+float ceilf (float);
+long double ceill (long double);
+
+double round (double);
+float roundf (float);
+long double roundl (long double);
+
+double rint (double);
+float rintf (float);
+long double rintl (long double);
+
+int ifloor (double a) { return (int) floor (a); }
+#ifdef HAVE_C99_RUNTIME
+int ifloorf (float a) { return (int) floorf (a); }
+int ifloorl (long double a) { return (int) floorl (a); }
+#endif
+
+long lfloor (double a) { return (long) floor (a); }
+#ifdef HAVE_C99_RUNTIME
+long lfloorf (float a) { return (long) floorf (a); }
+long lfloorl (long double a) { return (long) floorl (a); }
+#endif
+
+long long llfloor (double a) { return (long long) floor (a); }
+#ifdef HAVE_C99_RUNTIME
+long long llfloorf (float a) { return (long long) floorf (a); }
+long long llfloorl (long double a) { return (long long) floorl (a); }
+#endif
+
+int iceil (double a) { return (int) ceil (a); }
+#ifdef HAVE_C99_RUNTIME
+int iceilf (float a) { return (int) ceilf (a); }
+int iceill (long double a) { return (int) ceill (a); }
+#endif
+
+long lceil (double a) { return (long) ceil (a); }
+#ifdef HAVE_C99_RUNTIME
+long lceilf (float a) { return (long) ceilf (a); }
+long lceill (long double a) { return (long) ceill (a); }
+#endif
+
+long long llceil (double a) { return (long long) ceil (a); }
+#ifdef HAVE_C99_RUNTIME
+long long llceilf (float a) { return (long long) ceilf (a); }
+long long llceill (long double a) { return (long long) ceill (a); }
+#endif
+
+int iround (double a) { return (int) round (a); }
+#ifdef HAVE_C99_RUNTIME
+int iroundf (float a) { return (int) roundf (a); }
+int iroundl (long double a) { return (int) roundl (a); }
+#endif
+
+int irint (double a) { return (int) rint (a); }
+#ifdef HAVE_C99_RUNTIME
+int irintf (float a) { return (int) rintf (a); }
+int irintl (long double a) { return (int) rintl (a); }
+#endif
+
+int main () { return 0; }
--- /dev/null
+/* Check that conversion functions don't leak into global namespace. */
+
+/* { dg-do link } */
+/* { dg-options "-ffast-math" } */
+
+#include "../../gcc.dg/builtins-config.h"
+
+int ifloor (double a) { return __builtin_ifloor (a); }
+#ifdef HAVE_C99_RUNTIME
+int ifloorf (float a) { return __builtin_ifloorf (a); }
+int ifloorl (long double a) { return __builtin_ifloorl (a); }
+#endif
+
+long lfloor (double a) { return __builtin_lfloor (a); }
+#ifdef HAVE_C99_RUNTIME
+long lfloorf (float a) { return __builtin_lfloorf (a); }
+long lfloorl (long double a) { return __builtin_lfloorl (a); }
+#endif
+
+long long llfloor (double a) { return __builtin_llfloor (a); }
+#ifdef HAVE_C99_RUNTIME
+long long llfloorf (float a) { return __builtin_llfloorf (a); }
+long long llfloorl (long double a) { return __builtin_llfloorl (a); }
+#endif
+
+int iceil (double a) { return __builtin_iceil (a); }
+#ifdef HAVE_C99_RUNTIME
+int iceilf (float a) { return __builtin_iceilf (a); }
+int iceill (long double a) { return __builtin_iceill (a); }
+#endif
+
+long lceil (double a) { return __builtin_lceil (a); }
+#ifdef HAVE_C99_RUNTIME
+long lceilf (float a) { return __builtin_lceilf (a); }
+long lceill (long double a) { return __builtin_lceill (a); }
+#endif
+
+long long llceil (double a) { return __builtin_llceil (a); }
+#ifdef HAVE_C99_RUNTIME
+long long llceilf (float a) { return __builtin_llceilf (a); }
+long long llceill (long double a) { return __builtin_llceill (a); }
+#endif
+
+int iround (double a) { return __builtin_iround (a); }
+#ifdef HAVE_C99_RUNTIME
+int iroundf (float a) { return __builtin_iroundf (a); }
+int iroundl (long double a) { return __builtin_iroundl (a); }
+#endif
+
+int irint (double a) { return __builtin_irint (a); }
+#ifdef HAVE_C99_RUNTIME
+int irintf (float a) { return __builtin_irintf (a); }
+int irintl (long double a) { return __builtin_irintl (a); }
+#endif
+
+int main () { return 0; }