tree-cfg.c (gimple_merge_blocks): Only reset count when BBs are in the same loop.
authorDehao Chen <dehao@google.com>
Tue, 3 Jun 2014 21:36:05 +0000 (21:36 +0000)
committerDehao Chen <dehao@gcc.gnu.org>
Tue, 3 Jun 2014 21:36:05 +0000 (21:36 +0000)
2014-06-03  Dehao Chen  <dehao@google.com>

* tree-cfg.c (gimple_merge_blocks): Only reset count when BBs are in
the same loop.
* gcc.dg/tree-prof/merge_block.c: New test.

From-SVN: r211202

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-prof/merge_block.c [new file with mode: 0644]
gcc/tree-cfg.c

index 406179f..0d61afe 100644 (file)
@@ -1,3 +1,8 @@
+2014-06-03  Dehao Chen  <dehao@google.com>
+
+       * tree-cfg.c (gimple_merge_blocks): Only reset count when BBs are in
+       the same loop.
+
 2014-06-03  Marek Polacek  <polacek@redhat.com>
 
        PR c/60439
index dbe2e44..db89ee3 100644 (file)
@@ -1,3 +1,7 @@
+2014-06-03  Dehao Chen  <dehao@google.com>
+
+       * gcc.dg/tree-prof/merge_block.c: New test.
+
 2014-06-03  Uros Bizjak  <ubizjak@gmail.com>
 
        * g++.dg/ext/mv14.C (dg-options): Add -march=x86-64.
diff --git a/gcc/testsuite/gcc.dg/tree-prof/merge_block.c b/gcc/testsuite/gcc.dg/tree-prof/merge_block.c
new file mode 100644 (file)
index 0000000..62f7f22
--- /dev/null
@@ -0,0 +1,21 @@
+
+/* { dg-options "-O2 -fno-ipa-pure-const -fdump-tree-optimized-blocks-details -fno-early-inlining" } */
+int a[8];
+int t()
+{
+       int i;
+       for (i = 0; i < 3; i++)
+               if (a[i])
+                       break;
+       return i;
+}
+main ()
+{
+  int i;
+  /* The loop will be optimized away after ipa-inline.  */
+  for (i = 0; i < 1000; i++)
+    t ();
+  return 0;
+}
+/* { dg-final-use { scan-tree-dump-not "Invalid sum" "optimized"} } */
+/* { dg-final-use { cleanup-tree-dump "optimized" } } */
index 126a1a9..acf08fc 100644 (file)
@@ -1880,8 +1880,11 @@ gimple_merge_blocks (basic_block a, basic_block b)
   /* When merging two BBs, if their counts are different, the larger count
      is selected as the new bb count. This is to handle inconsistent
      profiles.  */
-  a->count = MAX (a->count, b->count);
-  a->frequency = MAX (a->frequency, b->frequency);
+  if (a->loop_father == b->loop_father)
+    {
+      a->count = MAX (a->count, b->count);
+      a->frequency = MAX (a->frequency, b->frequency);
+    }
 
   /* Merge the sequences.  */
   last = gsi_last_bb (a);