Fix set of even probabilities (PR middle-end/89737).
authorMartin Liska <mliska@suse.cz>
Tue, 19 Mar 2019 17:08:28 +0000 (18:08 +0100)
committerMartin Liska <marxin@gcc.gnu.org>
Tue, 19 Mar 2019 17:08:28 +0000 (17:08 +0000)
2019-03-19  Martin Liska  <mliska@suse.cz>

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  <mliska@suse.cz>

PR middle-end/89737
* gcc.dg/pr89737.c: New test.

From-SVN: r269804

gcc/ChangeLog
gcc/predict.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr89737.c [new file with mode: 0644]

index 510faab83abb8a79d6adcfa195448ed2a0acfbe5..750d5e67cfd94696e332d29e778db5670d4121e8 100644 (file)
@@ -1,3 +1,9 @@
+2019-03-19  Martin Liska  <mliska@suse.cz>
+
+       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  <segher@kernel.crashing.org>
 
        PR target/89746
index 43ee91a5b13993a46aff9aaba3155d6e36e5c74b..60a19d7edd12f9e67025ea3c699f98323e1f0034 100644 (file)
@@ -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<edge_prediction *>::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);
index 986457ab1597ee2af983b51854b0075f82df2c32..86cc80b3d3783f57da264f2a6fbf40b854064c93 100644 (file)
@@ -1,3 +1,8 @@
+2019-03-19  Martin Liska  <mliska@suse.cz>
+
+       PR middle-end/89737
+       * gcc.dg/pr89737.c: New test.
+
 2019-03-19  Jan Hubicka  <hubicka@ucw.cz>
 
        PR lto/87809
diff --git a/gcc/testsuite/gcc.dg/pr89737.c b/gcc/testsuite/gcc.dg/pr89737.c
new file mode 100644 (file)
index 0000000..cd3dc81
--- /dev/null
@@ -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"} } */
+