]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Recover GOTO predictor.
authorJan Hubicka <hubicka@ucw.cz>
Mon, 31 Jul 2017 11:16:00 +0000 (13:16 +0200)
committerMartin Liska <marxin@gcc.gnu.org>
Mon, 31 Jul 2017 11:16:00 +0000 (11:16 +0000)
2017-07-31  Jan Hubicka <hubicka@ucw.cz>
    Martin Liska  <mliska@suse.cz>

* c-typeck.c (c_finish_goto_label): Build gimple predict
stament.
2017-07-31  Jan Hubicka <hubicka@ucw.cz>
    Martin Liska  <mliska@suse.cz>

* predict.def: Remove old comment and adjust probability.
* gimplify.c (should_warn_for_implicit_fallthrough): Ignore
PREDICT statements.
2017-07-31  Jan Hubicka <hubicka@ucw.cz>
    Martin Liska  <mliska@suse.cz>

* gcc.dg/predict-15.c: New test.
* gcc.dg/tree-ssa/vrp24.c: Update scanned pattern.
2017-07-31  Jan Hubicka <hubicka@ucw.cz>
    Martin Liska  <mliska@suse.cz>

* pt.c (tsubst_copy): Copy PREDICT_EXPR.
* semantics.c (finish_goto_stmt): Build gimple predict
stament.
* constexpr.c (potential_constant_expression_1): Handle
PREDICT_EXPR.

Co-Authored-By: Martin Liska <mliska@suse.cz>
From-SVN: r250737

13 files changed:
gcc/ChangeLog
gcc/c/ChangeLog
gcc/c/c-typeck.c
gcc/cp/ChangeLog
gcc/cp/constexpr.c
gcc/cp/pt.c
gcc/cp/semantics.c
gcc/gimplify.c
gcc/predict.def
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/predict-15.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/attr-hotcold-2.c
gcc/testsuite/gcc.dg/tree-ssa/vrp24.c

index 54e9a2e684168ae076d027ae0a9bd113750faa08..58d1942c8f7c098dfa8db771ac3dd97498dca2c8 100644 (file)
@@ -1,3 +1,10 @@
+2017-07-31  Jan Hubicka <hubicka@ucw.cz>
+           Martin Liska  <mliska@suse.cz>
+
+       * predict.def: Remove old comment and adjust probability.
+       * gimplify.c (should_warn_for_implicit_fallthrough): Ignore
+       PREDICT statements.
+
 2017-07-31  Uros Bizjak  <ubizjak@gmail.com>
 
        PR target/25967
index ab2a4c88ceebb502d9580a4fdfbac0e870ba9984..aff4866d91583241740bccd5ceb740a13b00f18b 100644 (file)
@@ -1,3 +1,9 @@
+2017-07-31  Jan Hubicka <hubicka@ucw.cz>
+           Martin Liska  <mliska@suse.cz>
+
+       * c-typeck.c (c_finish_goto_label): Build gimple predict
+       stament.
+
 2017-07-31  Martin Liska  <mliska@suse.cz>
 
        PR sanitize/81530
index 7451f3249fd1ac6cb030ce845f85acf9cc2eaef3..71d0135018619bafa0b118dd22dcc24ca6c223da 100644 (file)
@@ -9824,6 +9824,7 @@ c_finish_goto_label (location_t loc, tree label)
     return NULL_TREE;
   TREE_USED (decl) = 1;
   {
+    add_stmt (build_predict_expr (PRED_GOTO, NOT_TAKEN));
     tree t = build1 (GOTO_EXPR, void_type_node, decl);
     SET_EXPR_LOCATION (t, loc);
     return add_stmt (t);
index 6d9ff79c974981697fb92470b318a9fd10a451d9..76d1de09c4dd708f99ff871e91f87251b1da33d9 100644 (file)
@@ -1,3 +1,12 @@
+2017-07-31  Jan Hubicka <hubicka@ucw.cz>
+           Martin Liska  <mliska@suse.cz>
+
+       * pt.c (tsubst_copy): Copy PREDICT_EXPR.
+       * semantics.c (finish_goto_stmt): Build gimple predict
+       stament.
+       * constexpr.c (potential_constant_expression_1): Handle
+       PREDICT_EXPR.
+
 2017-07-31  Martin Liska  <mliska@suse.cz>
 
        PR sanitize/81530
index 32180a74c3fd3cb974193f96b31bdc4b13c7f692..29ba2c3dac2c0ab57e2be40289b75272f840cc04 100644 (file)
@@ -5782,6 +5782,7 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict,
 
     case CLEANUP_STMT:
     case EMPTY_CLASS_EXPR:
+    case PREDICT_EXPR:
       return false;
 
     case GOTO_EXPR:
index 173ec3f303bac9d1529f652dfaf5319e8a375d8f..ee4e6b113341387ee882c629ef8e51b7c73779f1 100644 (file)
@@ -15105,6 +15105,8 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl)
       return tsubst_binary_left_fold (t, args, complain, in_decl);
     case BINARY_RIGHT_FOLD_EXPR:
       return tsubst_binary_right_fold (t, args, complain, in_decl);
+    case PREDICT_EXPR:
+      return t;
 
     default:
       /* We shouldn't get here, but keep going if !flag_checking.  */
index 743adbc44c67d39259198eb1b48aa56dac07de41..f56d00fd8f388f21dc30789db04c09bfc94770d6 100644 (file)
@@ -41,6 +41,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "omp-general.h"
 #include "convert.h"
 #include "gomp-constants.h"
+#include "predict.h"
 
 /* There routines provide a modular interface to perform many parsing
    operations.  They may therefore be used during actual parsing, or
@@ -630,6 +631,7 @@ finish_goto_stmt (tree destination)
 
   check_goto (destination);
 
+  add_stmt (build_predict_expr (PRED_GOTO, NOT_TAKEN));
   return add_stmt (build_stmt (input_location, GOTO_EXPR, destination));
 }
 
index 80712488833efc94ca698fca9bebdd0f8ae15c58..76a08c67061e85c1004d6852e21470ebe63e41e1 100644 (file)
@@ -2037,7 +2037,9 @@ should_warn_for_implicit_fallthrough (gimple_stmt_iterator *gsi_p, tree label)
   gsi = *gsi_p;
 
   /* Skip all immediately following labels.  */
-  while (!gsi_end_p (gsi) && gimple_code (gsi_stmt (gsi)) == GIMPLE_LABEL)
+  while (!gsi_end_p (gsi)
+        && (gimple_code (gsi_stmt (gsi)) == GIMPLE_LABEL
+            || gimple_code (gsi_stmt (gsi)) == GIMPLE_PREDICT))
     gsi_next (&gsi);
 
   /* { ... something; default:; } */
index f7b2bf7738c1bbfeea6ec5b9cef1002ccb3c3640..326c39ae4c9eb63c28ebf8ee78fee37a61535c99 100644 (file)
@@ -132,9 +132,8 @@ DEF_PREDICTOR (PRED_RECURSIVE_CALL, "recursive call", HITRATE (75), 0)
 DEF_PREDICTOR (PRED_TREE_EARLY_RETURN, "early return (on trees)", HITRATE (66),
               0)
 
-/* Branch containing goto is probably not taken.
-   FIXME: Currently not used.  */
-DEF_PREDICTOR (PRED_GOTO, "goto", HITRATE (70), 0)
+/* Branch containing goto is probably not taken.  */
+DEF_PREDICTOR (PRED_GOTO, "goto", HITRATE (66), 0)
 
 /* Branch ending with return constant is probably not taken.  */
 DEF_PREDICTOR (PRED_CONST_RETURN, "const return", HITRATE (69), 0)
index 68ef6fc9365b8a93d403edc4f884413031f7d5cb..7243fdf337208a456b1512db7f10a3144b91e6c8 100644 (file)
@@ -1,3 +1,9 @@
+2017-07-31  Jan Hubicka <hubicka@ucw.cz>
+           Martin Liska  <mliska@suse.cz>
+
+       * gcc.dg/predict-15.c: New test.
+       * gcc.dg/tree-ssa/vrp24.c: Update scanned pattern.
+
 2017-07-31  Uros Bizjak  <ubizjak@gmail.com>
 
        PR target/25967
diff --git a/gcc/testsuite/gcc.dg/predict-15.c b/gcc/testsuite/gcc.dg/predict-15.c
new file mode 100644 (file)
index 0000000..2a8c3ea
--- /dev/null
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-profile_estimate" } */
+
+int main(int argc, char **argv)
+{
+  if (argc == 123)
+    goto exit;
+  else
+    {
+      return 0;
+    }
+
+exit:
+  return 1;
+}
+
+/* { dg-final { scan-tree-dump "goto heuristics of edge" "profile_estimate"} } */
index 5f7e3afa2ae6caeb9b784ed2e5966bf75a904faa..17526113d4b65b1a3d87a2ebab1b476ed64179fa 100644 (file)
@@ -1,8 +1,7 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-profile_estimate-blocks-details" } */
+/* { dg-options "-O2 -fdump-tree-profile_estimate" } */
 
-void g(void);
-void h(void);
+int v1, v2;
 void f(int x, int y)
 {
   if (x) goto A;
@@ -10,11 +9,11 @@ void f(int x, int y)
   return;
 
  A: __attribute__((cold))
-  g();
+  v1 = x;
   return;
 
  B: __attribute__((hot))
-  h();
+  v2 = y;
   return;
 }
 
index 853ee21bb8f515099c1205f1b21266129b250606..ed49e25f87a9ccf49a6e420821263509c80d3df5 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fno-tree-forwprop -fdump-tree-vrp1-details" } */
+/* { dg-options "-O2 -fno-tree-forwprop -fdump-tree-vrp1-details -fdump-tree-optimized" } */
 
 
 struct rtx_def;
@@ -86,10 +86,8 @@ L7:
 
 /* The first n_sets > 0 test can be simplfiied into n_sets == 1 since
    n_sets can only have the values [0, 1] as it's the result of a
-   boolean operation.
+   boolean operation.  */
 
-   The second n_sets > 0 test can also be simplified into n_sets == 1
-   as the only way to reach the tests is when n_sets <= 1 and the only
-   value which satisfies both conditions is n_sets == 1.  */
-/* { dg-final { scan-tree-dump-times "Simplified relational" 2 "vrp1" } } */
+/* { dg-final { scan-tree-dump-times "Simplified relational" 1 "vrp1" } } */
+/* { dg-final { scan-tree-dump-times "if " 4 "optimized" } } */