From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22714 invoked by alias); 7 Nov 2015 12:44:57 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 22702 invoked by uid 89); 7 Nov 2015 12:44:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.8 required=5.0 tests=AWL,BAYES_05,SPF_PASS autolearn=ham version=3.3.2 X-HELO: eu-smtp-delivery-143.mimecast.com Received: from eu-smtp-delivery-143.mimecast.com (HELO eu-smtp-delivery-143.mimecast.com) (146.101.78.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 07 Nov 2015 12:44:52 +0000 Received: from cam-owa1.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-3-THdzXa6dSfija8iB7i8upg-1; Sat, 07 Nov 2015 12:44:47 +0000 Received: from localhost ([10.1.2.79]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Sat, 7 Nov 2015 12:44:47 +0000 From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: Make more use of combined_fn Date: Sat, 07 Nov 2015 12:44:00 -0000 Message-ID: <87mvuqq8qo.fsf@e105548-lin.cambridge.arm.com> User-Agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 X-MC-Unique: THdzXa6dSfija8iB7i8upg-1 Content-Type: multipart/mixed; boundary="=-=-=" X-SW-Source: 2015-11/txt/msg00794.txt.bz2 --=-=-= Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable Content-length: 1461 This patch generalises fold-const.[hc] routines to use combined_fn instead of built_in_function. It also updates gimple-ssa-backprop,c since the update is simple and it avoids churn on the call to negate_mathfn_p. Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi. OK to install? Thanks, Richard [I've attached a -b form of the patch too since it's easier to read.] gcc/ * fold-const.h (negate_mathfn_p): Take a combined_fn rather than a built_in_function. (tree_call_nonnegative_warnv_p): Take a combined_fn rather than a function decl. (integer_valued_real_call_p): Likewise. * fold-const.c: Include case-cfn-macros.h (negate_mathfn_p): Take a combined_fn rather than a built_in_function. (negate_expr_p): Update accordingly. (tree_call_nonnegative_warnv_p): Take a combined_fn rather than a function decl. (integer_valued_real_call_p): Likewise. (tree_invalid_nonnegative_warnv_p): Update accordingly. (integer_valued_real_p): Likewise. * gimple-fold.c (gimple_call_nonnegative_warnv_p): Update call to tree_call_nonnegative_warnv_p. (gimple_call_integer_valued_real_p): Likewise integer_valued_real_call_p. * gimple-ssa-backprop.c: Include case-cfn-macros.h. (backprop::process_builtin_call_use): Extend to combined_fn. (strip_sign_op_1): Likewise. (backprop::process_use): Don't check for built-in calls here. (backprop::execute): Likewise. (backprop::optimize_builtin_call): Update call to negate_mathfn_p. --=-=-= Content-Type: text/x-diff; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename=actual.patch Content-length: 17357 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index ae28445..a7085ef 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -73,6 +73,7 @@ along with GCC; see the file COPYING3. If not see #include "params.h" #include "tree-into-ssa.h" #include "md5.h" +#include "case-cfn-macros.h" =20 #ifndef LOAD_EXTEND_OP #define LOAD_EXTEND_OP(M) UNKNOWN @@ -313,39 +314,39 @@ fold_overflow_warning (const char* gmsgid, enum warn_= strict_overflow_code wc) is odd, i.e. -f(x) =3D=3D f(-x). */ =20 bool -negate_mathfn_p (enum built_in_function code) -{ - switch (code) - { - CASE_FLT_FN (BUILT_IN_ASIN): - CASE_FLT_FN (BUILT_IN_ASINH): - CASE_FLT_FN (BUILT_IN_ATAN): - CASE_FLT_FN (BUILT_IN_ATANH): - CASE_FLT_FN (BUILT_IN_CASIN): - CASE_FLT_FN (BUILT_IN_CASINH): - CASE_FLT_FN (BUILT_IN_CATAN): - CASE_FLT_FN (BUILT_IN_CATANH): - CASE_FLT_FN (BUILT_IN_CBRT): - CASE_FLT_FN (BUILT_IN_CPROJ): - CASE_FLT_FN (BUILT_IN_CSIN): - CASE_FLT_FN (BUILT_IN_CSINH): - CASE_FLT_FN (BUILT_IN_CTAN): - CASE_FLT_FN (BUILT_IN_CTANH): - CASE_FLT_FN (BUILT_IN_ERF): - CASE_FLT_FN (BUILT_IN_LLROUND): - CASE_FLT_FN (BUILT_IN_LROUND): - CASE_FLT_FN (BUILT_IN_ROUND): - CASE_FLT_FN (BUILT_IN_SIN): - CASE_FLT_FN (BUILT_IN_SINH): - CASE_FLT_FN (BUILT_IN_TAN): - CASE_FLT_FN (BUILT_IN_TANH): - CASE_FLT_FN (BUILT_IN_TRUNC): +negate_mathfn_p (combined_fn fn) +{ + switch (fn) + { + CASE_CFN_ASIN: + CASE_CFN_ASINH: + CASE_CFN_ATAN: + CASE_CFN_ATANH: + CASE_CFN_CASIN: + CASE_CFN_CASINH: + CASE_CFN_CATAN: + CASE_CFN_CATANH: + CASE_CFN_CBRT: + CASE_CFN_CPROJ: + CASE_CFN_CSIN: + CASE_CFN_CSINH: + CASE_CFN_CTAN: + CASE_CFN_CTANH: + CASE_CFN_ERF: + CASE_CFN_LLROUND: + CASE_CFN_LROUND: + CASE_CFN_ROUND: + CASE_CFN_SIN: + CASE_CFN_SINH: + CASE_CFN_TAN: + CASE_CFN_TANH: + CASE_CFN_TRUNC: return true; =20 - CASE_FLT_FN (BUILT_IN_LLRINT): - CASE_FLT_FN (BUILT_IN_LRINT): - CASE_FLT_FN (BUILT_IN_NEARBYINT): - CASE_FLT_FN (BUILT_IN_RINT): + CASE_CFN_LLRINT: + CASE_CFN_LRINT: + CASE_CFN_NEARBYINT: + CASE_CFN_RINT: return !flag_rounding_math; =20 default: @@ -506,7 +507,7 @@ negate_expr_p (tree t) =20 case CALL_EXPR: /* Negate -f(x) as f(-x). */ - if (negate_mathfn_p (builtin_mathfn_code (t))) + if (negate_mathfn_p (get_call_combined_fn (t))) return negate_expr_p (CALL_EXPR_ARG (t, 0)); break; =20 @@ -693,7 +694,7 @@ fold_negate_expr (location_t loc, tree t) =20 case CALL_EXPR: /* Negate -f(x) as f(-x). */ - if (negate_mathfn_p (builtin_mathfn_code (t)) + if (negate_mathfn_p (get_call_combined_fn (t)) && negate_expr_p (CALL_EXPR_ARG (t, 0))) { tree fndecl, arg; @@ -12905,121 +12906,120 @@ tree_single_nonnegative_warnv_p (tree t, bool *= strict_overflow_p, int depth) *STRICT_OVERFLOW_P. DEPTH is the current nesting depth of the query. = */ =20 bool -tree_call_nonnegative_warnv_p (tree type, tree fndecl, tree arg0, tree arg= 1, +tree_call_nonnegative_warnv_p (tree type, combined_fn fn, tree arg0, tree = arg1, bool *strict_overflow_p, int depth) { - if (fndecl && DECL_BUILT_IN_CLASS (fndecl) =3D=3D BUILT_IN_NORMAL) - switch (DECL_FUNCTION_CODE (fndecl)) - { - CASE_FLT_FN (BUILT_IN_ACOS): - CASE_FLT_FN (BUILT_IN_ACOSH): - CASE_FLT_FN (BUILT_IN_CABS): - CASE_FLT_FN (BUILT_IN_COSH): - CASE_FLT_FN (BUILT_IN_ERFC): - CASE_FLT_FN (BUILT_IN_EXP): - CASE_FLT_FN (BUILT_IN_EXP10): - CASE_FLT_FN (BUILT_IN_EXP2): - CASE_FLT_FN (BUILT_IN_FABS): - CASE_FLT_FN (BUILT_IN_FDIM): - CASE_FLT_FN (BUILT_IN_HYPOT): - CASE_FLT_FN (BUILT_IN_POW10): - CASE_INT_FN (BUILT_IN_FFS): - CASE_INT_FN (BUILT_IN_PARITY): - CASE_INT_FN (BUILT_IN_POPCOUNT): - CASE_INT_FN (BUILT_IN_CLZ): - CASE_INT_FN (BUILT_IN_CLRSB): - case BUILT_IN_BSWAP32: - case BUILT_IN_BSWAP64: - /* Always true. */ - return true; + switch (fn) + { + CASE_CFN_ACOS: + CASE_CFN_ACOSH: + CASE_CFN_CABS: + CASE_CFN_COSH: + CASE_CFN_ERFC: + CASE_CFN_EXP: + CASE_CFN_EXP10: + CASE_CFN_EXP2: + CASE_CFN_FABS: + CASE_CFN_FDIM: + CASE_CFN_HYPOT: + CASE_CFN_POW10: + CASE_CFN_FFS: + CASE_CFN_PARITY: + CASE_CFN_POPCOUNT: + CASE_CFN_CLZ: + CASE_CFN_CLRSB: + case CFN_BUILT_IN_BSWAP32: + case CFN_BUILT_IN_BSWAP64: + /* Always true. */ + return true; =20 - CASE_FLT_FN (BUILT_IN_SQRT): - /* sqrt(-0.0) is -0.0. */ - if (!HONOR_SIGNED_ZEROS (element_mode (type))) - return true; - return RECURSE (arg0); - - CASE_FLT_FN (BUILT_IN_ASINH): - CASE_FLT_FN (BUILT_IN_ATAN): - CASE_FLT_FN (BUILT_IN_ATANH): - CASE_FLT_FN (BUILT_IN_CBRT): - CASE_FLT_FN (BUILT_IN_CEIL): - CASE_FLT_FN (BUILT_IN_ERF): - CASE_FLT_FN (BUILT_IN_EXPM1): - CASE_FLT_FN (BUILT_IN_FLOOR): - CASE_FLT_FN (BUILT_IN_FMOD): - CASE_FLT_FN (BUILT_IN_FREXP): - CASE_FLT_FN (BUILT_IN_ICEIL): - CASE_FLT_FN (BUILT_IN_IFLOOR): - CASE_FLT_FN (BUILT_IN_IRINT): - CASE_FLT_FN (BUILT_IN_IROUND): - CASE_FLT_FN (BUILT_IN_LCEIL): - CASE_FLT_FN (BUILT_IN_LDEXP): - CASE_FLT_FN (BUILT_IN_LFLOOR): - CASE_FLT_FN (BUILT_IN_LLCEIL): - CASE_FLT_FN (BUILT_IN_LLFLOOR): - CASE_FLT_FN (BUILT_IN_LLRINT): - CASE_FLT_FN (BUILT_IN_LLROUND): - CASE_FLT_FN (BUILT_IN_LRINT): - CASE_FLT_FN (BUILT_IN_LROUND): - CASE_FLT_FN (BUILT_IN_MODF): - CASE_FLT_FN (BUILT_IN_NEARBYINT): - CASE_FLT_FN (BUILT_IN_RINT): - CASE_FLT_FN (BUILT_IN_ROUND): - CASE_FLT_FN (BUILT_IN_SCALB): - CASE_FLT_FN (BUILT_IN_SCALBLN): - CASE_FLT_FN (BUILT_IN_SCALBN): - CASE_FLT_FN (BUILT_IN_SIGNBIT): - CASE_FLT_FN (BUILT_IN_SIGNIFICAND): - CASE_FLT_FN (BUILT_IN_SINH): - CASE_FLT_FN (BUILT_IN_TANH): - CASE_FLT_FN (BUILT_IN_TRUNC): - /* True if the 1st argument is nonnegative. */ - return RECURSE (arg0); - - CASE_FLT_FN (BUILT_IN_FMAX): - /* True if the 1st OR 2nd arguments are nonnegative. */ - return RECURSE (arg0) || RECURSE (arg1); - - CASE_FLT_FN (BUILT_IN_FMIN): - /* True if the 1st AND 2nd arguments are nonnegative. */ - return RECURSE (arg0) && RECURSE (arg1); - - CASE_FLT_FN (BUILT_IN_COPYSIGN): - /* True if the 2nd argument is nonnegative. */ - return RECURSE (arg1); - - CASE_FLT_FN (BUILT_IN_POWI): - /* True if the 1st argument is nonnegative or the second - argument is an even integer. */ - if (TREE_CODE (arg1) =3D=3D INTEGER_CST - && (TREE_INT_CST_LOW (arg1) & 1) =3D=3D 0) - return true; - return RECURSE (arg0); + CASE_CFN_SQRT: + /* sqrt(-0.0) is -0.0. */ + if (!HONOR_SIGNED_ZEROS (element_mode (type))) + return true; + return RECURSE (arg0); + + CASE_CFN_ASINH: + CASE_CFN_ATAN: + CASE_CFN_ATANH: + CASE_CFN_CBRT: + CASE_CFN_CEIL: + CASE_CFN_ERF: + CASE_CFN_EXPM1: + CASE_CFN_FLOOR: + CASE_CFN_FMOD: + CASE_CFN_FREXP: + CASE_CFN_ICEIL: + CASE_CFN_IFLOOR: + CASE_CFN_IRINT: + CASE_CFN_IROUND: + CASE_CFN_LCEIL: + CASE_CFN_LDEXP: + CASE_CFN_LFLOOR: + CASE_CFN_LLCEIL: + CASE_CFN_LLFLOOR: + CASE_CFN_LLRINT: + CASE_CFN_LLROUND: + CASE_CFN_LRINT: + CASE_CFN_LROUND: + CASE_CFN_MODF: + CASE_CFN_NEARBYINT: + CASE_CFN_RINT: + CASE_CFN_ROUND: + CASE_CFN_SCALB: + CASE_CFN_SCALBLN: + CASE_CFN_SCALBN: + CASE_CFN_SIGNBIT: + CASE_CFN_SIGNIFICAND: + CASE_CFN_SINH: + CASE_CFN_TANH: + CASE_CFN_TRUNC: + /* True if the 1st argument is nonnegative. */ + return RECURSE (arg0); + + CASE_CFN_FMAX: + /* True if the 1st OR 2nd arguments are nonnegative. */ + return RECURSE (arg0) || RECURSE (arg1); + + CASE_CFN_FMIN: + /* True if the 1st AND 2nd arguments are nonnegative. */ + return RECURSE (arg0) && RECURSE (arg1); + + CASE_CFN_COPYSIGN: + /* True if the 2nd argument is nonnegative. */ + return RECURSE (arg1); + + CASE_CFN_POWI: + /* True if the 1st argument is nonnegative or the second + argument is an even integer. */ + if (TREE_CODE (arg1) =3D=3D INTEGER_CST + && (TREE_INT_CST_LOW (arg1) & 1) =3D=3D 0) + return true; + return RECURSE (arg0); =20 - CASE_FLT_FN (BUILT_IN_POW): - /* True if the 1st argument is nonnegative or the second - argument is an even integer valued real. */ - if (TREE_CODE (arg1) =3D=3D REAL_CST) - { - REAL_VALUE_TYPE c; - HOST_WIDE_INT n; + CASE_CFN_POW: + /* True if the 1st argument is nonnegative or the second + argument is an even integer valued real. */ + if (TREE_CODE (arg1) =3D=3D REAL_CST) + { + REAL_VALUE_TYPE c; + HOST_WIDE_INT n; =20 - c =3D TREE_REAL_CST (arg1); - n =3D real_to_integer (&c); - if ((n & 1) =3D=3D 0) - { - REAL_VALUE_TYPE cint; - real_from_integer (&cint, VOIDmode, n, SIGNED); - if (real_identical (&c, &cint)) - return true; - } - } - return RECURSE (arg0); + c =3D TREE_REAL_CST (arg1); + n =3D real_to_integer (&c); + if ((n & 1) =3D=3D 0) + { + REAL_VALUE_TYPE cint; + real_from_integer (&cint, VOIDmode, n, SIGNED); + if (real_identical (&c, &cint)) + return true; + } + } + return RECURSE (arg0); =20 - default: - break; - } + default: + break; + } return tree_simple_nonnegative_warnv_p (CALL_EXPR, type); } =20 @@ -13074,7 +13074,7 @@ tree_invalid_nonnegative_warnv_p (tree t, bool *str= ict_overflow_p, int depth) tree arg1 =3D call_expr_nargs (t) > 1 ? CALL_EXPR_ARG (t, 1) : NULL_TREE; =20 return tree_call_nonnegative_warnv_p (TREE_TYPE (t), - get_callee_fndecl (t), + get_call_combined_fn (t), arg0, arg1, strict_overflow_p, depth); @@ -13477,26 +13477,25 @@ integer_valued_real_binary_p (tree_code code, tre= e op0, tree op1, int depth) DEPTH is the current nesting depth of the query. */ =20 bool -integer_valued_real_call_p (tree fndecl, tree arg0, tree arg1, int depth) +integer_valued_real_call_p (combined_fn fn, tree arg0, tree arg1, int dept= h) { - if (fndecl && DECL_BUILT_IN_CLASS (fndecl) =3D=3D BUILT_IN_NORMAL) - switch (DECL_FUNCTION_CODE (fndecl)) - { - CASE_FLT_FN (BUILT_IN_CEIL): - CASE_FLT_FN (BUILT_IN_FLOOR): - CASE_FLT_FN (BUILT_IN_NEARBYINT): - CASE_FLT_FN (BUILT_IN_RINT): - CASE_FLT_FN (BUILT_IN_ROUND): - CASE_FLT_FN (BUILT_IN_TRUNC): - return true; + switch (fn) + { + CASE_CFN_CEIL: + CASE_CFN_FLOOR: + CASE_CFN_NEARBYINT: + CASE_CFN_RINT: + CASE_CFN_ROUND: + CASE_CFN_TRUNC: + return true; =20 - CASE_FLT_FN (BUILT_IN_FMIN): - CASE_FLT_FN (BUILT_IN_FMAX): - return RECURSE (arg0) && RECURSE (arg1); + CASE_CFN_FMIN: + CASE_CFN_FMAX: + return RECURSE (arg0) && RECURSE (arg1); =20 - default: - break; - } + default: + break; + } return false; } =20 @@ -13607,7 +13606,7 @@ integer_valued_real_p (tree t, int depth) tree arg1 =3D (call_expr_nargs (t) > 1 ? CALL_EXPR_ARG (t, 1) : NULL_TREE); - return integer_valued_real_call_p (get_callee_fndecl (t), + return integer_valued_real_call_p (get_call_combined_fn (t), arg0, arg1, depth); } =20 diff --git a/gcc/fold-const.h b/gcc/fold-const.h index 94a21b7..7741802 100644 --- a/gcc/fold-const.h +++ b/gcc/fold-const.h @@ -137,12 +137,12 @@ extern bool tree_unary_nonnegative_warnv_p (enum tree= _code, tree, tree, extern bool tree_binary_nonnegative_warnv_p (enum tree_code, tree, tree, t= ree, bool *, int); extern bool tree_single_nonnegative_warnv_p (tree, bool *, int); -extern bool tree_call_nonnegative_warnv_p (tree, tree, tree, tree, bool *, - int); +extern bool tree_call_nonnegative_warnv_p (tree, combined_fn, tree, tree, + bool *, int); =20 extern bool integer_valued_real_unary_p (tree_code, tree, int); extern bool integer_valued_real_binary_p (tree_code, tree, tree, int); -extern bool integer_valued_real_call_p (tree, tree, tree, int); +extern bool integer_valued_real_call_p (combined_fn, tree, tree, int); extern bool integer_valued_real_single_p (tree, int); extern bool integer_valued_real_p (tree, int =3D 0); =20 @@ -179,7 +179,7 @@ extern tree sign_bit_p (tree, const_tree); extern tree exact_inverse (tree, tree); extern tree const_unop (enum tree_code, tree, tree); extern tree const_binop (enum tree_code, tree, tree, tree); -extern bool negate_mathfn_p (enum built_in_function); +extern bool negate_mathfn_p (combined_fn); extern const char *c_getstr (tree); =20 /* Return OFF converted to a pointer offset type suitable as offset for diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index 45840af..b72ea00 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -6197,7 +6197,7 @@ gimple_call_nonnegative_warnv_p (gimple *stmt, bool *= strict_overflow_p, gimple_call_arg (stmt, 1) : NULL_TREE; =20 return tree_call_nonnegative_warnv_p (gimple_expr_type (stmt), - gimple_call_fndecl (stmt), + gimple_call_combined_fn (stmt), arg0, arg1, strict_overflow_p, depth); @@ -6290,7 +6290,7 @@ gimple_call_integer_valued_real_p (gimple *stmt, int = depth) tree arg1 =3D (gimple_call_num_args (stmt) > 1 ? gimple_call_arg (stmt, 1) : NULL_TREE); - return integer_valued_real_call_p (gimple_call_fndecl (stmt), + return integer_valued_real_call_p (gimple_call_combined_fn (stmt), arg0, arg1, depth); } =20 diff --git a/gcc/gimple-ssa-backprop.c b/gcc/gimple-ssa-backprop.c index 91a3c79..d573651 100644 --- a/gcc/gimple-ssa-backprop.c +++ b/gcc/gimple-ssa-backprop.c @@ -102,6 +102,7 @@ along with GCC; see the file COPYING3. If not see #include "gimple-fold.h" #include "alloc-pool.h" #include "tree-hash-traits.h" +#include "case-cfn-macros.h" =20 namespace { =20 @@ -337,26 +338,29 @@ backprop::pop_from_worklist () void backprop::process_builtin_call_use (gcall *call, tree rhs, usage_info *inf= o) { - enum built_in_function fn =3D DECL_FUNCTION_CODE (gimple_call_fndecl (ca= ll)); + combined_fn fn =3D gimple_call_combined_fn (call); tree lhs =3D gimple_call_lhs (call); switch (fn) { - CASE_FLT_FN (BUILT_IN_COS): - CASE_FLT_FN (BUILT_IN_COSH): - CASE_FLT_FN (BUILT_IN_CCOS): - CASE_FLT_FN (BUILT_IN_CCOSH): - CASE_FLT_FN (BUILT_IN_HYPOT): + case CFN_LAST: + break; + + CASE_CFN_COS: + CASE_CFN_COSH: + CASE_CFN_CCOS: + CASE_CFN_CCOSH: + CASE_CFN_HYPOT: /* The signs of all inputs are ignored. */ info->flags.ignore_sign =3D true; break; =20 - CASE_FLT_FN (BUILT_IN_COPYSIGN): + CASE_CFN_COPYSIGN: /* The sign of the first input is ignored. */ if (rhs !=3D gimple_call_arg (call, 1)) info->flags.ignore_sign =3D true; break; =20 - CASE_FLT_FN (BUILT_IN_POW): + CASE_CFN_POW: { /* The sign of the first input is ignored as long as the second input is an even real. */ @@ -369,7 +373,7 @@ backprop::process_builtin_call_use (gcall *call, tree r= hs, usage_info *info) break; } =20 - CASE_FLT_FN (BUILT_IN_FMA): + CASE_CFN_FMA: /* In X * X + Y, where Y is distinct from X, the sign of X doesn't matter. */ if (gimple_call_arg (call, 0) =3D=3D rhs @@ -472,10 +476,7 @@ backprop::process_use (gimple *stmt, tree rhs, usage_i= nfo *info) } =20 if (gcall *call =3D dyn_cast (stmt)) - { - if (gimple_call_builtin_p (call, BUILT_IN_NORMAL)) - process_builtin_call_use (call, rhs, info); - } + process_builtin_call_use (call, rhs, info); else if (gassign *assign =3D dyn_cast (stmt)) process_assign_use (assign, rhs, info); else if (gphi *phi =3D dyn_cast (stmt)) @@ -686,17 +687,14 @@ strip_sign_op_1 (tree rhs) break; } else if (gcall *call =3D dyn_cast (def_stmt)) - { - if (gimple_call_builtin_p (call, BUILT_IN_NORMAL)) - switch (DECL_FUNCTION_CODE (gimple_call_fndecl (call))) - { - CASE_FLT_FN (BUILT_IN_COPYSIGN): - return gimple_call_arg (call, 0); - - default: - break; - } - } + switch (gimple_call_combined_fn (call)) + { + CASE_CFN_COPYSIGN: + return gimple_call_arg (call, 0); + + default: + break; + } =20 return NULL_TREE; } @@ -758,11 +756,10 @@ backprop::complete_change (gimple *stmt) void backprop::optimize_builtin_call (gcall *call, tree lhs, const usage_info *= info) { - tree fndecl =3D gimple_call_fndecl (call); - enum built_in_function fn =3D DECL_FUNCTION_CODE (fndecl); /* If we have an f such that -f(x) =3D f(-x), and if the sign of the res= ult doesn't matter, strip any sign operations from the input. */ - if (info->flags.ignore_sign && negate_mathfn_p (fn)) + if (info->flags.ignore_sign + && negate_mathfn_p (gimple_call_combined_fn (call))) { tree new_arg =3D strip_sign_op (gimple_call_arg (call, 0)); if (new_arg) @@ -889,10 +886,7 @@ backprop::execute () tree var =3D m_vars[i].first; gimple *stmt =3D SSA_NAME_DEF_STMT (var); if (gcall *call =3D dyn_cast (stmt)) - { - if (gimple_call_builtin_p (call, BUILT_IN_NORMAL)) - optimize_builtin_call (call, var, info); - } + optimize_builtin_call (call, var, info); else if (gassign *assign =3D dyn_cast (stmt)) optimize_assign (assign, var, info); else if (gphi *phi =3D dyn_cast (stmt)) --=-=-= Content-Type: text/x-diff; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename=with-b.patch Content-length: 15400 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index ae28445..a7085ef 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -73,6 +73,7 @@ along with GCC; see the file COPYING3. If not see #include "params.h" #include "tree-into-ssa.h" #include "md5.h" +#include "case-cfn-macros.h" =20 #ifndef LOAD_EXTEND_OP #define LOAD_EXTEND_OP(M) UNKNOWN @@ -313,39 +314,39 @@ fold_overflow_warning (const char* gmsgid, enum warn_= strict_overflow_code wc) is odd, i.e. -f(x) =3D=3D f(-x). */ =20 bool -negate_mathfn_p (enum built_in_function code) -{ - switch (code) - { - CASE_FLT_FN (BUILT_IN_ASIN): - CASE_FLT_FN (BUILT_IN_ASINH): - CASE_FLT_FN (BUILT_IN_ATAN): - CASE_FLT_FN (BUILT_IN_ATANH): - CASE_FLT_FN (BUILT_IN_CASIN): - CASE_FLT_FN (BUILT_IN_CASINH): - CASE_FLT_FN (BUILT_IN_CATAN): - CASE_FLT_FN (BUILT_IN_CATANH): - CASE_FLT_FN (BUILT_IN_CBRT): - CASE_FLT_FN (BUILT_IN_CPROJ): - CASE_FLT_FN (BUILT_IN_CSIN): - CASE_FLT_FN (BUILT_IN_CSINH): - CASE_FLT_FN (BUILT_IN_CTAN): - CASE_FLT_FN (BUILT_IN_CTANH): - CASE_FLT_FN (BUILT_IN_ERF): - CASE_FLT_FN (BUILT_IN_LLROUND): - CASE_FLT_FN (BUILT_IN_LROUND): - CASE_FLT_FN (BUILT_IN_ROUND): - CASE_FLT_FN (BUILT_IN_SIN): - CASE_FLT_FN (BUILT_IN_SINH): - CASE_FLT_FN (BUILT_IN_TAN): - CASE_FLT_FN (BUILT_IN_TANH): - CASE_FLT_FN (BUILT_IN_TRUNC): +negate_mathfn_p (combined_fn fn) +{ + switch (fn) + { + CASE_CFN_ASIN: + CASE_CFN_ASINH: + CASE_CFN_ATAN: + CASE_CFN_ATANH: + CASE_CFN_CASIN: + CASE_CFN_CASINH: + CASE_CFN_CATAN: + CASE_CFN_CATANH: + CASE_CFN_CBRT: + CASE_CFN_CPROJ: + CASE_CFN_CSIN: + CASE_CFN_CSINH: + CASE_CFN_CTAN: + CASE_CFN_CTANH: + CASE_CFN_ERF: + CASE_CFN_LLROUND: + CASE_CFN_LROUND: + CASE_CFN_ROUND: + CASE_CFN_SIN: + CASE_CFN_SINH: + CASE_CFN_TAN: + CASE_CFN_TANH: + CASE_CFN_TRUNC: return true; =20 - CASE_FLT_FN (BUILT_IN_LLRINT): - CASE_FLT_FN (BUILT_IN_LRINT): - CASE_FLT_FN (BUILT_IN_NEARBYINT): - CASE_FLT_FN (BUILT_IN_RINT): + CASE_CFN_LLRINT: + CASE_CFN_LRINT: + CASE_CFN_NEARBYINT: + CASE_CFN_RINT: return !flag_rounding_math; =20 default: @@ -506,7 +507,7 @@ negate_expr_p (tree t) =20 case CALL_EXPR: /* Negate -f(x) as f(-x). */ - if (negate_mathfn_p (builtin_mathfn_code (t))) + if (negate_mathfn_p (get_call_combined_fn (t))) return negate_expr_p (CALL_EXPR_ARG (t, 0)); break; =20 @@ -693,7 +694,7 @@ fold_negate_expr (location_t loc, tree t) =20 case CALL_EXPR: /* Negate -f(x) as f(-x). */ - if (negate_mathfn_p (builtin_mathfn_code (t)) + if (negate_mathfn_p (get_call_combined_fn (t)) && negate_expr_p (CALL_EXPR_ARG (t, 0))) { tree fndecl, arg; @@ -12905,91 +12906,90 @@ tree_single_nonnegative_warnv_p (tree t, bool *st= rict_overflow_p, int depth) *STRICT_OVERFLOW_P. DEPTH is the current nesting depth of the query. = */ =20 bool -tree_call_nonnegative_warnv_p (tree type, tree fndecl, tree arg0, tree arg= 1, +tree_call_nonnegative_warnv_p (tree type, combined_fn fn, tree arg0, tree = arg1, bool *strict_overflow_p, int depth) { - if (fndecl && DECL_BUILT_IN_CLASS (fndecl) =3D=3D BUILT_IN_NORMAL) - switch (DECL_FUNCTION_CODE (fndecl)) - { - CASE_FLT_FN (BUILT_IN_ACOS): - CASE_FLT_FN (BUILT_IN_ACOSH): - CASE_FLT_FN (BUILT_IN_CABS): - CASE_FLT_FN (BUILT_IN_COSH): - CASE_FLT_FN (BUILT_IN_ERFC): - CASE_FLT_FN (BUILT_IN_EXP): - CASE_FLT_FN (BUILT_IN_EXP10): - CASE_FLT_FN (BUILT_IN_EXP2): - CASE_FLT_FN (BUILT_IN_FABS): - CASE_FLT_FN (BUILT_IN_FDIM): - CASE_FLT_FN (BUILT_IN_HYPOT): - CASE_FLT_FN (BUILT_IN_POW10): - CASE_INT_FN (BUILT_IN_FFS): - CASE_INT_FN (BUILT_IN_PARITY): - CASE_INT_FN (BUILT_IN_POPCOUNT): - CASE_INT_FN (BUILT_IN_CLZ): - CASE_INT_FN (BUILT_IN_CLRSB): - case BUILT_IN_BSWAP32: - case BUILT_IN_BSWAP64: + switch (fn) + { + CASE_CFN_ACOS: + CASE_CFN_ACOSH: + CASE_CFN_CABS: + CASE_CFN_COSH: + CASE_CFN_ERFC: + CASE_CFN_EXP: + CASE_CFN_EXP10: + CASE_CFN_EXP2: + CASE_CFN_FABS: + CASE_CFN_FDIM: + CASE_CFN_HYPOT: + CASE_CFN_POW10: + CASE_CFN_FFS: + CASE_CFN_PARITY: + CASE_CFN_POPCOUNT: + CASE_CFN_CLZ: + CASE_CFN_CLRSB: + case CFN_BUILT_IN_BSWAP32: + case CFN_BUILT_IN_BSWAP64: /* Always true. */ return true; =20 - CASE_FLT_FN (BUILT_IN_SQRT): + CASE_CFN_SQRT: /* sqrt(-0.0) is -0.0. */ if (!HONOR_SIGNED_ZEROS (element_mode (type))) return true; return RECURSE (arg0); =20 - CASE_FLT_FN (BUILT_IN_ASINH): - CASE_FLT_FN (BUILT_IN_ATAN): - CASE_FLT_FN (BUILT_IN_ATANH): - CASE_FLT_FN (BUILT_IN_CBRT): - CASE_FLT_FN (BUILT_IN_CEIL): - CASE_FLT_FN (BUILT_IN_ERF): - CASE_FLT_FN (BUILT_IN_EXPM1): - CASE_FLT_FN (BUILT_IN_FLOOR): - CASE_FLT_FN (BUILT_IN_FMOD): - CASE_FLT_FN (BUILT_IN_FREXP): - CASE_FLT_FN (BUILT_IN_ICEIL): - CASE_FLT_FN (BUILT_IN_IFLOOR): - CASE_FLT_FN (BUILT_IN_IRINT): - CASE_FLT_FN (BUILT_IN_IROUND): - CASE_FLT_FN (BUILT_IN_LCEIL): - CASE_FLT_FN (BUILT_IN_LDEXP): - CASE_FLT_FN (BUILT_IN_LFLOOR): - CASE_FLT_FN (BUILT_IN_LLCEIL): - CASE_FLT_FN (BUILT_IN_LLFLOOR): - CASE_FLT_FN (BUILT_IN_LLRINT): - CASE_FLT_FN (BUILT_IN_LLROUND): - CASE_FLT_FN (BUILT_IN_LRINT): - CASE_FLT_FN (BUILT_IN_LROUND): - CASE_FLT_FN (BUILT_IN_MODF): - CASE_FLT_FN (BUILT_IN_NEARBYINT): - CASE_FLT_FN (BUILT_IN_RINT): - CASE_FLT_FN (BUILT_IN_ROUND): - CASE_FLT_FN (BUILT_IN_SCALB): - CASE_FLT_FN (BUILT_IN_SCALBLN): - CASE_FLT_FN (BUILT_IN_SCALBN): - CASE_FLT_FN (BUILT_IN_SIGNBIT): - CASE_FLT_FN (BUILT_IN_SIGNIFICAND): - CASE_FLT_FN (BUILT_IN_SINH): - CASE_FLT_FN (BUILT_IN_TANH): - CASE_FLT_FN (BUILT_IN_TRUNC): + CASE_CFN_ASINH: + CASE_CFN_ATAN: + CASE_CFN_ATANH: + CASE_CFN_CBRT: + CASE_CFN_CEIL: + CASE_CFN_ERF: + CASE_CFN_EXPM1: + CASE_CFN_FLOOR: + CASE_CFN_FMOD: + CASE_CFN_FREXP: + CASE_CFN_ICEIL: + CASE_CFN_IFLOOR: + CASE_CFN_IRINT: + CASE_CFN_IROUND: + CASE_CFN_LCEIL: + CASE_CFN_LDEXP: + CASE_CFN_LFLOOR: + CASE_CFN_LLCEIL: + CASE_CFN_LLFLOOR: + CASE_CFN_LLRINT: + CASE_CFN_LLROUND: + CASE_CFN_LRINT: + CASE_CFN_LROUND: + CASE_CFN_MODF: + CASE_CFN_NEARBYINT: + CASE_CFN_RINT: + CASE_CFN_ROUND: + CASE_CFN_SCALB: + CASE_CFN_SCALBLN: + CASE_CFN_SCALBN: + CASE_CFN_SIGNBIT: + CASE_CFN_SIGNIFICAND: + CASE_CFN_SINH: + CASE_CFN_TANH: + CASE_CFN_TRUNC: /* True if the 1st argument is nonnegative. */ return RECURSE (arg0); =20 - CASE_FLT_FN (BUILT_IN_FMAX): + CASE_CFN_FMAX: /* True if the 1st OR 2nd arguments are nonnegative. */ return RECURSE (arg0) || RECURSE (arg1); =20 - CASE_FLT_FN (BUILT_IN_FMIN): + CASE_CFN_FMIN: /* True if the 1st AND 2nd arguments are nonnegative. */ return RECURSE (arg0) && RECURSE (arg1); =20 - CASE_FLT_FN (BUILT_IN_COPYSIGN): + CASE_CFN_COPYSIGN: /* True if the 2nd argument is nonnegative. */ return RECURSE (arg1); =20 - CASE_FLT_FN (BUILT_IN_POWI): + CASE_CFN_POWI: /* True if the 1st argument is nonnegative or the second argument is an even integer. */ if (TREE_CODE (arg1) =3D=3D INTEGER_CST @@ -12997,7 +12997,7 @@ tree_call_nonnegative_warnv_p (tree type, tree fnde= cl, tree arg0, tree arg1, return true; return RECURSE (arg0); =20 - CASE_FLT_FN (BUILT_IN_POW): + CASE_CFN_POW: /* True if the 1st argument is nonnegative or the second argument is an even integer valued real. */ if (TREE_CODE (arg1) =3D=3D REAL_CST) @@ -13074,7 +13074,7 @@ tree_invalid_nonnegative_warnv_p (tree t, bool *str= ict_overflow_p, int depth) tree arg1 =3D call_expr_nargs (t) > 1 ? CALL_EXPR_ARG (t, 1) : NULL_TREE; =20 return tree_call_nonnegative_warnv_p (TREE_TYPE (t), - get_callee_fndecl (t), + get_call_combined_fn (t), arg0, arg1, strict_overflow_p, depth); @@ -13477,21 +13477,20 @@ integer_valued_real_binary_p (tree_code code, tre= e op0, tree op1, int depth) DEPTH is the current nesting depth of the query. */ =20 bool -integer_valued_real_call_p (tree fndecl, tree arg0, tree arg1, int depth) +integer_valued_real_call_p (combined_fn fn, tree arg0, tree arg1, int dept= h) { - if (fndecl && DECL_BUILT_IN_CLASS (fndecl) =3D=3D BUILT_IN_NORMAL) - switch (DECL_FUNCTION_CODE (fndecl)) + switch (fn) { - CASE_FLT_FN (BUILT_IN_CEIL): - CASE_FLT_FN (BUILT_IN_FLOOR): - CASE_FLT_FN (BUILT_IN_NEARBYINT): - CASE_FLT_FN (BUILT_IN_RINT): - CASE_FLT_FN (BUILT_IN_ROUND): - CASE_FLT_FN (BUILT_IN_TRUNC): + CASE_CFN_CEIL: + CASE_CFN_FLOOR: + CASE_CFN_NEARBYINT: + CASE_CFN_RINT: + CASE_CFN_ROUND: + CASE_CFN_TRUNC: return true; =20 - CASE_FLT_FN (BUILT_IN_FMIN): - CASE_FLT_FN (BUILT_IN_FMAX): + CASE_CFN_FMIN: + CASE_CFN_FMAX: return RECURSE (arg0) && RECURSE (arg1); =20 default: @@ -13607,7 +13606,7 @@ integer_valued_real_p (tree t, int depth) tree arg1 =3D (call_expr_nargs (t) > 1 ? CALL_EXPR_ARG (t, 1) : NULL_TREE); - return integer_valued_real_call_p (get_callee_fndecl (t), + return integer_valued_real_call_p (get_call_combined_fn (t), arg0, arg1, depth); } =20 diff --git a/gcc/fold-const.h b/gcc/fold-const.h index 94a21b7..7741802 100644 --- a/gcc/fold-const.h +++ b/gcc/fold-const.h @@ -137,12 +137,12 @@ extern bool tree_unary_nonnegative_warnv_p (enum tree= _code, tree, tree, extern bool tree_binary_nonnegative_warnv_p (enum tree_code, tree, tree, t= ree, bool *, int); extern bool tree_single_nonnegative_warnv_p (tree, bool *, int); -extern bool tree_call_nonnegative_warnv_p (tree, tree, tree, tree, bool *, - int); +extern bool tree_call_nonnegative_warnv_p (tree, combined_fn, tree, tree, + bool *, int); =20 extern bool integer_valued_real_unary_p (tree_code, tree, int); extern bool integer_valued_real_binary_p (tree_code, tree, tree, int); -extern bool integer_valued_real_call_p (tree, tree, tree, int); +extern bool integer_valued_real_call_p (combined_fn, tree, tree, int); extern bool integer_valued_real_single_p (tree, int); extern bool integer_valued_real_p (tree, int =3D 0); =20 @@ -179,7 +179,7 @@ extern tree sign_bit_p (tree, const_tree); extern tree exact_inverse (tree, tree); extern tree const_unop (enum tree_code, tree, tree); extern tree const_binop (enum tree_code, tree, tree, tree); -extern bool negate_mathfn_p (enum built_in_function); +extern bool negate_mathfn_p (combined_fn); extern const char *c_getstr (tree); =20 /* Return OFF converted to a pointer offset type suitable as offset for diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index 45840af..b72ea00 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -6197,7 +6197,7 @@ gimple_call_nonnegative_warnv_p (gimple *stmt, bool *= strict_overflow_p, gimple_call_arg (stmt, 1) : NULL_TREE; =20 return tree_call_nonnegative_warnv_p (gimple_expr_type (stmt), - gimple_call_fndecl (stmt), + gimple_call_combined_fn (stmt), arg0, arg1, strict_overflow_p, depth); @@ -6290,7 +6290,7 @@ gimple_call_integer_valued_real_p (gimple *stmt, int = depth) tree arg1 =3D (gimple_call_num_args (stmt) > 1 ? gimple_call_arg (stmt, 1) : NULL_TREE); - return integer_valued_real_call_p (gimple_call_fndecl (stmt), + return integer_valued_real_call_p (gimple_call_combined_fn (stmt), arg0, arg1, depth); } =20 diff --git a/gcc/gimple-ssa-backprop.c b/gcc/gimple-ssa-backprop.c index 91a3c79..d573651 100644 --- a/gcc/gimple-ssa-backprop.c +++ b/gcc/gimple-ssa-backprop.c @@ -102,6 +102,7 @@ along with GCC; see the file COPYING3. If not see #include "gimple-fold.h" #include "alloc-pool.h" #include "tree-hash-traits.h" +#include "case-cfn-macros.h" =20 namespace { =20 @@ -337,26 +338,29 @@ backprop::pop_from_worklist () void backprop::process_builtin_call_use (gcall *call, tree rhs, usage_info *inf= o) { - enum built_in_function fn =3D DECL_FUNCTION_CODE (gimple_call_fndecl (ca= ll)); + combined_fn fn =3D gimple_call_combined_fn (call); tree lhs =3D gimple_call_lhs (call); switch (fn) { - CASE_FLT_FN (BUILT_IN_COS): - CASE_FLT_FN (BUILT_IN_COSH): - CASE_FLT_FN (BUILT_IN_CCOS): - CASE_FLT_FN (BUILT_IN_CCOSH): - CASE_FLT_FN (BUILT_IN_HYPOT): + case CFN_LAST: + break; + + CASE_CFN_COS: + CASE_CFN_COSH: + CASE_CFN_CCOS: + CASE_CFN_CCOSH: + CASE_CFN_HYPOT: /* The signs of all inputs are ignored. */ info->flags.ignore_sign =3D true; break; =20 - CASE_FLT_FN (BUILT_IN_COPYSIGN): + CASE_CFN_COPYSIGN: /* The sign of the first input is ignored. */ if (rhs !=3D gimple_call_arg (call, 1)) info->flags.ignore_sign =3D true; break; =20 - CASE_FLT_FN (BUILT_IN_POW): + CASE_CFN_POW: { /* The sign of the first input is ignored as long as the second input is an even real. */ @@ -369,7 +373,7 @@ backprop::process_builtin_call_use (gcall *call, tree r= hs, usage_info *info) break; } =20 - CASE_FLT_FN (BUILT_IN_FMA): + CASE_CFN_FMA: /* In X * X + Y, where Y is distinct from X, the sign of X doesn't matter. */ if (gimple_call_arg (call, 0) =3D=3D rhs @@ -472,10 +476,7 @@ backprop::process_use (gimple *stmt, tree rhs, usage_i= nfo *info) } =20 if (gcall *call =3D dyn_cast (stmt)) - { - if (gimple_call_builtin_p (call, BUILT_IN_NORMAL)) process_builtin_call_use (call, rhs, info); - } else if (gassign *assign =3D dyn_cast (stmt)) process_assign_use (assign, rhs, info); else if (gphi *phi =3D dyn_cast (stmt)) @@ -686,17 +687,14 @@ strip_sign_op_1 (tree rhs) break; } else if (gcall *call =3D dyn_cast (def_stmt)) + switch (gimple_call_combined_fn (call)) { - if (gimple_call_builtin_p (call, BUILT_IN_NORMAL)) - switch (DECL_FUNCTION_CODE (gimple_call_fndecl (call))) - { - CASE_FLT_FN (BUILT_IN_COPYSIGN): + CASE_CFN_COPYSIGN: return gimple_call_arg (call, 0); =20 default: break; } - } =20 return NULL_TREE; } @@ -758,11 +756,10 @@ backprop::complete_change (gimple *stmt) void backprop::optimize_builtin_call (gcall *call, tree lhs, const usage_info *= info) { - tree fndecl =3D gimple_call_fndecl (call); - enum built_in_function fn =3D DECL_FUNCTION_CODE (fndecl); /* If we have an f such that -f(x) =3D f(-x), and if the sign of the res= ult doesn't matter, strip any sign operations from the input. */ - if (info->flags.ignore_sign && negate_mathfn_p (fn)) + if (info->flags.ignore_sign + && negate_mathfn_p (gimple_call_combined_fn (call))) { tree new_arg =3D strip_sign_op (gimple_call_arg (call, 0)); if (new_arg) @@ -889,10 +886,7 @@ backprop::execute () tree var =3D m_vars[i].first; gimple *stmt =3D SSA_NAME_DEF_STMT (var); if (gcall *call =3D dyn_cast (stmt)) - { - if (gimple_call_builtin_p (call, BUILT_IN_NORMAL)) optimize_builtin_call (call, var, info); - } else if (gassign *assign =3D dyn_cast (stmt)) optimize_assign (assign, var, info); else if (gphi *phi =3D dyn_cast (stmt)) --=-=-=--