public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH][PR65511] Fix edge probabilities in gimple_duplicate_sese_tail
@ 2015-03-30  7:57 Tom de Vries
  2015-03-30  8:15 ` Jan Hubicka
  2015-03-30  8:21 ` [PATCH][PR65511] Fix edge probabilities in gimple_duplicate_sese_tail Jan Hubicka
  0 siblings, 2 replies; 8+ messages in thread
From: Tom de Vries @ 2015-03-30  7:57 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 1968 bytes --]

Hi,

this patch fixes PR65511.

For the testcase, before transform_to_exit_first_loop the back-edge probability 
is 99%:
...
;; basic block 5, loop depth 1, count 0, freq 7920, maybe hot
;;  prev block 11, next block 6, flags: (NEW)
;;  pred:       11 [100.0%]  (FALLTHRU)
;;              7 [100.0%]  (FALLTHRU,EXECUTABLE)
# .MEM_15 = PHI <.MEM_3(D)(11), .MEM_9(7)>
# ivtmp_22 = PHI <0(11), ivtmp_23(7)>
# RANGE [0, 1000] NONZERO 1023
i_14 = ivtmp_22;
# VUSE <.MEM_15>
_6 = aD.1830[i_14];
# VUSE <.MEM_15>
_7 = bD.1831[i_14];
# RANGE [0, 4294967295]
_8 = _6 + _7;
# .MEM_9 = VDEF <.MEM_15>
cD.1832[i_14] = _8;
# RANGE [1, 1001] NONZERO 1023
i_10 = i_14 + 1;
# RANGE [0, 1000] NONZERO 1023
i.0_4 = (unsigned intD.9) i_10;
if (ivtmp_22 < _12)
   goto <bb 7>;
else
   goto <bb 6>;
;;  succ:       7 [99.0%]  (TRUE_VALUE,EXECUTABLE)
;;              6 [1.0%]  (FALSE_VALUE,EXECUTABLE)
...

But after transform_to_exit_first_loop, the back-edge has a probability of 100%:
...
;; basic block 5, loop depth 1, count 0, freq 7920, maybe hot
;;  prev block 11, next block 13, flags: (NEW)
;;  pred:       11 [100.0%]  (FALLTHRU)
;;              7 [100.0%]  (FALLTHRU,EXECUTABLE)
# .MEM_24 = PHI <.MEM_3(D)(11), .MEM_9(7)>
# ivtmp_25 = PHI <0(11), ivtmp_23(7)>
if (ivtmp_25 < _12)
   goto <bb 13>;
else
   goto <bb 14>;
;;  succ:       13 [100.0%]  (TRUE_VALUE,EXECUTABLE)
;;              14 (FALSE_VALUE,EXECUTABLE)
...

This patch fixes that:
...
;; basic block 5, loop depth 1, count 0, freq 7920, maybe hot
;;  prev block 11, next block 13, flags: (NEW)
;;  pred:       11 [100.0%]  (FALLTHRU)
;;              7 [100.0%]  (FALLTHRU,EXECUTABLE)
# .MEM_24 = PHI <.MEM_3(D)(11), .MEM_9(7)>
# ivtmp_25 = PHI <0(11), ivtmp_23(7)>
if (ivtmp_25 < _12)
   goto <bb 13>;
else
   goto <bb 14>;
;;  succ:       13 [99.0%]  (TRUE_VALUE,EXECUTABLE)
;;              14 [1.0%]  (FALSE_VALUE,EXECUTABLE)
...

Bootstrapped and reg-tested on x86_64.

OK for, I'd guess, stage1?

Thanks,
- Tom

[-- Attachment #2: 0001-Fix-edge-probabilities-in-gimple_duplicate_sese_tail.patch --]
[-- Type: text/x-patch, Size: 1956 bytes --]

Fix edge probabilities in gimple_duplicate_sese_tail

2015-03-27  Tom de Vries  <tom@codesourcery.com>

	PR tree-optimization/65511
	* tree-cfg.c (gimple_duplicate_sese_tail): Fix edge probabilities.

	* gcc.dg/parloops-prob.c: New test.
---
 gcc/testsuite/gcc.dg/parloops-prob.c | 21 +++++++++++++++++++++
 gcc/tree-cfg.c                       |  3 +++
 2 files changed, 24 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..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;
 
   /* Register the new edge from SWITCH_BB in loop exit lists.  */
   rescan_loop_exit (snew, true, false);
-- 
1.9.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH][PR65511] Fix edge probabilities in gimple_duplicate_sese_tail
  2015-03-30  7:57 [PATCH][PR65511] Fix edge probabilities in gimple_duplicate_sese_tail Tom de Vries
@ 2015-03-30  8:15 ` Jan Hubicka
  2015-03-30  9:54   ` Tom de Vries
  2015-03-30  9:55   ` [PATCH][PR65511] " Tom de Vries
  2015-03-30  8:21 ` [PATCH][PR65511] Fix edge probabilities in gimple_duplicate_sese_tail Jan Hubicka
  1 sibling, 2 replies; 8+ messages in thread
From: Jan Hubicka @ 2015-03-30  8:15 UTC (permalink / raw)
  To: Tom de Vries; +Cc: GCC Patches

> 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.

Also move_sese_region_to_fn seem to mis updating of counts.  Can you, please, add that and send updated patch?

Honza
>  
>    /* Register the new edge from SWITCH_BB in loop exit lists.  */
>    rescan_loop_exit (snew, true, false);
> -- 
> 1.9.1
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH][PR65511] Fix edge probabilities in gimple_duplicate_sese_tail
  2015-03-30  7:57 [PATCH][PR65511] Fix edge probabilities in gimple_duplicate_sese_tail Tom de Vries
  2015-03-30  8:15 ` Jan Hubicka
@ 2015-03-30  8:21 ` Jan Hubicka
  1 sibling, 0 replies; 8+ messages in thread
From: Jan Hubicka @ 2015-03-30  8:21 UTC (permalink / raw)
  To: Tom de Vries; +Cc: GCC Patches

Hi,
also this code ignores counts and probabilities:
  /* Rewire the entry and exit blocks.  The successor to the entry
     block turns into the successor of DEST_FN's ENTRY_BLOCK_PTR in
     the child function.  Similarly, the predecessor of DEST_FN's
     EXIT_BLOCK_PTR turns into the predecessor of EXIT_BLOCK_PTR.  We
     need to switch CFUN between DEST_CFUN and SAVED_CFUN so that the
     various CFG manipulation function get to the right CFG.

     FIXME, this is silly.  The CFG ought to become a parameter to
     these helpers.  */
  push_cfun (dest_cfun);
  make_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun), entry_bb, EDGE_FALLTHRU);
  if (exit_bb)
    make_edge (exit_bb,  EXIT_BLOCK_PTR_FOR_FN (cfun), 0);
  pop_cfun ();

  /* Back in the original function, the SESE region has disappeared,
     create a new basic block in its place.  */
  bb = create_empty_bb (entry_pred[0]);
  if (current_loops)
    add_bb_to_loop (bb, loop);
  for (i = 0; i < num_entry_edges; i++)
    {
      e = make_edge (entry_pred[i], bb, entry_flag[i]);
      e->probability = entry_prob[i];
    }

  for (i = 0; i < num_exit_edges; i++)
    {
      e = make_edge (bb, exit_succ[i], exit_flag[i]);
      e->probability = exit_prob[i];
    }

Finally I am somewhat concerned about move_block_to_fn.
The frequencies in one function may have different base from other function,
so they may need rescaling.

Honza

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH][PR65511] Fix edge probabilities in gimple_duplicate_sese_tail
  2015-03-30  8:15 ` Jan Hubicka
@ 2015-03-30  9:54   ` Tom de Vries
  2015-06-14 14:16     ` [PING][PATCH][PR65511] " Tom de Vries
  2015-03-30  9:55   ` [PATCH][PR65511] " Tom de Vries
  1 sibling, 1 reply; 8+ messages in thread
From: Tom de Vries @ 2015-03-30  9:54 UTC (permalink / raw)
  To: Jan Hubicka; +Cc: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 991 bytes --]

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?

Thanks,
- Tom


[-- Attachment #2: 0001-Fix-edge-probabilities-in-gimple_duplicate_sese_tail.patch --]
[-- Type: text/x-patch, Size: 2345 bytes --]

Fix edge probabilities in gimple_duplicate_sese_tail

2015-03-27  Tom de Vries  <tom@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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH][PR65511] Fix edge probabilities in gimple_duplicate_sese_tail
  2015-03-30  8:15 ` Jan Hubicka
  2015-03-30  9:54   ` Tom de Vries
@ 2015-03-30  9:55   ` Tom de Vries
  2015-06-14 16:26     ` [PING][PATCH][PR65511] Fix edge probabilities in move_sese_region_to_fn Tom de Vries
  1 sibling, 1 reply; 8+ messages in thread
From: Tom de Vries @ 2015-03-30  9:55 UTC (permalink / raw)
  To: Jan Hubicka; +Cc: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 239 bytes --]

On 30-03-15 10:15, Jan Hubicka wrote:
> Also move_sese_region_to_fn seem to mis updating of counts.  Can you, please, add that and send updated patch?
>

Like this?

OK for stage1 if bootstrap and reg-test on x86_64 are ok?

Thanks,
- Tom

[-- Attachment #2: 0002-Preserve-edge-count-in-move_sese_region_to_fn.patch --]
[-- Type: text/x-patch, Size: 3009 bytes --]

Preserve edge count in move_sese_region_to_fn

2015-03-30  Tom de Vries  <tom@codesourcery.com>

	* tree-cfg.c (move_sese_region_to_fn): Add entry_count and exit_count
	arrays, and used the to propagate edge counts alongside edge
	probabilities.
---
 gcc/tree-cfg.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index 6db6dff..ad528a3 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -6976,6 +6976,7 @@ move_sese_region_to_fn (struct function *dest_cfun, basic_block entry_bb,
   struct function *saved_cfun = cfun;
   int *entry_flag, *exit_flag;
   unsigned *entry_prob, *exit_prob;
+  gcov_type *entry_count, *exit_count;
   unsigned i, num_entry_edges, num_exit_edges, num_nodes;
   edge e;
   edge_iterator ei;
@@ -7014,10 +7015,12 @@ move_sese_region_to_fn (struct function *dest_cfun, basic_block entry_bb,
   entry_pred = XNEWVEC (basic_block, num_entry_edges);
   entry_flag = XNEWVEC (int, num_entry_edges);
   entry_prob = XNEWVEC (unsigned, num_entry_edges);
+  entry_count = XNEWVEC (gcov_type, num_entry_edges);
   i = 0;
   for (ei = ei_start (entry_bb->preds); (e = ei_safe_edge (ei)) != NULL;)
     {
       entry_prob[i] = e->probability;
+      entry_count[i] = e->count;
       entry_flag[i] = e->flags;
       entry_pred[i++] = e->src;
       remove_edge (e);
@@ -7029,10 +7032,12 @@ move_sese_region_to_fn (struct function *dest_cfun, basic_block entry_bb,
       exit_succ = XNEWVEC (basic_block, num_exit_edges);
       exit_flag = XNEWVEC (int, num_exit_edges);
       exit_prob = XNEWVEC (unsigned, num_exit_edges);
+      exit_count = XNEWVEC (gcov_type, num_exit_edges);
       i = 0;
       for (ei = ei_start (exit_bb->succs); (e = ei_safe_edge (ei)) != NULL;)
 	{
 	  exit_prob[i] = e->probability;
+	  exit_count[i] = e->count;
 	  exit_flag[i] = e->flags;
 	  exit_succ[i++] = e->dest;
 	  remove_edge (e);
@@ -7044,6 +7049,7 @@ move_sese_region_to_fn (struct function *dest_cfun, basic_block entry_bb,
       exit_succ = NULL;
       exit_flag = NULL;
       exit_prob = NULL;
+      exit_count = NULL;
     }
 
   /* Switch context to the child function to initialize DEST_FN's CFG.  */
@@ -7221,12 +7227,14 @@ move_sese_region_to_fn (struct function *dest_cfun, basic_block entry_bb,
     {
       e = make_edge (entry_pred[i], bb, entry_flag[i]);
       e->probability = entry_prob[i];
+      e->count = entry_count[i];
     }
 
   for (i = 0; i < num_exit_edges; i++)
     {
       e = make_edge (bb, exit_succ[i], exit_flag[i]);
       e->probability = exit_prob[i];
+      e->count = exit_count[i];
     }
 
   set_immediate_dominator (CDI_DOMINATORS, bb, dom_entry);
@@ -7237,10 +7245,12 @@ move_sese_region_to_fn (struct function *dest_cfun, basic_block entry_bb,
   if (exit_bb)
     {
       free (exit_prob);
+      free (exit_count);
       free (exit_flag);
       free (exit_succ);
     }
   free (entry_prob);
+  free (entry_count);
   free (entry_flag);
   free (entry_pred);
   bbs.release ();
-- 
1.9.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PING][PATCH][PR65511] Fix edge probabilities in gimple_duplicate_sese_tail
  2015-03-30  9:54   ` Tom de Vries
@ 2015-06-14 14:16     ` Tom de Vries
  0 siblings, 0 replies; 8+ messages in thread
From: Tom de Vries @ 2015-06-14 14:16 UTC (permalink / raw)
  To: Jan Hubicka; +Cc: GCC Patches

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<tom@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
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PING][PATCH][PR65511] Fix edge probabilities in move_sese_region_to_fn
  2015-03-30  9:55   ` [PATCH][PR65511] " Tom de Vries
@ 2015-06-14 16:26     ` Tom de Vries
  2015-06-24  4:38       ` Jeff Law
  0 siblings, 1 reply; 8+ messages in thread
From: Tom de Vries @ 2015-06-14 16:26 UTC (permalink / raw)
  To: Jan Hubicka; +Cc: GCC Patches

On 30/03/15 11:54, Tom de Vries wrote:
> On 30-03-15 10:15, Jan Hubicka wrote:
>> Also move_sese_region_to_fn seem to mis updating of counts.  Can you,
>> please, add that and send updated patch?
>>
>
> Like this?
>
> 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/msg01537.html .

Thanks,
- Tom

> 0002-Preserve-edge-count-in-move_sese_region_to_fn.patch
>
>
> Preserve edge count in move_sese_region_to_fn
>
> 2015-03-30  Tom de Vries<tom@codesourcery.com>
>
> 	* tree-cfg.c (move_sese_region_to_fn): Add entry_count and exit_count
> 	arrays, and used the to propagate edge counts alongside edge
> 	probabilities.
> ---
>   gcc/tree-cfg.c | 10 ++++++++++
>   1 file changed, 10 insertions(+)
>
> diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
> index 6db6dff..ad528a3 100644
> --- a/gcc/tree-cfg.c
> +++ b/gcc/tree-cfg.c
> @@ -6976,6 +6976,7 @@ move_sese_region_to_fn (struct function *dest_cfun, basic_block entry_bb,
>     struct function *saved_cfun = cfun;
>     int *entry_flag, *exit_flag;
>     unsigned *entry_prob, *exit_prob;
> +  gcov_type *entry_count, *exit_count;
>     unsigned i, num_entry_edges, num_exit_edges, num_nodes;
>     edge e;
>     edge_iterator ei;
> @@ -7014,10 +7015,12 @@ move_sese_region_to_fn (struct function *dest_cfun, basic_block entry_bb,
>     entry_pred = XNEWVEC (basic_block, num_entry_edges);
>     entry_flag = XNEWVEC (int, num_entry_edges);
>     entry_prob = XNEWVEC (unsigned, num_entry_edges);
> +  entry_count = XNEWVEC (gcov_type, num_entry_edges);
>     i = 0;
>     for (ei = ei_start (entry_bb->preds); (e = ei_safe_edge (ei)) != NULL;)
>       {
>         entry_prob[i] = e->probability;
> +      entry_count[i] = e->count;
>         entry_flag[i] = e->flags;
>         entry_pred[i++] = e->src;
>         remove_edge (e);
> @@ -7029,10 +7032,12 @@ move_sese_region_to_fn (struct function *dest_cfun, basic_block entry_bb,
>         exit_succ = XNEWVEC (basic_block, num_exit_edges);
>         exit_flag = XNEWVEC (int, num_exit_edges);
>         exit_prob = XNEWVEC (unsigned, num_exit_edges);
> +      exit_count = XNEWVEC (gcov_type, num_exit_edges);
>         i = 0;
>         for (ei = ei_start (exit_bb->succs); (e = ei_safe_edge (ei)) != NULL;)
>   	{
>   	  exit_prob[i] = e->probability;
> +	  exit_count[i] = e->count;
>   	  exit_flag[i] = e->flags;
>   	  exit_succ[i++] = e->dest;
>   	  remove_edge (e);
> @@ -7044,6 +7049,7 @@ move_sese_region_to_fn (struct function *dest_cfun, basic_block entry_bb,
>         exit_succ = NULL;
>         exit_flag = NULL;
>         exit_prob = NULL;
> +      exit_count = NULL;
>       }
>
>     /* Switch context to the child function to initialize DEST_FN's CFG.  */
> @@ -7221,12 +7227,14 @@ move_sese_region_to_fn (struct function *dest_cfun, basic_block entry_bb,
>       {
>         e = make_edge (entry_pred[i], bb, entry_flag[i]);
>         e->probability = entry_prob[i];
> +      e->count = entry_count[i];
>       }
>
>     for (i = 0; i < num_exit_edges; i++)
>       {
>         e = make_edge (bb, exit_succ[i], exit_flag[i]);
>         e->probability = exit_prob[i];
> +      e->count = exit_count[i];
>       }
>
>     set_immediate_dominator (CDI_DOMINATORS, bb, dom_entry);
> @@ -7237,10 +7245,12 @@ move_sese_region_to_fn (struct function *dest_cfun, basic_block entry_bb,
>     if (exit_bb)
>       {
>         free (exit_prob);
> +      free (exit_count);
>         free (exit_flag);
>         free (exit_succ);
>       }
>     free (entry_prob);
> +  free (entry_count);
>     free (entry_flag);
>     free (entry_pred);
>     bbs.release ();
> -- 1.9.1
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PING][PATCH][PR65511] Fix edge probabilities in move_sese_region_to_fn
  2015-06-14 16:26     ` [PING][PATCH][PR65511] Fix edge probabilities in move_sese_region_to_fn Tom de Vries
@ 2015-06-24  4:38       ` Jeff Law
  0 siblings, 0 replies; 8+ messages in thread
From: Jeff Law @ 2015-06-24  4:38 UTC (permalink / raw)
  To: Tom de Vries, Jan Hubicka; +Cc: GCC Patches

On 06/14/2015 08:15 AM, Tom de Vries wrote:
> On 30/03/15 11:54, Tom de Vries wrote:
>> On 30-03-15 10:15, Jan Hubicka wrote:
>>> Also move_sese_region_to_fn seem to mis updating of counts.  Can you,
>>> please, add that and send updated patch?
>>>
>>
>> Like this?
>>
>> 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/msg01537.html .
>
> Thanks,
> - Tom
>
>> 0002-Preserve-edge-count-in-move_sese_region_to_fn.patch
>>
>>
>> Preserve edge count in move_sese_region_to_fn
>>
>> 2015-03-30  Tom de Vries<tom@codesourcery.com>
>>
>>     * tree-cfg.c (move_sese_region_to_fn): Add entry_count and exit_count
>>     arrays, and used the to propagate edge counts alongside edge
>>     probabilities.
Please include a testcase.  I think you had one in the earlier patch 
submissions.

OK with a testcase and fresh bootstrap/regression test.

jeff

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-06-24  4:33 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-30  7:57 [PATCH][PR65511] Fix edge probabilities in gimple_duplicate_sese_tail Tom de Vries
2015-03-30  8:15 ` Jan Hubicka
2015-03-30  9:54   ` Tom de Vries
2015-06-14 14:16     ` [PING][PATCH][PR65511] " Tom de Vries
2015-03-30  9:55   ` [PATCH][PR65511] " Tom de Vries
2015-06-14 16:26     ` [PING][PATCH][PR65511] Fix edge probabilities in move_sese_region_to_fn Tom de Vries
2015-06-24  4:38       ` Jeff Law
2015-03-30  8:21 ` [PATCH][PR65511] Fix edge probabilities in gimple_duplicate_sese_tail Jan Hubicka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).