From a4ab23b698ec5b8810a23df011453967d1d09180 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Tue, 17 Jun 2014 07:37:24 +0000 Subject: [PATCH] tree-ssa-loop-im.c (determine_max_movement): Adjust cost of PHI node moving. 2014-06-17 Richard Biener * tree-ssa-loop-im.c (determine_max_movement): Adjust cost of PHI node moving. * gcc.dg/tree-ssa/ssa-lim-12.c: New testcase. From-SVN: r211724 --- gcc/ChangeLog | 5 ++++ gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-12.c | 27 ++++++++++++++++++++++ gcc/tree-ssa-loop-im.c | 15 ++++++++---- 4 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-12.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 676621e85cf..16c505f6f1d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2014-06-17 Richard Biener + + * tree-ssa-loop-im.c (determine_max_movement): Adjust cost + of PHI node moving. + 2014-06-17 Kugan Vivekanandarajah * config/arm/arm.c (arm_atomic_assign_expand_fenv): call diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d6a3dd3c7e0..7f408adf743 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2014-06-17 Richard Biener + + * gcc.dg/tree-ssa/ssa-lim-12.c: New testcase. + 2014-06-16 Richard Biener PR tree-optimization/61482 diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-12.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-12.c new file mode 100644 index 00000000000..e0d93a993d2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-12.c @@ -0,0 +1,27 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-lim1" } */ + +int a[1024]; + +void foo (int x, int z) +{ + int i; + int y = -x; + for (i = 0; i < 1024; ++i) + a[i] = x ? y : z; +} + +void bar (int x, int z) +{ + int j; + for (j = 0; j < 1024; ++j) + { + int i; + int y = -j + z; + for (i = 0; i < 1024; ++i) + a[i] = x ? y : j; + } +} + +/* { dg-final { scan-tree-dump-times "!= 0 ? " 2 "lim1" } } */ +/* { dg-final { cleanup-tree-dump "lim1" } } */ diff --git a/gcc/tree-ssa-loop-im.c b/gcc/tree-ssa-loop-im.c index e957f921141..6569c0664d2 100644 --- a/gcc/tree-ssa-loop-im.c +++ b/gcc/tree-ssa-loop-im.c @@ -729,14 +729,21 @@ determine_max_movement (gimple stmt, bool must_preserve_exec) } if (!add_dependency (val, lim_data, loop, false)) return false; - def_data = get_lim_data (SSA_NAME_DEF_STMT (val)); - if (def_data) + + gimple def_stmt = SSA_NAME_DEF_STMT (val); + if (gimple_bb (def_stmt) + && gimple_bb (def_stmt)->loop_father == loop) { - min_cost = MIN (min_cost, def_data->cost); - total_cost += def_data->cost; + def_data = get_lim_data (def_stmt); + if (def_data) + { + min_cost = MIN (min_cost, def_data->cost); + total_cost += def_data->cost; + } } } + min_cost = MIN (min_cost, total_cost); lim_data->cost += min_cost; if (gimple_phi_num_args (stmt) > 1) -- 2.30.2