public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Michael Meissner <meissner@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/meissner/heads/work122-vpair)] Simplify making overloaded fp built-in functions. Date: Sat, 17 Jun 2023 01:55:30 +0000 (GMT) [thread overview] Message-ID: <20230617015530.7AFAC3858D35@sourceware.org> (raw) https://gcc.gnu.org/g:274266466944b79d55972540443d1ab3d64ffd4b commit 274266466944b79d55972540443d1ab3d64ffd4b Author: Michael Meissner <meissner@linux.ibm.com> Date: Fri Jun 16 21:55:06 2023 -0400 Simplify making overloaded fp built-in functions. 2023-06-16 Michael Meissner <meissner@linux.ibm.com> gcc/ * config/rs6000/rs6000-builtin.cc (fold_builtin_overload_fp): New helper function. (rs6000_gimple_fold_builtin): Move common code for built-in overloaded floating point functions into fold_builtin_overload_fp. Diff: --- gcc/config/rs6000/rs6000-builtin.cc | 81 ++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 42 deletions(-) diff --git a/gcc/config/rs6000/rs6000-builtin.cc b/gcc/config/rs6000/rs6000-builtin.cc index 54e6b9e7c9c..2b6e39ba638 100644 --- a/gcc/config/rs6000/rs6000-builtin.cc +++ b/gcc/config/rs6000/rs6000-builtin.cc @@ -1261,6 +1261,37 @@ rs6000_gimple_fold_mma_builtin (gimple_stmt_iterator *gsi, return true; } +/* Helper function to fold the overloaded fp functions for the scalar and + vector types that support the operation directly. */ + +static void +fold_builtin_overload_fp (gimple_stmt_iterator *gsi, + gimple *stmt, + enum tree_code code) +{ + location_t loc = gimple_location (stmt); + tree lhs = gimple_call_lhs (stmt); + tree t; + + if (code == ABS_EXPR || code == NEGATE_EXPR) + { + tree arg0 = gimple_call_arg (stmt, 0); + t = build1 (code, TREE_TYPE (lhs), arg0); + } + + else + { + tree arg0 = gimple_call_arg (stmt, 0); + tree arg1 = gimple_call_arg (stmt, 1); + t = build2 (code, TREE_TYPE (lhs), arg0, arg1); + } + + gimple *g = gimple_build_assign (lhs, t); + gimple_set_location (g, loc); + gsi_replace (gsi, g, true); + return; +} + /* Fold a machine-dependent built-in in GIMPLE. (For folding into a constant, use rs6000_fold_builtin.) */ bool @@ -2233,32 +2264,15 @@ rs6000_gimple_fold_builtin (gimple_stmt_iterator *gsi) case RS6000_BIF_ABS_F32_VECTOR: case RS6000_BIF_ABS_F64_SCALAR: case RS6000_BIF_ABS_F64_VECTOR: - { - location_t loc = gimple_location (stmt); - lhs = gimple_call_lhs (stmt); - arg0 = gimple_call_arg (stmt, 0); - tree t = build1 (ABS_EXPR, TREE_TYPE (lhs), arg0); - g = gimple_build_assign (lhs, t); - gimple_set_location (g, loc); - gsi_replace (gsi, g, true); - return true; - } + fold_builtin_overload_fp (gsi, stmt, ABS_EXPR); + return true; case RS6000_BIF_ADD_F32_SCALAR: case RS6000_BIF_ADD_F32_VECTOR: case RS6000_BIF_ADD_F64_SCALAR: case RS6000_BIF_ADD_F64_VECTOR: - { - location_t loc = gimple_location (stmt); - lhs = gimple_call_lhs (stmt); - arg0 = gimple_call_arg (stmt, 0); - arg1 = gimple_call_arg (stmt, 1); - tree t = build2 (PLUS_EXPR, TREE_TYPE (lhs), arg0, arg1); - g = gimple_build_assign (lhs, t); - gimple_set_location (g, loc); - gsi_replace (gsi, g, true); - return true; - } + fold_builtin_overload_fp (gsi, stmt, PLUS_EXPR); + return true; case RS6000_BIF_FMA_F32_SCALAR: case RS6000_BIF_FMA_F32_VECTOR: @@ -2283,32 +2297,15 @@ rs6000_gimple_fold_builtin (gimple_stmt_iterator *gsi) case RS6000_BIF_MULT_F64_VECTOR: case RS6000_BIF_SCALE_F32_SCALAR: case RS6000_BIF_SCALE_F64_SCALAR: - { - location_t loc = gimple_location (stmt); - lhs = gimple_call_lhs (stmt); - arg0 = gimple_call_arg (stmt, 0); - arg1 = gimple_call_arg (stmt, 1); - tree t = build2 (MULT_EXPR, TREE_TYPE (lhs), arg0, arg1); - g = gimple_build_assign (lhs, t); - gimple_set_location (g, loc); - gsi_replace (gsi, g, true); - return true; - } + fold_builtin_overload_fp (gsi, stmt, MULT_EXPR); + return true; case RS6000_BIF_NEG_F32_SCALAR: case RS6000_BIF_NEG_F32_VECTOR: case RS6000_BIF_NEG_F64_SCALAR: case RS6000_BIF_NEG_F64_VECTOR: - { - location_t loc = gimple_location (stmt); - lhs = gimple_call_lhs (stmt); - arg0 = gimple_call_arg (stmt, 0); - tree t = build1 (NEGATE_EXPR, TREE_TYPE (lhs), arg0); - g = gimple_build_assign (lhs, t); - gimple_set_location (g, loc); - gsi_replace (gsi, g, true); - return true; - } + fold_builtin_overload_fp (gsi, stmt, NEGATE_EXPR); + return true; case RS6000_BIF_REDUCE_F32_SCALAR: case RS6000_BIF_REDUCE_F64_SCALAR:
reply other threads:[~2023-06-17 1:55 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20230617015530.7AFAC3858D35@sourceware.org \ --to=meissner@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).