Patchwork tail_merge_optimize frequency fix

login
register
mail settings
Submitter Tom de Vries
Date Nov. 15, 2011, 7:24 p.m.
Message ID <4EC2BC5B.1000408@mentor.com>
Download mbox | patch
Permalink /patch/125860/
State New
Headers show

Comments

Tom de Vries - Nov. 15, 2011, 7:24 p.m.
Richard,

this patch fixes up the basic block frequencies after merging 2 bbs in
tail_merge_optimize, and prevents tree-dump messages like:
'Invalid sum of incoming frequencies x, should be y'.

Bootstrapped and reg-tested on x86_64 and i686, build and reg-tested on ARM and
MIPS.

OK for trunk?

Thanks,
- Tom

2011-11-15  Tom de Vries  <tom@codesourcery.com>

	* tree-ssa-tail-merge.c (replace_block_by): Add frequency of bb2 to bb1.

	* gcc.dg/pr43864.c: Check for absence of 'Invalid sum' in pre tree-dump.
	* gcc.dg/pr43864-2.c: Same.
	* gcc.dg/pr43864-3.c: Same.
	* gcc.dg/pr43864-4.c: Same.
Jeff Law - Nov. 15, 2011, 8:15 p.m.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 11/15/11 12:24, Tom de Vries wrote:
> Richard,
> 
> this patch fixes up the basic block frequencies after merging 2 bbs
> in tail_merge_optimize, and prevents tree-dump messages like: 
> 'Invalid sum of incoming frequencies x, should be y'.
> 
> Bootstrapped and reg-tested on x86_64 and i686, build and
> reg-tested on ARM and MIPS.
> 
> OK for trunk?
> 
> Thanks, - Tom
> 
> 2011-11-15  Tom de Vries  <tom@codesourcery.com>
> 
> * tree-ssa-tail-merge.c (replace_block_by): Add frequency of bb2 to
> bb1.
> 
> * gcc.dg/pr43864.c: Check for absence of 'Invalid sum' in pre
> tree-dump. * gcc.dg/pr43864-2.c: Same. * gcc.dg/pr43864-3.c: Same. 
> * gcc.dg/pr43864-4.c: Same.
Just to be safe, can you clamp bb's frequency at BB_FREQ_MAX.   ie,
after summing the frequencies

if (bb2->frequency > BB_FREQ_MAX)
  bb2->frequency = BB_FREQ_MAX;

In theory this shouldn't happen, but often the frequencies go goofy.

Approved with that fix.

jeff
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJOwshbAAoJEBRtltQi2kC7JbcH/1EWDBcbyGnBPK9TiSYN9bUq
jA9Unhw3cA6VChRL9B4LVI6IdHuukzCnyFHgKUYU0IwHWKEJFXK59JrQh5xxlXxd
Xe4A+7ryNxoFatXPPzisovB5YUVgxQ+vq6J1kQcXl/Ty2c64706ufJ/3lvV1THL1
1lLtxXZs8qzTB0tLerQAcviyr4pV7/Wmj7NXsylR43ogHZIrjRG2BeQdiVeNNgJ5
tPvC8/ZVjycj21jvISUxKbAJgRIVBHCPAYKf3K7nHblwnThq7M+BGazvrQIsgCSu
AjH7zDgrlD/x02dP/41UrxeGGtuMyefTpGVp5b7azzjni5/n/3xpwv/Ogv/Y97I=
=zT+M
-----END PGP SIGNATURE-----

Patch

Index: gcc/tree-ssa-tail-merge.c
===================================================================
--- gcc/tree-ssa-tail-merge.c (revision 181377)
+++ gcc/tree-ssa-tail-merge.c (working copy)
@@ -1396,6 +1396,9 @@  replace_block_by (basic_block bb1, basic
 		   pred_edge, UNKNOWN_LOCATION);
     }
 
+  bb2->frequency += bb1->frequency;
+  bb1->frequency = 0;
+
   /* Do updates that use bb1, before deleting bb1.  */
   release_last_vdef (bb1);
   same_succ_flush_bb (bb1);
Index: gcc/testsuite/gcc.dg/pr43864-2.c
===================================================================
--- gcc/testsuite/gcc.dg/pr43864-2.c (revision 181377)
+++ gcc/testsuite/gcc.dg/pr43864-2.c (working copy)
@@ -19,4 +19,5 @@  f (int c, int b, int d)
 
 /* { dg-final { scan-tree-dump-times "if " 0 "pre"} } */
 /* { dg-final { scan-tree-dump-times "_.*\\\+.*_" 1 "pre"} } */
+/* { dg-final { scan-tree-dump-not "Invalid sum" "pre"} } */
 /* { dg-final { cleanup-tree-dump "pre" } } */
Index: gcc/testsuite/gcc.dg/pr43864-3.c
===================================================================
--- gcc/testsuite/gcc.dg/pr43864-3.c (revision 181377)
+++ gcc/testsuite/gcc.dg/pr43864-3.c (working copy)
@@ -20,4 +20,5 @@  int f(int c, int b, int d)
 
 /* { dg-final { scan-tree-dump-times "if " 0 "pre"} } */
 /* { dg-final { scan-tree-dump-times "_.*\\\+.*_" 1 "pre"} } */
+/* { dg-final { scan-tree-dump-not "Invalid sum" "pre"} } */
 /* { dg-final { cleanup-tree-dump "pre" } } */
Index: gcc/testsuite/gcc.dg/pr43864-4.c
===================================================================
--- gcc/testsuite/gcc.dg/pr43864-4.c (revision 181377)
+++ gcc/testsuite/gcc.dg/pr43864-4.c (working copy)
@@ -25,4 +25,5 @@  int f(int c, int b, int d)
 /* { dg-final { scan-tree-dump-times "if " 0 "pre"} } */
 /* { dg-final { scan-tree-dump-times "_.*\\\+.*_" 1 "pre"} } */
 /* { dg-final { scan-tree-dump-times " - " 2 "pre"} } */
+/* { dg-final { scan-tree-dump-not "Invalid sum" "pre"} } */
 /* { dg-final { cleanup-tree-dump "pre" } } */
Index: gcc/testsuite/gcc.dg/pr43864.c
===================================================================
--- gcc/testsuite/gcc.dg/pr43864.c (revision 181377)
+++ gcc/testsuite/gcc.dg/pr43864.c (working copy)
@@ -32,4 +32,5 @@  hprofStartupp (char *outputFileName, cha
 }
 
 /* { dg-final { scan-tree-dump-times "myfree \\(" 1 "pre"} } */
+/* { dg-final { scan-tree-dump-not "Invalid sum" "pre"} } */
 /* { dg-final { cleanup-tree-dump "pre" } } */