On 30/03/15 11:54, Tom de Vries wrote:
On 30-03-15 10:15, Jan Hubicka wrote:
diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index 64bdc92..c7a7c4d 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -6177,6 +6177,7 @@ gimple_duplicate_sese_tail (edge entry
ATTRIBUTE_UNUSED, edge exit ATTRIBUTE_UNU
gphi *phi;
tree def;
struct loop *target, *aloop, *cloop;
+ int exit_prob = exit->probability;
gcc_assert (EDGE_COUNT (exit->src->succs) == 2);
exits[0] = exit;
@@ -6268,6 +6269,8 @@ gimple_duplicate_sese_tail (edge entry
ATTRIBUTE_UNUSED, edge exit ATTRIBUTE_UNU
sorig = single_succ_edge (switch_bb);
sorig->flags = exits[1]->flags;
snew = make_edge (switch_bb, nentry_bb, exits[0]->flags);
+ snew->probability = exit_prob;
+ sorig->probability = REG_BR_PROB_BASE - exit_prob;
You need to also set snew->count/sorig->count.
Thanks for noting that. Updated patch.
OK for stage1 if bootstrap and reg-test on x86_64 are ok?
Ping. Original posting at
https://gcc.gnu.org/ml/gcc-patches/2015-03/msg01536.html .
Thanks,
- Tom
0001-Fix-edge-probabilities-in-gimple_duplicate_sese_tail.patch
Fix edge probabilities in gimple_duplicate_sese_tail
2015-03-27 Tom de Vries<t...@codesourcery.com>
PR tree-optimization/65511
* tree-cfg.c (gimple_duplicate_sese_tail): Fix edge probabilities and
counts.
* gcc.dg/parloops-prob.c: New test.
---
gcc/testsuite/gcc.dg/parloops-prob.c | 21 +++++++++++++++++++++
gcc/tree-cfg.c | 11 +++++++++++
2 files changed, 32 insertions(+)
create mode 100644 gcc/testsuite/gcc.dg/parloops-prob.c
diff --git a/gcc/testsuite/gcc.dg/parloops-prob.c
b/gcc/testsuite/gcc.dg/parloops-prob.c
new file mode 100644
index 0000000..a3e767c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/parloops-prob.c
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target pthread } */
+/* { dg-options "-O2 -ftree-parallelize-loops=2 -fdump-tree-fixup_cfg4-all" }
*/
+
+#define N 1000
+
+unsigned int a[N];
+unsigned int b[N];
+unsigned int c[N];
+
+void
+f (unsigned int n)
+{
+ int i;
+
+ for (i = 0; i < n; ++i)
+ c[i] = a[i] + b[i];
+}
+
+/* { dg-final { scan-tree-dump-not "freq 0" "fixup_cfg4" } } */
+/* { dg-final { cleanup-tree-dump "fixup_cfg4" } } */
diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index 64bdc92..6db6dff 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -6177,11 +6177,18 @@ gimple_duplicate_sese_tail (edge entry
ATTRIBUTE_UNUSED, edge exit ATTRIBUTE_UNU
gphi *phi;
tree def;
struct loop *target, *aloop, *cloop;
+ int exits_prob[2];
+ gcov_type exits_count[2];
gcc_assert (EDGE_COUNT (exit->src->succs) == 2);
exits[0] = exit;
exits[1] = EDGE_SUCC (exit->src, EDGE_SUCC (exit->src, 0) == exit);
+ exits_prob[0] = exits[0]->probability;
+ exits_prob[1] = exits[1]->probability;
+ exits_count[0] = exits[0]->count;
+ exits_count[1] = exits[1]->count;
+
if (!can_copy_bbs_p (region, n_region))
return false;
@@ -6268,6 +6275,10 @@ gimple_duplicate_sese_tail (edge entry ATTRIBUTE_UNUSED,
edge exit ATTRIBUTE_UNU
sorig = single_succ_edge (switch_bb);
sorig->flags = exits[1]->flags;
snew = make_edge (switch_bb, nentry_bb, exits[0]->flags);
+ snew->probability = exits_prob[0];
+ snew->count = exits_count[0];
+ sorig->probability = exits_prob[1];
+ sorig->count = exits_count[1];
/* Register the new edge from SWITCH_BB in loop exit lists. */
rescan_loop_exit (snew, true, false);
-- 1.9.1