Commit df11b2ea by Bill Schmidt Committed by William Schmidt

gimple-ssa-strength-reduction.c (uses_consumed_by_stmt): New function.

[gcc]

2016-06-26  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>

	* gimple-ssa-strength-reduction.c (uses_consumed_by_stmt): New
	function.
	(find_basis_for_candidate): Call uses_consumed_by_stmt rather than
	has_single_use.
	(slsr_process_phi): Likewise.
	(replace_uncond_cands_and_profitable_phis): Don't replace a
	multiply candidate with a stride of 1 (copy or cast).
	(phi_incr_cost): Call uses_consumed_by_stmt rather than
	has_single_use.
	(lowest_cost_path): Likewise.
	(total_savings): Likewise.

[gcc/testsuite]

2016-06-26  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>

	* gcc.dg/tree-ssa/slsr-35.c: Remove -fno-code-hoisting workaround.
	* gcc.dg/tree-ssa/slsr-36.c: Likewise.

From-SVN: r249648
parent fa7ccca0
2016-06-26 Bill Schmidt <wschmidt@linux.vnet.ibm.com>
* gimple-ssa-strength-reduction.c (uses_consumed_by_stmt): New
function.
(find_basis_for_candidate): Call uses_consumed_by_stmt rather than
has_single_use.
(slsr_process_phi): Likewise.
(replace_uncond_cands_and_profitable_phis): Don't replace a
multiply candidate with a stride of 1 (copy or cast).
(phi_incr_cost): Call uses_consumed_by_stmt rather than
has_single_use.
(lowest_cost_path): Likewise.
(total_savings): Likewise.
2017-06-26 Richard Biener <rguenther@suse.de> 2017-06-26 Richard Biener <rguenther@suse.de>
PR target/81175 PR target/81175
......
...@@ -482,6 +482,36 @@ find_phi_def (tree base) ...@@ -482,6 +482,36 @@ find_phi_def (tree base)
return c->cand_num; return c->cand_num;
} }
/* Determine whether all uses of NAME are directly or indirectly
used by STMT. That is, we want to know whether if STMT goes
dead, the definition of NAME also goes dead. */
static bool
uses_consumed_by_stmt (tree name, gimple *stmt, unsigned recurse = 0)
{
gimple *use_stmt;
imm_use_iterator iter;
bool retval = true;
FOR_EACH_IMM_USE_STMT (use_stmt, iter, name)
{
if (use_stmt == stmt || is_gimple_debug (use_stmt))
continue;
if (!is_gimple_assign (use_stmt)
|| !gimple_get_lhs (use_stmt)
|| !is_gimple_reg (gimple_get_lhs (use_stmt))
|| recurse >= 10
|| !uses_consumed_by_stmt (gimple_get_lhs (use_stmt), stmt,
recurse + 1))
{
retval = false;
BREAK_FROM_IMM_USE_STMT (iter);
}
}
return retval;
}
/* Helper routine for find_basis_for_candidate. May be called twice: /* Helper routine for find_basis_for_candidate. May be called twice:
once for the candidate's base expr, and optionally again either for once for the candidate's base expr, and optionally again either for
the candidate's phi definition or for a CAND_REF's alternative base the candidate's phi definition or for a CAND_REF's alternative base
...@@ -558,7 +588,8 @@ find_basis_for_candidate (slsr_cand_t c) ...@@ -558,7 +588,8 @@ find_basis_for_candidate (slsr_cand_t c)
/* If we found a hidden basis, estimate additional dead-code /* If we found a hidden basis, estimate additional dead-code
savings if the phi and its feeding statements can be removed. */ savings if the phi and its feeding statements can be removed. */
if (basis && has_single_use (gimple_phi_result (phi_cand->cand_stmt))) tree feeding_var = gimple_phi_result (phi_cand->cand_stmt);
if (basis && uses_consumed_by_stmt (feeding_var, c->cand_stmt))
c->dead_savings += phi_cand->dead_savings; c->dead_savings += phi_cand->dead_savings;
} }
} }
...@@ -789,7 +820,7 @@ slsr_process_phi (gphi *phi, bool speed) ...@@ -789,7 +820,7 @@ slsr_process_phi (gphi *phi, bool speed)
/* Gather potential dead code savings if the phi statement /* Gather potential dead code savings if the phi statement
can be removed later on. */ can be removed later on. */
if (has_single_use (arg)) if (uses_consumed_by_stmt (arg, phi))
{ {
if (gimple_code (arg_stmt) == GIMPLE_PHI) if (gimple_code (arg_stmt) == GIMPLE_PHI)
savings += arg_cand->dead_savings; savings += arg_cand->dead_savings;
...@@ -2479,7 +2510,9 @@ replace_uncond_cands_and_profitable_phis (slsr_cand_t c) ...@@ -2479,7 +2510,9 @@ replace_uncond_cands_and_profitable_phis (slsr_cand_t c)
{ {
if (phi_dependent_cand_p (c)) if (phi_dependent_cand_p (c))
{ {
if (c->kind == CAND_MULT) /* A multiply candidate with a stride of 1 is just an artifice
of a copy or cast; there is no value in replacing it. */
if (c->kind == CAND_MULT && wi::to_widest (c->stride) != 1)
{ {
/* A candidate dependent upon a phi will replace a multiply by /* A candidate dependent upon a phi will replace a multiply by
a constant with an add, and will insert at most one add for a constant with an add, and will insert at most one add for
...@@ -2725,8 +2758,9 @@ phi_incr_cost (slsr_cand_t c, const widest_int &incr, gimple *phi, ...@@ -2725,8 +2758,9 @@ phi_incr_cost (slsr_cand_t c, const widest_int &incr, gimple *phi,
if (gimple_code (arg_def) == GIMPLE_PHI) if (gimple_code (arg_def) == GIMPLE_PHI)
{ {
int feeding_savings = 0; int feeding_savings = 0;
tree feeding_var = gimple_phi_result (arg_def);
cost += phi_incr_cost (c, incr, arg_def, &feeding_savings); cost += phi_incr_cost (c, incr, arg_def, &feeding_savings);
if (has_single_use (gimple_phi_result (arg_def))) if (uses_consumed_by_stmt (feeding_var, phi))
*savings += feeding_savings; *savings += feeding_savings;
} }
else else
...@@ -2739,7 +2773,7 @@ phi_incr_cost (slsr_cand_t c, const widest_int &incr, gimple *phi, ...@@ -2739,7 +2773,7 @@ phi_incr_cost (slsr_cand_t c, const widest_int &incr, gimple *phi,
tree basis_lhs = gimple_assign_lhs (basis->cand_stmt); tree basis_lhs = gimple_assign_lhs (basis->cand_stmt);
tree lhs = gimple_assign_lhs (arg_cand->cand_stmt); tree lhs = gimple_assign_lhs (arg_cand->cand_stmt);
cost += add_cost (true, TYPE_MODE (TREE_TYPE (basis_lhs))); cost += add_cost (true, TYPE_MODE (TREE_TYPE (basis_lhs)));
if (has_single_use (lhs)) if (uses_consumed_by_stmt (lhs, phi))
*savings += stmt_cost (arg_cand->cand_stmt, true); *savings += stmt_cost (arg_cand->cand_stmt, true);
} }
} }
...@@ -2816,7 +2850,7 @@ lowest_cost_path (int cost_in, int repl_savings, slsr_cand_t c, ...@@ -2816,7 +2850,7 @@ lowest_cost_path (int cost_in, int repl_savings, slsr_cand_t c,
gimple *phi = lookup_cand (c->def_phi)->cand_stmt; gimple *phi = lookup_cand (c->def_phi)->cand_stmt;
local_cost += phi_incr_cost (c, incr, phi, &savings); local_cost += phi_incr_cost (c, incr, phi, &savings);
if (has_single_use (gimple_phi_result (phi))) if (uses_consumed_by_stmt (gimple_phi_result (phi), c->cand_stmt))
local_cost -= savings; local_cost -= savings;
} }
...@@ -2860,7 +2894,7 @@ total_savings (int repl_savings, slsr_cand_t c, const widest_int &incr, ...@@ -2860,7 +2894,7 @@ total_savings (int repl_savings, slsr_cand_t c, const widest_int &incr,
gimple *phi = lookup_cand (c->def_phi)->cand_stmt; gimple *phi = lookup_cand (c->def_phi)->cand_stmt;
savings -= phi_incr_cost (c, incr, phi, &phi_savings); savings -= phi_incr_cost (c, incr, phi, &phi_savings);
if (has_single_use (gimple_phi_result (phi))) if (uses_consumed_by_stmt (gimple_phi_result (phi), c->cand_stmt))
savings += phi_savings; savings += phi_savings;
} }
......
2016-06-26 Bill Schmidt <wschmidt@linux.vnet.ibm.com>
* gcc.dg/tree-ssa/slsr-35.c: Remove -fno-code-hoisting workaround.
* gcc.dg/tree-ssa/slsr-36.c: Likewise.
2017-06-26 Renlin Li <renlin.li@arm.com> 2017-06-26 Renlin Li <renlin.li@arm.com>
Szabolcs Nagy <szabolcs.nagy@arm.com> Szabolcs Nagy <szabolcs.nagy@arm.com>
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
phi has an argument which is a parameter. */ phi has an argument which is a parameter. */
/* { dg-do compile } */ /* { dg-do compile } */
/* { dg-options "-O3 -fno-code-hoisting -fdump-tree-optimized" } */ /* { dg-options "-O3 -fdump-tree-optimized" } */
int int
f (int c, int i) f (int c, int i)
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
phi has an argument which is a parameter. */ phi has an argument which is a parameter. */
/* { dg-do compile } */ /* { dg-do compile } */
/* { dg-options "-O3 -fno-code-hoisting -fdump-tree-optimized" } */ /* { dg-options "-O3 -fdump-tree-optimized" } */
int int
f (int s, int c, int i) f (int s, int c, int i)
......
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