From 002618d87483cfb6481b0a044f113c9cf87d4ed6 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Fri, 1 Sep 2017 15:02:37 +0200 Subject: [PATCH] Fix profile update in tree-ssa-isolate-paths.c (PR tree-optimization/82059). 2017-09-01 Martin Liska PR tree-optimization/82059 * gimple-ssa-isolate-paths.c (isolate_path): Add profile and frequency only when an edge is redirected. 2017-09-01 Martin Liska PR tree-optimization/82059 * gcc.dg/tree-ssa/pr82059.c: New test. From-SVN: r251591 --- gcc/ChangeLog | 6 ++++++ gcc/gimple-ssa-isolate-paths.c | 9 ++++++--- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/tree-ssa/pr82059.c | 22 ++++++++++++++++++++++ 4 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr82059.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 61ba8994f13..125eb928211 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2017-09-01 Martin Liska + + PR tree-optimization/82059 + * gimple-ssa-isolate-paths.c (isolate_path): Add profile and + frequency only when an edge is redirected. + 2017-09-01 Claudiu Zissulescu * config/arc/arc-c.c (__ARC_LPC_WIDTH__): Add builtin define. diff --git a/gcc/gimple-ssa-isolate-paths.c b/gcc/gimple-ssa-isolate-paths.c index fbc41057463..807e0032410 100644 --- a/gcc/gimple-ssa-isolate-paths.c +++ b/gcc/gimple-ssa-isolate-paths.c @@ -160,14 +160,17 @@ isolate_path (basic_block bb, basic_block duplicate, for (ei = ei_start (duplicate->succs); (e2 = ei_safe_edge (ei)); ) remove_edge (e2); } - bb->frequency += EDGE_FREQUENCY (e); - bb->count += e->count; /* Complete the isolation step by redirecting E to reach DUPLICATE. */ e2 = redirect_edge_and_branch (e, duplicate); if (e2) - flush_pending_stmts (e2); + { + flush_pending_stmts (e2); + /* Update profile only when redirection is really processed. */ + bb->frequency += EDGE_FREQUENCY (e); + bb->count += e->count; + } /* There may be more than one statement in DUPLICATE which exhibits undefined behavior. Ultimately we want the first such statement in diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 12161a62963..0cd2a62e5e5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-09-01 Martin Liska + + PR tree-optimization/82059 + * gcc.dg/tree-ssa/pr82059.c: New test. + 2017-09-01 Claudiu Zissulescu * gcc.target/arc/loop-1.c: Deleted. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr82059.c b/gcc/testsuite/gcc.dg/tree-ssa/pr82059.c new file mode 100644 index 00000000000..0285b03cc04 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr82059.c @@ -0,0 +1,22 @@ +/* PR tree-optimization/82059 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-isolate-paths" } */ + +struct a +{ + char b; + struct a *c; +} d (), f; +void *e; +long g; +void +h () +{ + struct a *i = 0; + if (g) + i = e; + if (!i) + d (); + i->c = &f; + i->b = *(char *) h; +} -- 2.30.2