From 47e78f984ef151c621587a4dcdebc48dd577a36a Mon Sep 17 00:00:00 2001 From: Dehao Chen Date: Tue, 3 Jun 2014 21:36:05 +0000 Subject: [PATCH] tree-cfg.c (gimple_merge_blocks): Only reset count when BBs are in the same loop. 2014-06-03 Dehao Chen * 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 | 5 +++++ gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/tree-prof/merge_block.c | 21 ++++++++++++++++++++ gcc/tree-cfg.c | 7 +++++-- 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-prof/merge_block.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 406179f1764a..0d61afefbbdd 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2014-06-03 Dehao Chen + + * tree-cfg.c (gimple_merge_blocks): Only reset count when BBs are in + the same loop. + 2014-06-03 Marek Polacek PR c/60439 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index dbe2e44f2e50..db89ee3974fd 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2014-06-03 Dehao Chen + + * gcc.dg/tree-prof/merge_block.c: New test. + 2014-06-03 Uros Bizjak * 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 index 000000000000..62f7f2275021 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-prof/merge_block.c @@ -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" } } */ diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c index 126a1a9e9c77..acf08fc7bed8 100644 --- a/gcc/tree-cfg.c +++ b/gcc/tree-cfg.c @@ -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); -- 2.47.3