public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Alexandre Oliva <aoliva@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/aoliva/heads/testme)] take type from intrinsic in sincos pass Date: Wed, 7 Oct 2020 13:58:32 +0000 (GMT) [thread overview] Message-ID: <20201007135832.5FB023861841@sourceware.org> (raw) https://gcc.gnu.org/g:c57c67e0ae137443e9dc6c39ab40505564c97ede commit c57c67e0ae137443e9dc6c39ab40505564c97ede Author: Alexandre Oliva <oliva@adacore.com> Date: Wed Oct 7 07:39:27 2020 -0300 take type from intrinsic in sincos pass This is a first step towards enabling the sincos optimization in Ada. The issue this patch solves is that sincos takes the type to be looked up with mathfn_built_in from variables or temporaries passed as arguments to SIN and COS intrinsics. In Ada, different float types may be used but, despite their representation equivalence, their distinctness causes the optimization to be skipped, because they are not the types that mathfn_built_in expects. This patch introduces a function that maps intrinsics to the type they're associated with, and uses that type, obtained from the intrinsics used in calls to be optimized, to look up the correspoding CEXPI intrinsic. For the sake of defensive programming, when using the type obtained from the intrinsic, it now checks that, if different types are found for the used argument, or for other calls that use it, that the types are interchangeable. for gcc/ChangeLog * builtins.c (mathfn_built_in_type): New. * builtins.h (mathfn_built_in_type): Declare. * tree-ssa-math-opts.c (execute_cse_sincos_1): Use it to obtain the type expected by the intrinsic. Diff: --- gcc/builtins.c | 145 +++++++++++++++++++++++++++++++++++++++++++++++ gcc/builtins.h | 1 + gcc/tree-ssa-math-opts.c | 17 +++++- 3 files changed, 160 insertions(+), 3 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 4927255d456..75045690e68 100644 --- a/gcc/tree-ssa-math-opts.c +++ b/gcc/tree-ssa-math-opts.c @@ -1139,7 +1139,7 @@ execute_cse_sincos_1 (tree name) { gimple_stmt_iterator gsi; imm_use_iterator use_iter; - tree fndecl, res, type; + tree fndecl, res, type = NULL_TREE; gimple *def_stmt, *use_stmt, *stmt; int seen_cos = 0, seen_sin = 0, seen_cexpi = 0; auto_vec<gimple *> stmts; @@ -1147,7 +1147,6 @@ execute_cse_sincos_1 (tree name) int i; bool cfg_changed = false; - type = TREE_TYPE (name); FOR_EACH_IMM_USE_STMT (use_stmt, use_iter, name) { if (gimple_code (use_stmt) != GIMPLE_CALL @@ -1169,9 +1168,21 @@ execute_cse_sincos_1 (tree name) break; default:; + continue; } - } + tree t = mathfn_built_in_type (gimple_call_combined_fn (use_stmt)); + if (!type) + { + 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;
next reply other threads:[~2020-10-07 13:58 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-10-07 13:58 Alexandre Oliva [this message] 2020-10-08 16:58 Alexandre Oliva
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20201007135832.5FB023861841@sourceware.org \ --to=aoliva@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).