Commit 1d9da71f by Richard Sandiford Committed by Richard Sandiford

Make more use of combined_fn

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.

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.

From-SVN: r230478
parent d7ebef06
2015-11-17 Richard Sandiford <richard.sandiford@arm.com>
* 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.
2015-11-17 Richard Sandiford <richard.sandiford@arm.com>
* fold-const-call.h (fold_const_call): Replace built_in_function
arguments with combined_fn arguments.
* fold-const-call.c: Include case-cfn-macros.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, tree,
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);
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 = 0);
......@@ -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);
/* Return OFF converted to a pointer offset type suitable as offset for
......
......@@ -6202,7 +6202,7 @@ gimple_call_nonnegative_warnv_p (gimple *stmt, bool *strict_overflow_p,
gimple_call_arg (stmt, 1) : NULL_TREE;
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);
......@@ -6295,7 +6295,7 @@ gimple_call_integer_valued_real_p (gimple *stmt, int depth)
tree arg1 = (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);
}
......
......@@ -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"
namespace {
......@@ -337,26 +338,29 @@ backprop::pop_from_worklist ()
void
backprop::process_builtin_call_use (gcall *call, tree rhs, usage_info *info)
{
enum built_in_function fn = DECL_FUNCTION_CODE (gimple_call_fndecl (call));
combined_fn fn = gimple_call_combined_fn (call);
tree lhs = 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 = true;
break;
CASE_FLT_FN (BUILT_IN_COPYSIGN):
CASE_CFN_COPYSIGN:
/* The sign of the first input is ignored. */
if (rhs != gimple_call_arg (call, 1))
info->flags.ignore_sign = true;
break;
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 rhs, usage_info *info)
break;
}
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) == rhs
......@@ -472,10 +476,7 @@ backprop::process_use (gimple *stmt, tree rhs, usage_info *info)
}
if (gcall *call = dyn_cast <gcall *> (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 = dyn_cast <gassign *> (stmt))
process_assign_use (assign, rhs, info);
else if (gphi *phi = dyn_cast <gphi *> (stmt))
......@@ -686,17 +687,14 @@ strip_sign_op_1 (tree rhs)
break;
}
else if (gcall *call = dyn_cast <gcall *> (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;
}
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 = gimple_call_fndecl (call);
enum built_in_function fn = DECL_FUNCTION_CODE (fndecl);
/* If we have an f such that -f(x) = f(-x), and if the sign of the result
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 = strip_sign_op (gimple_call_arg (call, 0));
if (new_arg)
......@@ -889,10 +886,7 @@ backprop::execute ()
tree var = m_vars[i].first;
gimple *stmt = SSA_NAME_DEF_STMT (var);
if (gcall *call = dyn_cast <gcall *> (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 = dyn_cast <gassign *> (stmt))
optimize_assign (assign, var, info);
else if (gphi *phi = dyn_cast <gphi *> (stmt))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment