From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 93181 invoked by alias); 7 Aug 2018 12:23:49 -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 93168 invoked by uid 89); 7 Aug 2018 12:23:48 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY autolearn=no version=3.3.2 spammy=percent, 20180724, 2018-07-24 X-HELO: nikam.ms.mff.cuni.cz Received: from nikam.ms.mff.cuni.cz (HELO nikam.ms.mff.cuni.cz) (195.113.20.16) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 07 Aug 2018 12:23:47 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 29A24541DB7; Tue, 7 Aug 2018 14:23:45 +0200 (CEST) Date: Tue, 07 Aug 2018 12:23:00 -0000 From: Jan Hubicka To: Martin =?iso-8859-2?Q?Li=B9ka?= Cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] Introduce __builtin_expect_with_probability (PR target/83610). Message-ID: <20180807122345.GB86326@kam.mff.cuni.cz> References: <20180731092407.GF29444@kam.mff.cuni.cz> <905756a5-4479-bf8e-cb59-ebdf26001729@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <905756a5-4479-bf8e-cb59-ebdf26001729@suse.cz> User-Agent: Mutt/1.5.23 (2014-03-12) X-SW-Source: 2018-08/txt/msg00480.txt.bz2 > 2018-07-24 Martin Liska > > PR target/83610 > * builtin-types.def (BT_FN_LONG_LONG_LONG_DOUBLE): New type. > * builtins.c (expand_builtin_expect_with_probability): > New function. > (expand_builtin): Handle also BUILT_IN_EXPECT_WITH_PROBABILITY. > (build_builtin_expect_predicate): Likewise. > (fold_builtin_expect): Likewise. > (fold_builtin_2): Likewise. > (fold_builtin_3): Likewise. > * builtins.def (BUILT_IN_EXPECT_WITH_PROBABILITY): Define new > builtin. > * builtins.h (fold_builtin_expect): Add new argument > (probability). > * doc/extend.texi: Document the new builtin. > * doc/invoke.texi: Likewise. > * gimple-fold.c (gimple_fold_call): Pass new argument. > * ipa-fnsummary.c (find_foldable_builtin_expect): > Handle also BUILT_IN_EXPECT_WITH_PROBABILITY. > * predict.c (expr_expected_value): Add new out argument which > is probability. > (expr_expected_value_1): Likewise. > (tree_predict_by_opcode): Predict edge based on > provided probability. > (pass_strip_predict_hints::execute): Use newly added > DECL_BUILT_IN_P macro. > * predict.def (PRED_BUILTIN_EXPECT_WITH_PROBABILITY): > Define new predictor. > * tree.h (DECL_BUILT_IN_P): Define. > > gcc/testsuite/ChangeLog: > > 2018-07-24 Martin Liska > > * gcc.dg/predict-16.c: New test. > * gcc.dg/predict-17.c: New test. OK > +@deftypefn {Built-in Function} long __builtin_expect_with_probability > +(long @var{exp}, long @var{c}, long @var{probability}) > + > +The built-in has same semantics as @code{__builtin_expect_with_probability}, > +but user can provide expected probability (in percent) for value of @var{exp}. > +Last argument @var{probability} is of flaot type and valid values flaot->float :) > @@ -2426,10 +2444,10 @@ expr_expected_value_1 (tree type, tree op0, enum tree_code code, > { > tree res; > enum br_predictor predictor2; > - op0 = expr_expected_value (op0, visited, predictor); > + op0 = expr_expected_value (op0, visited, predictor, probability); > if (!op0) > return NULL; > - op1 = expr_expected_value (op1, visited, &predictor2); > + op1 = expr_expected_value (op1, visited, &predictor2, probability); > if (predictor && *predictor < predictor2) > *predictor = predictor2; > if (!op1) Here you need to combine probabilities together. I would probably convert it early into profile_probability type (at the time builtin is handled) because then combination is better defined. If probability is known only over one path I guess you will need to turn predictor into probability and then do the combination. The predictor combining logic simply takes the weaker one (assumes that they are all first match), perhaps with probability one can just combine probabilties and throw away predictor info in this case. It would be still very nice to arrange loop code to set loop->nb_iterations_estimate accordingly in this case. That would be useful for loop opts as reliable hint that number of iterations is about that much. Honza