public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: marxin <mliska@suse.cz>
To: gcc-patches@gcc.gnu.org
Cc: hubicka@ucw.cz
Subject: [PATCH 1/3] Come up with selftests for predict.c.
Date: Tue, 06 Jun 2017 09:05:00 -0000	[thread overview]
Message-ID: <4086ac276cc114fac5d0e3e18c36138ae3d09b3c.1496739572.git.mliska@suse.cz> (raw)
In-Reply-To: <cover.1496739572.git.mliska@suse.cz>

gcc/ChangeLog:

2017-05-26  Martin Liska  <mliska@suse.cz>

	* predict.c (struct branch_predictor): New struct.
	(test_prediction_value_range): New test.
	(predict_tests_c_tests): New function.
	* selftest-run-tests.c (selftest::run_tests): Run the function.
	* selftest.h: Declare new tests.
---
 gcc/predict.c            | 39 +++++++++++++++++++++++++++++++++++++++
 gcc/selftest-run-tests.c |  1 +
 gcc/selftest.h           |  1 +
 3 files changed, 41 insertions(+)

diff --git a/gcc/predict.c b/gcc/predict.c
index ac35fa41129..ea445e94e46 100644
--- a/gcc/predict.c
+++ b/gcc/predict.c
@@ -57,6 +57,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-scalar-evolution.h"
 #include "ipa-utils.h"
 #include "gimple-pretty-print.h"
+#include "selftest.h"
 
 /* Enum with reasons why a predictor is ignored.  */
 
@@ -3803,3 +3804,41 @@ force_edge_cold (edge e, bool impossible)
 		 impossible ? "impossible" : "cold");
     }
 }
+
+#if CHECKING_P
+
+namespace selftest {
+
+/* Test that value range of predictor values defined in predict.def is
+   within range [51, 100].  */
+
+struct branch_predictor
+{
+  const char *name;
+  unsigned probability;
+};
+
+#define DEF_PREDICTOR(ENUM, NAME, HITRATE, FLAGS) { NAME, HITRATE },
+
+static void
+test_prediction_value_range ()
+{
+  branch_predictor predictors[] = {
+#include "predict.def"
+    {NULL, -1}
+  };
+
+  for (unsigned i = 0; predictors[i].name != NULL; i++)
+    ASSERT_TRUE (100 * predictors[i].probability / REG_BR_PROB_BASE > 50);
+}
+
+/* Run all of the selfests within this file.  */
+
+void
+predict_tests_c_tests ()
+{
+  test_prediction_value_range ();
+}
+
+} // namespace selftest
+#endif /* CHECKING_P.  */
diff --git a/gcc/selftest-run-tests.c b/gcc/selftest-run-tests.c
index f62bc72b072..af511a47681 100644
--- a/gcc/selftest-run-tests.c
+++ b/gcc/selftest-run-tests.c
@@ -92,6 +92,7 @@ selftest::run_tests ()
     targetm.run_target_selftests ();
 
   store_merging_c_tests ();
+  predict_tests_c_tests ();
 
   /* Run any lang-specific selftests.  */
   lang_hooks.run_lang_selftests ();
diff --git a/gcc/selftest.h b/gcc/selftest.h
index dad53e9fe09..e84b309359d 100644
--- a/gcc/selftest.h
+++ b/gcc/selftest.h
@@ -196,6 +196,7 @@ extern void tree_c_tests ();
 extern void tree_cfg_c_tests ();
 extern void vec_c_tests ();
 extern void wide_int_cc_tests ();
+extern void predict_tests_c_tests ();
 
 extern int num_passes;
 
-- 
2.13.0


  parent reply	other threads:[~2017-06-06  9:05 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-06  9:05 [PATCH 0/3] Rework early return and hot/cold label predictors marxin
2017-06-06  9:05 ` [PATCH 2/3] Make early return predictor more precise marxin
2017-06-09 14:08   ` Jan Hubicka
2017-06-13 10:59     ` Martin Liška
2017-06-19 11:11       ` Jan Hubicka
2017-06-20 12:13         ` Martin Liška
2017-06-21  8:27           ` Jan Hubicka
2017-06-21 12:50             ` Martin Liška
2017-06-22 10:48               ` [PATCH] Fix ipa-split-5.c test-case Martin Liška
2017-06-22 14:14               ` [PATCH 2/3] Make early return predictor more precise Christophe Lyon
2017-06-23  7:03                 ` Martin Liška
2017-06-23  7:40                   ` Christophe Lyon
2017-06-06  9:05 ` marxin [this message]
2017-06-06 10:44   ` [PATCH 1/3] Come up with selftests for predict.c David Malcolm
2017-06-08 12:30     ` Martin Liška
2017-06-08 13:09       ` David Malcolm
2017-06-08 23:07       ` Jan Hubicka
2017-06-06  9:05 ` [PATCH 3/3] Rework cold and hot label attributes in predict.c marxin
2017-06-09 14:04   ` Jan Hubicka
2017-06-21 13:06 ` [PATCH 4/N] Recover GOTO predictor Martin Liška
2017-06-21 13:09   ` Martin Liška
2017-06-22 10:27   ` Richard Biener
2017-06-22 10:57     ` Martin Liška
2017-06-22 11:47       ` Richard Biener
2017-06-30  9:24         ` Martin Liška
2017-06-30 12:37           ` Jan Hubicka
2017-06-30 13:48     ` Martin Liška
2017-07-31  7:47       ` Martin Liška
2017-07-31  8:55         ` Richard Biener

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4086ac276cc114fac5d0e3e18c36138ae3d09b3c.1496739572.git.mliska@suse.cz \
    --to=mliska@suse.cz \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=hubicka@ucw.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).