From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 125516 invoked by alias); 13 Jun 2017 10:59:59 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 125483 invoked by uid 89); 13 Jun 2017 10:59:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 13 Jun 2017 10:59:56 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 292AFADF1; Tue, 13 Jun 2017 10:59:58 +0000 (UTC) Subject: Re: [PATCH 2/3] Make early return predictor more precise. To: Jan Hubicka Cc: gcc-patches@gcc.gnu.org References: <20170609140804.GI53583@kam.mff.cuni.cz> From: =?UTF-8?Q?Martin_Li=c5=a1ka?= Message-ID: Date: Tue, 13 Jun 2017 10:59:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1 MIME-Version: 1.0 In-Reply-To: <20170609140804.GI53583@kam.mff.cuni.cz> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2017-06/txt/msg00896.txt.bz2 On 06/09/2017 04:08 PM, Jan Hubicka wrote: >> gcc/ChangeLog: >> >> 2017-05-26 Martin Liska >> >> PR tree-optimization/79489 >> * gimplify.c (maybe_add_early_return_predict_stmt): New >> function. >> (gimplify_return_expr): Call the function. >> * predict.c (tree_estimate_probability_bb): Remove handling >> of early return. >> * predict.def: Update comment about early return predictor. >> * gimple-predict.h (is_gimple_predict): New function. >> * tree-inline.c (remap_gimple_stmt): Do not copy early return >> predictors during inlining. >> * predict.def: Change default value of early return to 66. > > Thanks for working on this. > Doing tail recursion early is quite useful. Can't we make the pass to > skip predict statements in analysis similar was as debug statements are > skipped? Hi. Yes, this was easy to fix, skipping here helps. >> diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c >> index f3ec404ef09..3f3813cb062 100644 >> --- a/gcc/tree-inline.c >> +++ b/gcc/tree-inline.c >> @@ -1629,6 +1629,13 @@ remap_gimple_stmt (gimple *stmt, copy_body_data *id) >> gimple_seq_add_stmt (&stmts, copy); >> return stmts; >> } >> + if (is_gimple_predict (stmt)) >> + { >> + /* Do not copy early return predictor that does not make sense >> + after inlining. */ >> + if (gimple_predict_predictor (stmt) == PRED_TREE_EARLY_RETURN) >> + return stmts; >> + } > > I am also not quite sure about this one. The code was still structured in a way > there was early return in the inlined function, so we may still assume that > the heuristic works for it? Ok, you're right that we can preserve the predictor. However, let's consider following test-case: static int baz(int a) { if (a == 1) return 1; return 0; } static int bar(int a) { if (a == 1) return baz(a); return 0; } static int foo(int a) { if (a == 1) return bar(a); return 12; } int main(int argc, char **argv) { return foo(argc); } There after einline we have: main (int argc, char * * argv) { int D.1832; int _3; int _4; [100.00%]: if (argc_2(D) == 1) goto ; [37.13%] else goto ; [62.87%] [37.13%]: // predicted unlikely by early return (on trees) predictor. // predicted unlikely by early return (on trees) predictor. // predicted unlikely by early return (on trees) predictor. [100.00%]: # _3 = PHI <12(2), 1(3)> _5 = _3; _4 = _5; return _4; } I'm thinking what's the best place to merge all the predictor statements? Thanks, Martin > > Where did you found this case? > Honza >> >> /* Create a new deep copy of the statement. */ >> copy = gimple_copy (stmt); >> -- >> 2.13.0 >>