public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/meissner/heads/work122-vpair)] Simplify making overloaded fp built-in functions.
@ 2023-06-17 1:55 Michael Meissner
0 siblings, 0 replies; only message in thread
From: Michael Meissner @ 2023-06-17 1:55 UTC (permalink / raw)
To: gcc-cvs
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:
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-06-17 1:55 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-17 1:55 [gcc(refs/users/meissner/heads/work122-vpair)] Simplify making overloaded fp built-in functions Michael Meissner
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).