From: Martin Liska Date: Tue, 19 Mar 2019 17:08:28 +0000 (+0100) Subject: Fix set of even probabilities (PR middle-end/89737). X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2214085affb80feb19e79882ee769e28c2a85a5a;p=gcc.git Fix set of even probabilities (PR middle-end/89737). 2019-03-19 Martin Liska PR middle-end/89737 * predict.c (combine_predictions_for_bb): Empty likely_edges and unlikely_edges if there's an edge that belongs to both these sets. 2019-03-19 Martin Liska PR middle-end/89737 * gcc.dg/pr89737.c: New test. From-SVN: r269804 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 510faab83ab..750d5e67cfd 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2019-03-19 Martin Liska + + PR middle-end/89737 + * predict.c (combine_predictions_for_bb): Empty likely_edges and + unlikely_edges if there's an edge that belongs to both these sets. + 2018-03-19 Segher Boessenkool PR target/89746 diff --git a/gcc/predict.c b/gcc/predict.c index 43ee91a5b13..60a19d7edd1 100644 --- a/gcc/predict.c +++ b/gcc/predict.c @@ -1229,12 +1229,23 @@ combine_predictions_for_bb (basic_block bb, bool dry_run) if (pred->ep_probability <= PROB_VERY_UNLIKELY || pred->ep_predictor == PRED_COLD_LABEL) unlikely_edges.add (pred->ep_edge); - if (pred->ep_probability >= PROB_VERY_LIKELY - || pred->ep_predictor == PRED_BUILTIN_EXPECT - || pred->ep_predictor == PRED_HOT_LABEL) + else if (pred->ep_probability >= PROB_VERY_LIKELY + || pred->ep_predictor == PRED_BUILTIN_EXPECT + || pred->ep_predictor == PRED_HOT_LABEL) likely_edges.add (pred); } + /* It can happen that an edge is both in likely_edges and unlikely_edges. + Clear both sets in that situation. */ + for (hash_set::iterator it = likely_edges.begin (); + it != likely_edges.end (); ++it) + if (unlikely_edges.contains ((*it)->ep_edge)) + { + likely_edges.empty (); + unlikely_edges.empty (); + break; + } + if (!dry_run) set_even_probabilities (bb, &unlikely_edges, &likely_edges); clear_bb_predictions (bb); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 986457ab159..86cc80b3d37 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-03-19 Martin Liska + + PR middle-end/89737 + * gcc.dg/pr89737.c: New test. + 2019-03-19 Jan Hubicka PR lto/87809 diff --git a/gcc/testsuite/gcc.dg/pr89737.c b/gcc/testsuite/gcc.dg/pr89737.c new file mode 100644 index 00000000000..cd3dc81769e --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr89737.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-profile_estimate" } */ + +int a, b; + +void c() { + &&d; + void *e = &&f, *g = &&h; +f: + __attribute__((hot)) h : __attribute__((cold)) for (; a;) goto *g; +d: + for (; b;) + goto *e; +} + +/* { dg-final { scan-tree-dump-times "predicted to even probabilities" 4 "profile_estimate"} } */ +