From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1005) id 7AFAC3858D35; Sat, 17 Jun 2023 01:55:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7AFAC3858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686966930; bh=xhQovpW/Ie0iXZq95V+5n6x6sbs9gxOwFp+AQK7bAAQ=; h=From:To:Subject:Date:From; b=gszPwWRQUZfHDsmw+TjqpkpQpN3omINWiJav62ifVOnpG2rwJBBnIOo0hDAnnqXS/ tGjvOEtRByXyPvhT28QlFGB+8ysokd3FVM6k6EhemP9tKgvMaUU05leri0M6i6mE7V KsOAepBsiBNZuc/LuDF8wTaJ+JL/+7/04+4J1hCU= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Michael Meissner To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/meissner/heads/work122-vpair)] Simplify making overloaded fp built-in functions. X-Act-Checkin: gcc X-Git-Author: Michael Meissner X-Git-Refname: refs/users/meissner/heads/work122-vpair X-Git-Oldrev: 141d5656c5ad6f4266cc1b611a5b39f3e107050e X-Git-Newrev: 274266466944b79d55972540443d1ab3d64ffd4b Message-Id: <20230617015530.7AFAC3858D35@sourceware.org> Date: Sat, 17 Jun 2023 01:55:30 +0000 (GMT) List-Id: https://gcc.gnu.org/g:274266466944b79d55972540443d1ab3d64ffd4b commit 274266466944b79d55972540443d1ab3d64ffd4b Author: Michael Meissner Date: Fri Jun 16 21:55:06 2023 -0400 Simplify making overloaded fp built-in functions. 2023-06-16 Michael Meissner 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: