From 7699e88f68de2f5488ad260fdd35ee3a2b910014 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Fri, 24 Feb 2017 08:04:31 +0000 Subject: [PATCH] re PR tree-optimization/79389 (30% performance regression in SciMark2 MonteCarlo) 2017-02-24 Richard Biener PR tree-optimization/79389 * gimple-ssa-split-paths.c (is_feasible_trace): Verify more properly that a threading opportunity exists. Detect conditional copy/constant propagation opportunities. * gcc.dg/tree-ssa/split-path-10.c: New testcase. From-SVN: r245696 --- gcc/ChangeLog | 7 +++ gcc/gimple-ssa-split-paths.c | 49 ++++++++++++++++++- gcc/testsuite/ChangeLog | 5 ++ gcc/testsuite/gcc.dg/tree-ssa/split-path-10.c | 49 +++++++++++++++++++ 4 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/split-path-10.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 68cd88f1ff2..f90686c2d98 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2017-02-24 Richard Biener + + PR tree-optimization/79389 + * gimple-ssa-split-paths.c (is_feasible_trace): Verify more + properly that a threading opportunity exists. Detect conditional + copy/constant propagation opportunities. + 2017-02-23 Eric Botcazou * config/visium/visium.md (type): Add trap. diff --git a/gcc/gimple-ssa-split-paths.c b/gcc/gimple-ssa-split-paths.c index f1bf7ec604c..0f6b2417d2c 100644 --- a/gcc/gimple-ssa-split-paths.c +++ b/gcc/gimple-ssa-split-paths.c @@ -232,12 +232,32 @@ is_feasible_trace (basic_block bb) /* But for memory the PHI alone isn't good enough. */ && ! virtual_operand_p (gimple_phi_result (stmt))) { + bool found_unchanged_path = false; 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; + found_unchanged_path = true; break; } + /* If we found an unchanged path this can only be a threading + opportunity if we have uses of the loop header PHI result + in a stmt dominating the merge block. Otherwise the + splitting may prevent if-conversion. */ + if (found_unchanged_path) + { + use_operand_p use2_p; + imm_use_iterator iter2; + FOR_EACH_IMM_USE_FAST (use2_p, iter2, gimple_phi_result (stmt)) + { + basic_block use_bb = gimple_bb (USE_STMT (use2_p)); + if (use_bb != bb + && dominated_by_p (CDI_DOMINATORS, bb, use_bb)) + { + found_useful_phi = true; + break; + } + } + } if (found_useful_phi) break; } @@ -245,7 +265,32 @@ is_feasible_trace (basic_block bb) if (found_useful_phi) break; } - if (! found_useful_phi) + /* There is one exception namely a controlling condition we can propagate + an equivalence from to the joiner. */ + bool found_cprop_opportunity = false; + basic_block dom = get_immediate_dominator (CDI_DOMINATORS, bb); + gcond *cond = as_a (last_stmt (dom)); + if (gimple_cond_code (cond) == EQ_EXPR + || gimple_cond_code (cond) == NE_EXPR) + for (unsigned i = 0; i < 2; ++i) + { + tree op = gimple_op (cond, i); + if (TREE_CODE (op) == SSA_NAME) + { + use_operand_p use_p; + imm_use_iterator iter; + FOR_EACH_IMM_USE_FAST (use_p, iter, op) + if (gimple_bb (USE_STMT (use_p)) == bb) + { + found_cprop_opportunity = true; + break; + } + } + if (found_cprop_opportunity) + break; + } + + if (! found_useful_phi && ! found_cprop_opportunity) { if (dump_file && (dump_flags & TDF_DETAILS)) fprintf (dump_file, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6efe58d151d..6b62ae8dc0e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-02-24 Richard Biener + + PR tree-optimization/79389 + * gcc.dg/tree-ssa/split-path-10.c: New testcase. + 2017-02-23 Paolo Carlini PR c++/79361 diff --git a/gcc/testsuite/gcc.dg/tree-ssa/split-path-10.c b/gcc/testsuite/gcc.dg/tree-ssa/split-path-10.c new file mode 100644 index 00000000000..ed208795488 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/split-path-10.c @@ -0,0 +1,49 @@ +/* PR tree-optimization/79389 */ +/* { dg-do compile } */ +/* { dg-options "-O3 -fdump-tree-split-paths-details" } */ + +typedef struct +{ + int m[17]; + int seed; + int i; + int j; + int haveRange; + double left; + double right; + double width; +} +Random_struct, *Random; + +Random new_Random_seed(int seed); +double Random_nextDouble(Random R); +void Random_delete(Random R); + +static const int SEED = 113; + +double MonteCarlo_integrate(int Num_samples) +{ + + + Random R = new_Random_seed(SEED); + + + int under_curve = 0; + int count; + + for (count=0; count