From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18530 invoked by alias); 12 Sep 2012 14:38:07 -0000 Received: (qmail 18364 invoked by uid 22791); 12 Sep 2012 14:38:05 -0000 X-SWARE-Spam-Status: No, hits=-4.3 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,KHOP_THREADED X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 12 Sep 2012 14:37:52 +0000 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/54493] -fguess-branch-probability takes ages Date: Wed, 12 Sep 2012 14:38:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Keywords: compile-time-hog X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-09/txt/msg00933.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54493 --- Comment #2 from Richard Guenther 2012-09-12 14:37:51 UTC --- Something like Index: gcc/predict.c =================================================================== --- gcc/predict.c (revision 191222) +++ gcc/predict.c (working copy) @@ -525,8 +525,9 @@ void gimple_predict_edge (edge e, enum br_predictor predictor, int probability) { gcc_assert (profile_status != PROFILE_GUESSED); - if ((e->src != ENTRY_BLOCK_PTR && EDGE_COUNT (e->src->succs) > 1) - && flag_guess_branch_prob && optimize) + if (flag_guess_branch_prob && optimize + && (e->src != ENTRY_BLOCK_PTR && EDGE_COUNT (e->src->succs) > 1) + && !gimple_predicted_by_p (e->src, predictor)) { struct edge_prediction *i = XNEW (struct edge_prediction); void **preds = pointer_map_insert (bb_predictions, e->src); of course that doesn't try to merge the predictors probability nor the edge it is for. Why are the predictors stored per block and not per edge? Another approach would be to fix this special case: && gimple_code (last) == GIMPLE_RETURN) { edge e1; edge_iterator ei1; if (single_succ_p (bb)) { FOR_EACH_EDGE (e1, ei1, bb->preds) if (!predicted_by_p (e1->src, PRED_NULL_RETURN) && !predicted_by_p (e1->src, PRED_CONST_RETURN) && !predicted_by_p (e1->src, PRED_NEGATIVE_RETURN)) predict_edge_def (e1, PRED_TREE_EARLY_RETURN, NOT_TAKEN); which ends up adding all those (bogus?!) predications to the entry block. Simplified we have foo (int a, int b, int c) { int d; : switch (a_2(D)) , case 10: , ... : d_5 = a_2(D) + b_4(D); goto (); ... : d_14 = a_2(D) + b_4(D); # d_1 = PHI : return d_1; and we are adding the loads of !PRED_TREE_EARLY_RETURN to bb 2. Thus as we are only adding PRED_TREE_EARLY_RETURN at this point we can also do @@ -2113,13 +2113,15 @@ tree_estimate_probability_bb (basic_bloc FOR_EACH_EDGE (e1, ei1, bb->preds) if (!predicted_by_p (e1->src, PRED_NULL_RETURN) && !predicted_by_p (e1->src, PRED_CONST_RETURN) - && !predicted_by_p (e1->src, PRED_NEGATIVE_RETURN)) + && !predicted_by_p (e1->src, PRED_NEGATIVE_RETURN) + && !predicted_by_p (e1->src, PRED_TREE_EARLY_RETURN)) predict_edge_def (e1, PRED_TREE_EARLY_RETURN, NOT_TAKEN); } else if (!predicted_by_p (e->src, PRED_NULL_RETURN) && !predicted_by_p (e->src, PRED_CONST_RETURN) - && !predicted_by_p (e->src, PRED_NEGATIVE_RETURN)) + && !predicted_by_p (e->src, PRED_NEGATIVE_RETURN) + && !predicted_by_p (e->src, PRED_TREE_EARLY_RETURN)) predict_edge_def (e, PRED_TREE_EARLY_RETURN, NOT_TAKEN); } (those predicted_by_p sequences are also inefficient as they repeat the linear walk ...) Honza?