re PR middle-end/65950 (exit in main is causing the path to it to become unlikely.)
authorAndrew Pinski <apinski@cavium.com>
Tue, 18 Oct 2016 15:42:21 +0000 (15:42 +0000)
committerAndrew Pinski <pinskia@gcc.gnu.org>
Tue, 18 Oct 2016 15:42:21 +0000 (08:42 -0700)
2016-10-18  Andrew Pinski  <apinski@cavium.com>

        PR tree-opt/65950
        * predict.c (is_exit_with_zero_arg): New function.
        (tree_bb_level_predictions): Don't consider paths leading to exit(0)
        as nottaken.

From-SVN: r241309

gcc/ChangeLog
gcc/predict.c

index 5fc85caaf7d45e337f4375241bc64ead326bf7ef..0b08748b9c1d00f4e3d5428bb2d12e422dcc5c68 100644 (file)
@@ -1,3 +1,10 @@
+2016-10-18  Andrew Pinski  <apinski@cavium.com>
+
+       PR tree-opt/65950
+       * predict.c (is_exit_with_zero_arg): New function.
+       (tree_bb_level_predictions): Don't consider paths leading to exit(0)
+       as nottaken.
+
 2016-10-18  Uros Bizjak  <ubizjak@gmail.com>
 
        PR target/77991
index 9950c095cc0217f8188a7f1592567e9efe649c8b..1bf04d18c1c70848b58febff517ba28aa5916be5 100644 (file)
@@ -2512,6 +2512,21 @@ tree_predict_by_opcode (basic_block bb)
       }
 }
 
+/* Returns TRUE if the STMT is exit(0) like statement. */
+
+static bool
+is_exit_with_zero_arg (const gimple *stmt)
+{
+  /* This is not exit, _exit or _Exit. */
+  if (!gimple_call_builtin_p (stmt, BUILT_IN_EXIT)
+      && !gimple_call_builtin_p (stmt, BUILT_IN__EXIT)
+      && !gimple_call_builtin_p (stmt, BUILT_IN__EXIT2))
+    return false;
+
+  /* Argument is an interger zero. */
+  return integer_zerop (gimple_call_arg (stmt, 0));
+}
+
 /* Try to guess whether the value of return means error code.  */
 
 static enum br_predictor
@@ -2638,7 +2653,9 @@ tree_bb_level_predictions (void)
 
          if (is_gimple_call (stmt))
            {
-             if (gimple_call_noreturn_p (stmt) && has_return_edges)
+             if (gimple_call_noreturn_p (stmt)
+                 && has_return_edges
+                 && !is_exit_with_zero_arg (stmt))
                predict_paths_leading_to (bb, PRED_NORETURN,
                                          NOT_TAKEN);
              decl = gimple_call_fndecl (stmt);