public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/aoliva/heads/testme)] improve sincos type inference
@ 2020-10-07 10:49 Alexandre Oliva
0 siblings, 0 replies; only message in thread
From: Alexandre Oliva @ 2020-10-07 10:49 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:28511c67f64a9484ff0e4a8cd7fd75dce0decfa2
commit 28511c67f64a9484ff0e4a8cd7fd75dce0decfa2
Author: Alexandre Oliva <oliva@adacore.com>
Date: Wed Oct 7 07:39:30 2020 -0300
improve sincos type inference
Diff:
---
gcc/builtins.c | 145 +++++++++++++++++++++++++++++++++++++++++++++++
gcc/builtins.h | 1 +
gcc/tree-ssa-math-opts.c | 25 +++-----
3 files changed, 155 insertions(+), 16 deletions(-)
diff --git a/gcc/builtins.c b/gcc/builtins.c
index f91266e4240..578960c9f20 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -2278,6 +2278,10 @@ mathfn_built_in_2 (tree type, combined_fn fn)
return END_BUILTINS;
}
+#undef CASE_MATHFN
+#undef CASE_MATHFN_FLOATN
+#undef CASE_MATHFN_REENT
+
/* Return mathematic function equivalent to FN but operating directly on TYPE,
if available. If IMPLICIT_P is true use the implicit builtin declaration,
otherwise use the explicit declaration. If we can't do the conversion,
@@ -2313,6 +2317,147 @@ mathfn_built_in (tree type, enum built_in_function fn)
return mathfn_built_in_1 (type, as_combined_fn (fn), /*implicit=*/ 1);
}
+/* Return the type associated with a built in function, i.e., the one
+ to be passed to mathfn_built_in to get the type-specific
+ function. */
+
+tree
+mathfn_built_in_type (combined_fn fn)
+{
+#define CASE_MATHFN(MATHFN) \
+ case BUILT_IN_##MATHFN: \
+ return double_type_node; \
+ case BUILT_IN_##MATHFN##F: \
+ return float_type_node; \
+ case BUILT_IN_##MATHFN##L: \
+ return long_double_type_node;
+
+#define CASE_MATHFN_FLOATN(MATHFN) \
+ CASE_MATHFN(MATHFN) \
+ case BUILT_IN_##MATHFN##F16: \
+ return float16_type_node; \
+ case BUILT_IN_##MATHFN##F32: \
+ return float32_type_node; \
+ case BUILT_IN_##MATHFN##F64: \
+ return float64_type_node; \
+ case BUILT_IN_##MATHFN##F128: \
+ return float128_type_node; \
+ case BUILT_IN_##MATHFN##F32X: \
+ return float32x_type_node; \
+ case BUILT_IN_##MATHFN##F64X: \
+ return float64x_type_node; \
+ case BUILT_IN_##MATHFN##F128X: \
+ return float128x_type_node;
+
+/* Similar to above, but appends _R after any F/L suffix. */
+#define CASE_MATHFN_REENT(MATHFN) \
+ case BUILT_IN_##MATHFN##_R: \
+ return double_type_node; \
+ case BUILT_IN_##MATHFN##F_R: \
+ return float_type_node; \
+ case BUILT_IN_##MATHFN##L_R: \
+ return long_double_type_node;
+
+ switch (fn)
+ {
+ CASE_MATHFN (ACOS)
+ CASE_MATHFN (ACOSH)
+ CASE_MATHFN (ASIN)
+ CASE_MATHFN (ASINH)
+ CASE_MATHFN (ATAN)
+ CASE_MATHFN (ATAN2)
+ CASE_MATHFN (ATANH)
+ CASE_MATHFN (CBRT)
+ CASE_MATHFN_FLOATN (CEIL)
+ CASE_MATHFN (CEXPI)
+ CASE_MATHFN_FLOATN (COPYSIGN)
+ CASE_MATHFN (COS)
+ CASE_MATHFN (COSH)
+ CASE_MATHFN (DREM)
+ CASE_MATHFN (ERF)
+ CASE_MATHFN (ERFC)
+ CASE_MATHFN (EXP)
+ CASE_MATHFN (EXP10)
+ CASE_MATHFN (EXP2)
+ CASE_MATHFN (EXPM1)
+ CASE_MATHFN (FABS)
+ CASE_MATHFN (FDIM)
+ CASE_MATHFN_FLOATN (FLOOR)
+ CASE_MATHFN_FLOATN (FMA)
+ CASE_MATHFN_FLOATN (FMAX)
+ CASE_MATHFN_FLOATN (FMIN)
+ CASE_MATHFN (FMOD)
+ CASE_MATHFN (FREXP)
+ CASE_MATHFN (GAMMA)
+ CASE_MATHFN_REENT (GAMMA) /* GAMMA_R */
+ CASE_MATHFN (HUGE_VAL)
+ CASE_MATHFN (HYPOT)
+ CASE_MATHFN (ILOGB)
+ CASE_MATHFN (ICEIL)
+ CASE_MATHFN (IFLOOR)
+ CASE_MATHFN (INF)
+ CASE_MATHFN (IRINT)
+ CASE_MATHFN (IROUND)
+ CASE_MATHFN (ISINF)
+ CASE_MATHFN (J0)
+ CASE_MATHFN (J1)
+ CASE_MATHFN (JN)
+ CASE_MATHFN (LCEIL)
+ CASE_MATHFN (LDEXP)
+ CASE_MATHFN (LFLOOR)
+ CASE_MATHFN (LGAMMA)
+ CASE_MATHFN_REENT (LGAMMA) /* LGAMMA_R */
+ CASE_MATHFN (LLCEIL)
+ CASE_MATHFN (LLFLOOR)
+ CASE_MATHFN (LLRINT)
+ CASE_MATHFN (LLROUND)
+ CASE_MATHFN (LOG)
+ CASE_MATHFN (LOG10)
+ CASE_MATHFN (LOG1P)
+ CASE_MATHFN (LOG2)
+ CASE_MATHFN (LOGB)
+ CASE_MATHFN (LRINT)
+ CASE_MATHFN (LROUND)
+ CASE_MATHFN (MODF)
+ CASE_MATHFN (NAN)
+ CASE_MATHFN (NANS)
+ CASE_MATHFN_FLOATN (NEARBYINT)
+ CASE_MATHFN (NEXTAFTER)
+ CASE_MATHFN (NEXTTOWARD)
+ CASE_MATHFN (POW)
+ CASE_MATHFN (POWI)
+ CASE_MATHFN (POW10)
+ CASE_MATHFN (REMAINDER)
+ CASE_MATHFN (REMQUO)
+ CASE_MATHFN_FLOATN (RINT)
+ CASE_MATHFN_FLOATN (ROUND)
+ CASE_MATHFN_FLOATN (ROUNDEVEN)
+ CASE_MATHFN (SCALB)
+ CASE_MATHFN (SCALBLN)
+ CASE_MATHFN (SCALBN)
+ CASE_MATHFN (SIGNBIT)
+ CASE_MATHFN (SIGNIFICAND)
+ CASE_MATHFN (SIN)
+ CASE_MATHFN (SINCOS)
+ CASE_MATHFN (SINH)
+ CASE_MATHFN_FLOATN (SQRT)
+ CASE_MATHFN (TAN)
+ CASE_MATHFN (TANH)
+ CASE_MATHFN (TGAMMA)
+ CASE_MATHFN_FLOATN (TRUNC)
+ CASE_MATHFN (Y0)
+ CASE_MATHFN (Y1)
+ CASE_MATHFN (YN)
+
+ default:
+ return NULL_TREE;
+ }
+
+#undef CASE_MATHFN
+#undef CASE_MATHFN_FLOATN
+#undef CASE_MATHFN_REENT
+}
+
/* If BUILT_IN_NORMAL function FNDECL has an associated internal function,
return its code, otherwise return IFN_LAST. Note that this function
only tests whether the function is defined in internals.def, not whether
diff --git a/gcc/builtins.h b/gcc/builtins.h
index 504c618b851..72012a28e03 100644
--- a/gcc/builtins.h
+++ b/gcc/builtins.h
@@ -109,6 +109,7 @@ extern void expand_builtin_setjmp_receiver (rtx);
extern void expand_builtin_update_setjmp_buf (rtx);
extern tree mathfn_built_in (tree, enum built_in_function fn);
extern tree mathfn_built_in (tree, combined_fn);
+extern tree mathfn_built_in_type (combined_fn);
extern rtx builtin_strncpy_read_str (void *, HOST_WIDE_INT, scalar_int_mode);
extern rtx builtin_memset_read_str (void *, HOST_WIDE_INT, scalar_int_mode);
extern rtx expand_builtin_saveregs (void);
diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c
index faba007ce4c..1c02ac1e635 100644
--- a/gcc/tree-ssa-math-opts.c
+++ b/gcc/tree-ssa-math-opts.c
@@ -1171,31 +1171,24 @@ execute_cse_sincos_1 (tree name)
continue;
}
- tree t = TREE_VALUE (TYPE_ARG_TYPES (gimple_call_fntype (use_stmt)));
+ tree t = mathfn_built_in_type (gimple_call_combined_fn (use_stmt));
if (!type)
- type = t;
- else if (t != type)
{
- if (!tree_nop_conversion_p (type, t))
- return false;
- /* If there is more than one type to choose from, prefer one
- that has a CEXPI builtin. */
- else if (!fndecl
- && (fndecl = mathfn_built_in (t, BUILT_IN_CEXPI)))
- type = t;
+ type = t;
+ t = TREE_TYPE (name);
}
+ /* This checks that NAME has the right type in the first round,
+ and, in subsequent rounds, that the built_in type is the same
+ type. */
+ if (type != t && !tree_nop_conversion_p (type, t))
+ return false;
}
if (seen_cos + seen_sin + seen_cexpi <= 1)
return false;
- if (type != TREE_TYPE (name)
- && !tree_nop_conversion_p (type, TREE_TYPE (name)))
- return false;
-
/* Simply insert cexpi at the beginning of top_bb but not earlier than
the name def statement. */
- if (!fndecl)
- fndecl = mathfn_built_in (type, BUILT_IN_CEXPI);
+ fndecl = mathfn_built_in (type, BUILT_IN_CEXPI);
if (!fndecl)
return false;
stmt = gimple_build_call (fndecl, 1, name);
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-10-07 10:49 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-07 10:49 [gcc(refs/users/aoliva/heads/testme)] improve sincos type inference Alexandre Oliva
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).