diff options
author | Richard Biener <rguenther@suse.de> | 2017-01-13 08:11:01 +0000 |
---|---|---|
committer | Richard Biener <rguenth@gcc.gnu.org> | 2017-01-13 08:11:01 +0000 |
commit | 10b70b8e5eb8d4b5ab175785366cfc6cbe837390 (patch) | |
tree | caf56ce1cf53d62119b36465ce668fc8202fd10d | |
parent | 53b586f27080c634a8c2a85d1d0619d1aa7e997c (diff) | |
download | gcc-10b70b8e5eb8d4b5ab175785366cfc6cbe837390.zip gcc-10b70b8e5eb8d4b5ab175785366cfc6cbe837390.tar.gz gcc-10b70b8e5eb8d4b5ab175785366cfc6cbe837390.tar.bz2 |
re PR tree-optimization/77283 (Revision 238005 disables loop unrolling)
2017-01-13 Richard Biener <rguenther@suse.de>
PR tree-optimization/77283
* gimple-ssa-split-paths.c: Include gimple-ssa.h, tree-phinodes.h
and ssa-iterators.h.
(is_feasible_trace): Implement a cost model based on joiner
PHI node uses.
* gcc.dg/tree-ssa/split-path-7.c: Adjust.
* gcc.dg/tree-ssa/split-path-8.c: New testcase.
* gcc.dg/tree-ssa/split-path-9.c: Likewise.
From-SVN: r244392
-rw-r--r-- | gcc/gimple-ssa-split-paths.c | 55 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/split-path-7.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/split-path-8.c | 14 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/split-path-9.c | 17 |
5 files changed, 94 insertions, 1 deletions
diff --git a/gcc/gimple-ssa-split-paths.c b/gcc/gimple-ssa-split-paths.c index ef6c720..f1bf7ec 100644 --- a/gcc/gimple-ssa-split-paths.c +++ b/gcc/gimple-ssa-split-paths.c @@ -32,6 +32,9 @@ along with GCC; see the file COPYING3. If not see #include "tracer.h" #include "predict.h" #include "params.h" +#include "gimple-ssa.h" +#include "tree-phinodes.h" +#include "ssa-iterators.h" /* Given LATCH, the latch block in a loop, see if the shape of the path reaching LATCH is suitable for being split by duplication. @@ -200,6 +203,58 @@ is_feasible_trace (basic_block bb) } } + /* If the joiner has no PHIs with useful uses there is zero chance + of CSE/DCE/jump-threading possibilities exposed by duplicating it. */ + bool found_useful_phi = false; + for (gphi_iterator si = gsi_start_phis (bb); ! gsi_end_p (si); + gsi_next (&si)) + { + gphi *phi = si.phi (); + use_operand_p use_p; + imm_use_iterator iter; + FOR_EACH_IMM_USE_FAST (use_p, iter, gimple_phi_result (phi)) + { + gimple *stmt = USE_STMT (use_p); + if (is_gimple_debug (stmt)) + continue; + /* If there's a use in the joiner this might be a CSE/DCE + opportunity. */ + if (gimple_bb (stmt) == bb) + { + found_useful_phi = true; + break; + } + /* If the use is on a loop header PHI and on one path the + value is unchanged this might expose a jump threading + opportunity. */ + if (gimple_code (stmt) == GIMPLE_PHI + && gimple_bb (stmt) == bb->loop_father->header + /* But for memory the PHI alone isn't good enough. */ + && ! virtual_operand_p (gimple_phi_result (stmt))) + { + for (unsigned i = 0; i < gimple_phi_num_args (phi); ++i) + if (gimple_phi_arg_def (phi, i) == gimple_phi_result (stmt)) + { + found_useful_phi = true; + break; + } + if (found_useful_phi) + break; + } + } + if (found_useful_phi) + break; + } + if (! found_useful_phi) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, + "Block %d is a join that does not expose CSE/DCE/jump-thread " + "opportunities when duplicated.\n", + bb->index); + return false; + } + /* We may want something here which looks at dataflow and tries to guess if duplication of BB is likely to result in simplification of instructions in BB in either the original or the duplicate. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d8fa57c..4dc4fc1 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2017-01-13 Richard Biener <rguenther@suse.de> + + PR tree-optimization/77283 + * gcc.dg/tree-ssa/split-path-7.c: Adjust. + * gcc.dg/tree-ssa/split-path-8.c: New testcase. + * gcc.dg/tree-ssa/split-path-9.c: Likewise. + 2017-01-12 Sandra Loosemore <sandra@codesourcery.com> * gcc.dg/pr77862.c: Require fpic target. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/split-path-7.c b/gcc/testsuite/gcc.dg/tree-ssa/split-path-7.c index f14ab79..f80d306 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/split-path-7.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/split-path-7.c @@ -91,4 +91,4 @@ linit () } } } -/* { dg-final { scan-tree-dump-times "Duplicating join block" 2 "split-paths" } } */ +/* { dg-final { scan-tree-dump-times "Duplicating join block" 0 "split-paths" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/split-path-8.c b/gcc/testsuite/gcc.dg/tree-ssa/split-path-8.c new file mode 100644 index 0000000..fb54f5d --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/split-path-8.c @@ -0,0 +1,14 @@ +/* PR77283 */ +/* { dg-do compile } */ +/* { dg-options "-O3 -fdump-tree-split-paths-details" } */ + +void +foo (double *x, double *a, double *b, long n, double limit) +{ + long i; + for (i=0; i < n; i++) + if (a[i] < limit) + x[i] = b[i]; +} + +/* { dg-final { scan-tree-dump-times "Duplicating join block" 0 "split-paths" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/split-path-9.c b/gcc/testsuite/gcc.dg/tree-ssa/split-path-9.c new file mode 100644 index 0000000..bd4ee76 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/split-path-9.c @@ -0,0 +1,17 @@ +/* PR77366 */ +/* { dg-do compile } */ +/* { dg-options "-O3 -fdump-tree-split-paths-details" } */ + +void +foo(unsigned int size, unsigned int *state) +{ + unsigned int i; + + for(i = 0; i < size; i++) + { + if(*state & 1) + *state ^= 1; + } +} + +/* { dg-final { scan-tree-dump-times "Duplicating join block" 0 "split-paths" } } */ |