diff options
author | Kaveh R. Ghazi <ghazi@caip.rutgers.edu> | 2007-07-18 17:42:12 +0000 |
---|---|---|
committer | Kaveh Ghazi <ghazi@gcc.gnu.org> | 2007-07-18 17:42:12 +0000 |
commit | 0c8d3c2b0852bf0eca1413c311fc3d2a9d3c1ade (patch) | |
tree | 25f7979650149bcd55f9e00ab15c292b6ca66e36 | |
parent | 7faa1bbb5d0206cc83f20c1145f612f7754fdcf3 (diff) | |
download | gcc-0c8d3c2b0852bf0eca1413c311fc3d2a9d3c1ade.zip gcc-0c8d3c2b0852bf0eca1413c311fc3d2a9d3c1ade.tar.gz gcc-0c8d3c2b0852bf0eca1413c311fc3d2a9d3c1ade.tar.bz2 |
re PR target/30652 (SSE expansion is missing for isinf() and other fpclassify functions)
PR target/30652
* builtins.c (expand_builtin_interclass_mathfn): Allow for missing
optabs infrastructure. Provide generic implementation for
FINITE/ISFINITE.
(expand_builtin): Handle FINITE/ISFINITE.
(fold_builtin_classify): Make ISFINITE canonical instead of FINITE.
(fold_builtin_1): Likewise.
* builtins.def (BUILT_IN_ISFINITE): New.
* doc/extend.texi: Document isfinite.
testsuite:
* gcc.dg/pr28796-1.c: Add more cases.
* gcc.dg/pr28796-2.c: Likewise.
From-SVN: r126725
-rw-r--r-- | gcc/ChangeLog | 15 | ||||
-rw-r--r-- | gcc/builtins.c | 34 | ||||
-rw-r--r-- | gcc/builtins.def | 1 | ||||
-rw-r--r-- | gcc/doc/extend.texi | 3 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr28796-1.c | 14 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr28796-2.c | 13 |
7 files changed, 80 insertions, 5 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 87ae99a..3bd353f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,6 +1,21 @@ 2007-07-18 Kaveh R. Ghazi <ghazi@caip.rutgers.edu> PR target/30652 + + * builtins.c (expand_builtin_interclass_mathfn): Allow for missing + optabs infrastructure. Provide generic implementation for + FINITE/ISFINITE. + (expand_builtin): Handle FINITE/ISFINITE. + (fold_builtin_classify): Make ISFINITE canonical instead of FINITE. + (fold_builtin_1): Likewise. + + * builtins.def (BUILT_IN_ISFINITE): New. + + * doc/extend.texi: Document isfinite. + +2007-07-18 Kaveh R. Ghazi <ghazi@caip.rutgers.edu> + + PR target/30652 PR middle-end/20558 * builtins.c (expand_builtin_interclass_mathfn): Provide a diff --git a/gcc/builtins.c b/gcc/builtins.c index e92e56f..b96cfb2 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -2211,8 +2211,8 @@ expand_builtin_mathfn_3 (tree exp, rtx target, rtx subtarget) static rtx expand_builtin_interclass_mathfn (tree exp, rtx target, rtx subtarget) { - optab builtin_optab; - enum insn_code icode; + optab builtin_optab = 0; + enum insn_code icode = CODE_FOR_nothing; rtx op0; tree fndecl = get_callee_fndecl (exp); enum machine_mode mode; @@ -2230,6 +2230,10 @@ expand_builtin_interclass_mathfn (tree exp, rtx target, rtx subtarget) errno_set = true; builtin_optab = ilogb_optab; break; CASE_FLT_FN (BUILT_IN_ISINF): builtin_optab = isinf_optab; break; + case BUILT_IN_ISFINITE: + CASE_FLT_FN (BUILT_IN_FINITE): + /* These builtins have no optabs (yet). */ + break; default: gcc_unreachable (); } @@ -2241,7 +2245,8 @@ expand_builtin_interclass_mathfn (tree exp, rtx target, rtx subtarget) /* Optab mode depends on the mode of the input argument. */ mode = TYPE_MODE (TREE_TYPE (arg)); - icode = builtin_optab->handlers[(int) mode].insn_code; + if (builtin_optab) + icode = builtin_optab->handlers[(int) mode].insn_code; /* Before working hard, check whether the instruction is available. */ if (icode != CODE_FOR_nothing) @@ -2295,6 +2300,22 @@ expand_builtin_interclass_mathfn (tree exp, rtx target, rtx subtarget) build_real (type, r)); return expand_expr (result, target, VOIDmode, EXPAND_NORMAL); } + CASE_FLT_FN (BUILT_IN_FINITE): + case BUILT_IN_ISFINITE: + { + /* isfinite(x) -> islessequal(fabs(x),DBL_MAX). */ + tree const isle_fn = built_in_decls[BUILT_IN_ISLESSEQUAL]; + tree const type = TREE_TYPE (arg); + REAL_VALUE_TYPE r; + char buf[128]; + + get_max_float (REAL_MODE_FORMAT (mode), buf, sizeof (buf)); + real_from_string (&r, buf); + result = build_call_expr (isle_fn, 2, + fold_build1 (ABS_EXPR, type, arg), + build_real (type, r)); + return expand_expr (result, target, VOIDmode, EXPAND_NORMAL); + } default: break; } @@ -6150,6 +6171,8 @@ expand_builtin (tree exp, rtx target, rtx subtarget, enum machine_mode mode, if (! flag_unsafe_math_optimizations) break; CASE_FLT_FN (BUILT_IN_ISINF): + CASE_FLT_FN (BUILT_IN_FINITE): + case BUILT_IN_ISFINITE: target = expand_builtin_interclass_mathfn (exp, target, subtarget); if (target) return target; @@ -9569,7 +9592,7 @@ fold_builtin_classify (tree fndecl, tree arg, int builtin_index) return NULL_TREE; - case BUILT_IN_FINITE: + case BUILT_IN_ISFINITE: if (!HONOR_NANS (TYPE_MODE (TREE_TYPE (arg))) && !HONOR_INFINITIES (TYPE_MODE (TREE_TYPE (arg)))) return omit_one_operand (type, integer_one_node, arg); @@ -9972,7 +9995,8 @@ fold_builtin_1 (tree fndecl, tree arg0, bool ignore) case BUILT_IN_FINITED32: case BUILT_IN_FINITED64: case BUILT_IN_FINITED128: - return fold_builtin_classify (fndecl, arg0, BUILT_IN_FINITE); + case BUILT_IN_ISFINITE: + return fold_builtin_classify (fndecl, arg0, BUILT_IN_ISFINITE); CASE_FLT_FN (BUILT_IN_ISINF): case BUILT_IN_ISINFD32: diff --git a/gcc/builtins.def b/gcc/builtins.def index 2855617..8f5f4f2 100644 --- a/gcc/builtins.def +++ b/gcc/builtins.def @@ -654,6 +654,7 @@ DEF_EXT_LIB_BUILTIN (BUILT_IN_FINITEL, "finitel", BT_FN_INT_LONGDOUBLE, ATTR_ DEF_EXT_LIB_BUILTIN (BUILT_IN_FINITED32, "finited32", BT_FN_INT_DFLOAT32, ATTR_CONST_NOTHROW_LIST) DEF_EXT_LIB_BUILTIN (BUILT_IN_FINITED64, "finited64", BT_FN_INT_DFLOAT64, ATTR_CONST_NOTHROW_LIST) DEF_EXT_LIB_BUILTIN (BUILT_IN_FINITED128, "finited128", BT_FN_INT_DFLOAT128, ATTR_CONST_NOTHROW_LIST) +DEF_GCC_BUILTIN (BUILT_IN_ISFINITE, "isfinite", BT_FN_INT_VAR, ATTR_CONST_NOTHROW_TYPEGENERIC) DEF_C99_C90RES_BUILTIN (BUILT_IN_ISINF, "isinf", BT_FN_INT_VAR, ATTR_CONST_NOTHROW_TYPEGENERIC) DEF_EXT_LIB_BUILTIN (BUILT_IN_ISINFF, "isinff", BT_FN_INT_FLOAT, ATTR_CONST_NOTHROW_LIST) DEF_EXT_LIB_BUILTIN (BUILT_IN_ISINFL, "isinfl", BT_FN_INT_LONGDOUBLE, ATTR_CONST_NOTHROW_LIST) diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 9fa09f4c..c974d52 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -5437,6 +5437,7 @@ should be called and the @var{flag} argument passed to it. @node Other Builtins @section Other built-in functions provided by GCC @cindex built-in functions +@findex __builtin_isfinite @findex __builtin_isgreater @findex __builtin_isgreaterequal @findex __builtin_isless @@ -5965,6 +5966,8 @@ the same names as the standard macros ( @code{isgreater}, @code{islessgreater}, and @code{isunordered}) , with @code{__builtin_} prefixed. We intend for a library implementor to be able to simply @code{#define} each standard macro to its built-in equivalent. +In the same fashion, GCC provides an @code{isfinite} built-in used +with @code{__builtin_} prefixed. @deftypefn {Built-in Function} int __builtin_types_compatible_p (@var{type1}, @var{type2}) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1c48519..64a5d01 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -3,6 +3,11 @@ * gcc.dg/pr28796-1.c: Add more cases. * gcc.dg/pr28796-2.c: Likewise. +2007-07-18 Kaveh R. Ghazi <ghazi@caip.rutgers.edu> + + * gcc.dg/pr28796-1.c: Add more cases. + * gcc.dg/pr28796-2.c: Likewise. + 2007-07-17 Janus Weil <jaydub66@gmail.com> PR fortran/32535 diff --git a/gcc/testsuite/gcc.dg/pr28796-1.c b/gcc/testsuite/gcc.dg/pr28796-1.c index d200b1a..077118a 100644 --- a/gcc/testsuite/gcc.dg/pr28796-1.c +++ b/gcc/testsuite/gcc.dg/pr28796-1.c @@ -38,6 +38,20 @@ int main() if (__builtin_finitel (ld) != 1) link_error (); + if (__builtin_isinf (f) != 0) + link_error (); + if (__builtin_isinf (d) != 0) + link_error (); + if (__builtin_isinf (ld) != 0) + link_error (); + + if (__builtin_isfinite (f) != 1) + link_error (); + if (__builtin_isfinite (d) != 1) + link_error (); + if (__builtin_isfinite (ld) != 1) + link_error (); + if (f != f) link_error (); if (d != d) diff --git a/gcc/testsuite/gcc.dg/pr28796-2.c b/gcc/testsuite/gcc.dg/pr28796-2.c index 2545484..6f929a8 100644 --- a/gcc/testsuite/gcc.dg/pr28796-2.c +++ b/gcc/testsuite/gcc.dg/pr28796-2.c @@ -43,10 +43,23 @@ foo_1 (float f, double d, long double ld, if (__builtin_isinfl (ld) != res_isinf) abort (); + if (__builtin_isfinite (f) != res_isfin) + abort (); + if (__builtin_isfinite (d) != res_isfin) + abort (); + if (__builtin_isfinite (ld) != res_isfin) + abort (); + + if (__builtin_finitef (f) != res_isfin) + abort (); if (__builtin_finite (f) != res_isfin) abort (); if (__builtin_finite (d) != res_isfin) abort (); + if (__builtin_finitel (d) != res_isfin) + abort (); + if (__builtin_finitel (ld) != res_isfin) + abort (); } void __attribute__ ((__noinline__)) |