Fix first match heuristics
authorMartin Liska <mliska@suse.cz>
Thu, 2 Jun 2016 12:51:57 +0000 (14:51 +0200)
committerMartin Liska <marxin@gcc.gnu.org>
Thu, 2 Jun 2016 12:51:57 +0000 (12:51 +0000)
* predict.c (combine_predictions_for_bb): Fix first match in
cases where a first predictor contains more than one occurence
in list of predictors.  Take the best value in such case.
* gcc.dg/predict-9.c: New test.

From-SVN: r237036

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

index 01beb954298220db06cabec47ab3247c753ad83f..d4af6afc87e3e1d1b78ad3d2ce2e92b8a6abd56e 100644 (file)
@@ -1,3 +1,9 @@
+2016-06-02  Martin Liska  <mliska@suse.cz>
+
+       * predict.c (combine_predictions_for_bb): Fix first match in
+       cases where a first predictor contains more than one occurence
+       in list of predictors.  Take the best value in such case.
+
 2016-06-02  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
 
        PR rtl-optimization/71295
index e9dda20a0f7b4e36e30524307bf2fbc749e15acd..429f44e02714db4efddd13aa940ad8167eca6584 100644 (file)
@@ -939,7 +939,7 @@ combine_predictions_for_bb (basic_block bb, bool dry_run)
                   pred2; pred2 = pred2->ep_next)
               if (pred2 != pred && pred2->ep_predictor == pred->ep_predictor)
                 {
-                  int probability2 = pred->ep_probability;
+                  int probability2 = pred2->ep_probability;
 
                   if (pred2->ep_edge != first)
                     probability2 = REG_BR_PROB_BASE - probability2;
index b0fa91b8171dc429f953a9eb8ce5b43c40db7121..fcf6bbd2279d079df479516416e8d2c2097b7726 100644 (file)
@@ -1,3 +1,7 @@
+2016-06-02  Martin Liska  <mliska@suse.cz>
+
+       * gcc.dg/predict-9.c: New test.
+
 2016-06-02  Jakub Jelinek  <jakub@redhat.com>
 
        * lib/gcc-dg.exp (cleanup-after-saved-dg-test): Add missing
diff --git a/gcc/testsuite/gcc.dg/predict-9.c b/gcc/testsuite/gcc.dg/predict-9.c
new file mode 100644 (file)
index 0000000..59be16e
--- /dev/null
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-profile_estimate" } */
+
+extern int global;
+extern int global2;
+extern int global3;
+
+void foo (int base)
+{
+  int i;
+  while (global < 10)
+  {
+    if(global || global2 || global3)
+      return;
+
+    for (i = base; i < 10; i++)
+      if (i > 123)
+       return;
+  }
+}
+
+/* { dg-final { scan-tree-dump-times "first match heuristics: 2.0%" 4 "profile_estimate"} } */
+/* { dg-final { scan-tree-dump-times "first match heuristics: 4.5%" 0 "profile_estimate"} } */