Introduce PROB_UNINITIALIZED constant and use it in predict.def.
authorMartin Liska <mliska@suse.cz>
Fri, 19 Jan 2018 12:05:20 +0000 (13:05 +0100)
committerMartin Liska <marxin@gcc.gnu.org>
Fri, 19 Jan 2018 12:05:20 +0000 (12:05 +0000)
2018-01-19  Martin Liska  <mliska@suse.cz>

* predict.c (predict_insn_def): Add new assert.
(struct branch_predictor): Change type to signed integer.
(test_prediction_value_range): Amend test to cover
PROB_UNINITIALIZED.
* predict.def (PRED_LOOP_ITERATIONS): Use the new constant.
(PRED_LOOP_ITERATIONS_GUESSED): Likewise.
(PRED_LOOP_ITERATIONS_MAX): Likewise.
(PRED_LOOP_IV_COMPARE): Likewise.
* predict.h (PROB_UNINITIALIZED): Define new constant.

From-SVN: r256887

gcc/ChangeLog
gcc/predict.c
gcc/predict.def
gcc/predict.h

index 5ea286f46e6bf44aedce3f10533af37eebe07e1c..38c85feb83e6a9c4a21aadbb97a0274313bf561b 100644 (file)
@@ -1,3 +1,15 @@
+2018-01-19  Martin Liska  <mliska@suse.cz>
+
+       * predict.c (predict_insn_def): Add new assert.
+       (struct branch_predictor): Change type to signed integer.
+       (test_prediction_value_range): Amend test to cover
+       PROB_UNINITIALIZED.
+       * predict.def (PRED_LOOP_ITERATIONS): Use the new constant.
+       (PRED_LOOP_ITERATIONS_GUESSED): Likewise.
+       (PRED_LOOP_ITERATIONS_MAX): Likewise.
+       (PRED_LOOP_IV_COMPARE): Likewise.
+       * predict.h (PROB_UNINITIALIZED): Define new constant.
+
 2018-01-19  Martin Liska  <mliska@suse.cz>
 
        * predict.c (dump_prediction): Add new format for
index fdf5d824459c85f414d3bd9c5bbcbbd3e4db3136..340c76674344b663a63f10186d9f7ba28795dbb9 100644 (file)
@@ -545,6 +545,7 @@ predict_insn_def (rtx_insn *insn, enum br_predictor predictor,
                  enum prediction taken)
 {
    int probability = predictor_info[(int) predictor].hitrate;
+   gcc_assert (probability != PROB_UNINITIALIZED);
 
    if (taken != TAKEN)
      probability = REG_BR_PROB_BASE - probability;
@@ -4196,7 +4197,7 @@ namespace selftest {
 struct branch_predictor
 {
   const char *name;
-  unsigned probability;
+  int probability;
 };
 
 #define DEF_PREDICTOR(ENUM, NAME, HITRATE, FLAGS) { NAME, HITRATE },
@@ -4211,6 +4212,9 @@ test_prediction_value_range ()
 
   for (unsigned i = 0; predictors[i].name != NULL; i++)
     {
+      if (predictors[i].probability == PROB_UNINITIALIZED)
+       continue;
+
       unsigned p = 100 * predictors[i].probability / REG_BR_PROB_BASE;
       ASSERT_TRUE (p > 50 && p <= 100);
     }
index 0f37e399312e6d4946f042c48d07596cd52dfb39..390b9a35fa7db4636bfc5da30fa37835039fa9dd 100644 (file)
@@ -54,7 +54,7 @@ DEF_PREDICTOR (PRED_UNCONDITIONAL, "unconditional jump", PROB_ALWAYS,
 /* Use number of loop iterations determined by # of iterations
    analysis to set probability.  We don't want to use Dempster-Shaffer
    theory here, as the predictions is exact.  */
-DEF_PREDICTOR (PRED_LOOP_ITERATIONS, "loop iterations", PROB_ALWAYS,
+DEF_PREDICTOR (PRED_LOOP_ITERATIONS, "loop iterations", PROB_UNINITIALIZED,
               PRED_FLAG_FIRST_MATCH)
 
 /* Assume that any given atomic operation has low contention,
@@ -71,11 +71,11 @@ DEF_PREDICTOR (PRED_BUILTIN_EXPECT, "__builtin_expect", PROB_VERY_LIKELY,
 
 /* Use number of loop iterations guessed by the contents of the loop.  */
 DEF_PREDICTOR (PRED_LOOP_ITERATIONS_GUESSED, "guessed loop iterations",
-              PROB_ALWAYS, PRED_FLAG_FIRST_MATCH)
+              PROB_UNINITIALIZED, PRED_FLAG_FIRST_MATCH)
 
 /* Use number of loop iterations guessed by the contents of the loop.  */
 DEF_PREDICTOR (PRED_LOOP_ITERATIONS_MAX, "guessed loop iterations",
-              PROB_ALWAYS, PRED_FLAG_FIRST_MATCH)
+              PROB_UNINITIALIZED, PRED_FLAG_FIRST_MATCH)
 
 /* Branch containing goto is probably not taken.  */
 DEF_PREDICTOR (PRED_CONTINUE, "continue", HITRATE (67), 0)
@@ -151,7 +151,7 @@ DEF_PREDICTOR (PRED_LOOP_IV_COMPARE_GUESS, "guess loop iv compare",
 
 /* Use number of loop iterations determined by # of iterations analysis
    to set probability of branches that compares IV to loop bound variable.  */
-DEF_PREDICTOR (PRED_LOOP_IV_COMPARE, "loop iv compare", PROB_VERY_LIKELY,
+DEF_PREDICTOR (PRED_LOOP_IV_COMPARE, "loop iv compare", PROB_UNINITIALIZED,
               PRED_FLAG_FIRST_MATCH)
 
 /* In the following code
index 57715159b956fb8ed40727d66ab046abb39e92ea..e4d1da090cada6742f5c193c4a91fd0ce13cb527 100644 (file)
@@ -31,6 +31,7 @@ along with GCC; see the file COPYING3.  If not see
 #define PROB_ALWAYS            (REG_BR_PROB_BASE)
 #define PROB_UNLIKELY           (REG_BR_PROB_BASE / 5 - 1)
 #define PROB_LIKELY             (REG_BR_PROB_BASE - PROB_UNLIKELY)
+#define PROB_UNINITIALIZED      (-1)
 
 #define DEF_PREDICTOR(ENUM, NAME, HITRATE, FLAGS) ENUM,
 enum br_predictor