re PR tree-optimization/79201 (missed optimization: sinking doesn't handle calls, swap PRE and sinking)

2017-04-25  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/79201
	* tree-ssa-sink.c (statement_sink_location): Handle calls.

	* gcc.dg/tree-ssa/ssa-sink-16.c: New testcase.
	* gcc.target/i386/pr22152.c: Disable sinking.

From-SVN: r247159
This commit is contained in:
Richard Biener 2017-04-25 09:26:37 +00:00 committed by Richard Biener
parent bfda9ccde6
commit 2700fbd655
5 changed files with 36 additions and 7 deletions

View File

@ -1,3 +1,8 @@
2017-04-25 Richard Biener <rguenther@suse.de>
PR tree-optimization/79201
* tree-ssa-sink.c (statement_sink_location): Handle calls.
2017-04-25 Andreas Krebbel <krebbel@linux.vnet.ibm.com>
PR target/80464

View File

@ -1,3 +1,9 @@
2017-04-25 Richard Biener <rguenther@suse.de>
PR tree-optimization/79201
* gcc.dg/tree-ssa/ssa-sink-16.c: New testcase.
* gcc.target/i386/pr22152.c: Disable sinking.
2017-04-25 Andreas Krebbel <krebbel@linux.vnet.ibm.com>
PR target/80464

View File

@ -0,0 +1,14 @@
/* { dg-do compile } */
/* Note PRE rotates the loop and blocks the sinking opportunity. */
/* { dg-options "-O2 -fno-tree-pre -fdump-tree-sink -fdump-tree-optimized" } */
int f(int n)
{
int i,j=0;
for (i = 0; i < 31; i++)
j = __builtin_ffs(i);
return j;
}
/* { dg-final { scan-tree-dump "Sinking j_. = __builtin_ffs" "sink" } } */
/* { dg-final { scan-tree-dump "return 2;" "optimized" } } */

View File

@ -1,5 +1,5 @@
/* { dg-do compile } */
/* { dg-options "-O2 -msse2 -mtune=core2" } */
/* { dg-options "-O2 -fno-tree-sink -msse2 -mtune=core2" } */
/* { dg-additional-options "-mno-vect8-ret-in-mem" { target *-*-vxworks* } } */
/* { dg-additional-options "-mabi=sysv" { target x86_64-*-mingw* } } */

View File

@ -256,8 +256,12 @@ statement_sink_location (gimple *stmt, basic_block frombb,
*zero_uses_p = false;
/* We only can sink assignments. */
if (!is_gimple_assign (stmt))
/* We only can sink assignments and non-looping const/pure calls. */
int cf;
if (!is_gimple_assign (stmt)
&& (!is_gimple_call (stmt)
|| !((cf = gimple_call_flags (stmt)) & (ECF_CONST|ECF_PURE))
|| (cf & ECF_LOOPING_CONST_OR_PURE)))
return false;
/* We only can sink stmts with a single definition. */
@ -291,7 +295,7 @@ statement_sink_location (gimple *stmt, basic_block frombb,
if (stmt_ends_bb_p (stmt)
|| gimple_has_side_effects (stmt)
|| (cfun->has_local_explicit_reg_vars
&& TYPE_MODE (TREE_TYPE (gimple_assign_lhs (stmt))) == BLKmode))
&& TYPE_MODE (TREE_TYPE (gimple_get_lhs (stmt))) == BLKmode))
return false;
/* Return if there are no immediate uses of this stmt. */
@ -323,15 +327,15 @@ statement_sink_location (gimple *stmt, basic_block frombb,
/* A killing definition is not a use. */
if ((gimple_has_lhs (use_stmt)
&& operand_equal_p (gimple_assign_lhs (stmt),
&& operand_equal_p (gimple_get_lhs (stmt),
gimple_get_lhs (use_stmt), 0))
|| stmt_kills_ref_p (use_stmt, gimple_assign_lhs (stmt)))
|| stmt_kills_ref_p (use_stmt, gimple_get_lhs (stmt)))
{
/* If use_stmt is or might be a nop assignment then USE_STMT
acts as a use as well as definition. */
if (stmt != use_stmt
&& ref_maybe_used_by_stmt_p (use_stmt,
gimple_assign_lhs (stmt)))
gimple_get_lhs (stmt)))
return false;
continue;
}