From patchwork Thu Nov 16 16:56:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 838684 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-467015-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="tYueSsa4"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yd6ph24fhz9ryv for ; Fri, 17 Nov 2017 03:56:43 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=QQ+ZYn3DMPBgNHEgIAmNvLmDB130wuKtAOu5fPzZaTvMc60+yrKlb XzY1VM5VIdtv5ymenfAW1urOUSzXXQIqD60EeIdqOuTvXDGIGCPgxeQkG+/4CudC /+VXA11vXXf8V6Vy62fH42NgkC3aAM2TVi4dEcNNWGs3cxswHnVaM4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=hk66Cs3CZT4cMUkKy+oKoKKW3Ic=; b=tYueSsa4zZHKrcs1S6Hu OlMfTbVLsnamc2F2pBXmxIT53NYTc7oMQSai2mPvnjoLWFjz4F9gK9TsVAAz74jb ZbI3UcHC9U9NG1w9qYFvgouybTmeyIiKVxKNZs6duZFhAqDxhX3hA7GA7gbsH+zZ +2Vxv/4MTisvhbgkyu4Dk2Y= Received: (qmail 62634 invoked by alias); 16 Nov 2017 16:56:33 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 62612 invoked by uid 89); 16 Nov 2017 16:56:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-9.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, KAM_NUMSUBJECT, KB_WAM_FROM_NAME_SINGLEWORD, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=254812, sk:expensi, 34987, eges 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; Thu, 16 Nov 2017 16:56:32 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id C9B2654886F; Thu, 16 Nov 2017 17:56:29 +0100 (CET) Date: Thu, 16 Nov 2017 17:56:29 +0100 From: Jan Hubicka To: gcc-patches@gcc.gnu.org Subject: Set edges to region known to be executed 0 times to have probability 0 Message-ID: <20171116165629.GE76038@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) Hi, this patch fixes one profilemismatch issue in testsuite where we end up with non-zero probability with edge to BB calling abort. When detecting regions known to be executed 0 times, we should also set edges leading to them to be executed 0 times. The other change makes combine_predictions_for_bb to preserve this information even if static branch prediction thinks otherwise. Finally I noticed one unnecesary assert and fact htat I forgot to add call to propagate_unlikely_bbs_forward while breaking it out of propagate_unlikely_bbs. Bootstrapped/regtested x86_64-linux, comitted. * predict.c (combine_predictions_for_bb): Preserve zero predicted eges. (expensive_function_p): Remove useless assert. (determine_unlikely_bbs): Propagate also forward; determine cold blocks Index: predict.c =================================================================== --- predict.c (revision 254812) +++ predict.c (working copy) @@ -1118,18 +1118,26 @@ combine_predictions_for_bb (basic_block int nedges = 0; edge e, first = NULL, second = NULL; edge_iterator ei; + int nzero = 0; + int nunknown = 0; FOR_EACH_EDGE (e, ei, bb->succs) - if (!unlikely_executed_edge_p (e)) - { - nedges ++; - if (first && !second) - second = e; - if (!first) - first = e; - } - else if (!e->probability.initialized_p ()) - e->probability = profile_probability::never (); + { + if (!unlikely_executed_edge_p (e)) + { + nedges ++; + if (first && !second) + second = e; + if (!first) + first = e; + } + else if (!e->probability.initialized_p ()) + e->probability = profile_probability::never (); + if (!e->probability.initialized_p ()) + nunknown++; + else if (e->probability == profile_probability::never ()) + nzero++; + } /* When there is no successor or only one choice, prediction is easy. @@ -1283,8 +1291,27 @@ combine_predictions_for_bb (basic_block } clear_bb_predictions (bb); - if ((!bb->count.nonzero_p () || !first->probability.initialized_p ()) - && !dry_run) + + /* If we have only one successor which is unknown, we can compute missing + probablity. */ + if (nunknown == 1) + { + profile_probability prob = profile_probability::always (); + edge missing = NULL; + + FOR_EACH_EDGE (e, ei, bb->succs) + if (e->probability.initialized_p ()) + prob -= e->probability; + else if (missing == NULL) + missing = e; + else + gcc_unreachable (); + missing->probability = prob; + } + /* If nothing is unknown, we have nothing to update. */ + else if (!nunknown && nzero != (int)EDGE_COUNT (bb->succs)) + ; + else if (!dry_run) { first->probability = profile_probability::from_reg_br_prob_base (combined_probability); @@ -3334,16 +3361,11 @@ expensive_function_p (int threshold) { basic_block bb; - /* We can not compute accurately for large thresholds due to scaled - frequencies. */ - gcc_assert (threshold <= BB_FREQ_MAX); - /* If profile was scaled in a way entry block has count 0, then the function is deifnitly taking a lot of time. */ if (!ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.nonzero_p ()) return true; - /* Maximally BB_FREQ_MAX^2 so overflow won't happen. */ profile_count limit = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.apply_scale (threshold, 1); profile_count sum = profile_count::zero (); @@ -3453,6 +3475,7 @@ determine_unlikely_bbs () gcc_checking_assert (!bb->aux); } + propagate_unlikely_bbs_forward (); auto_vec nsuccs; nsuccs.safe_grow_cleared (last_basic_block_for_fn (cfun)); @@ -3498,7 +3521,6 @@ determine_unlikely_bbs () FOR_EACH_EDGE (e, ei, bb->preds) if (!(e->probability == profile_probability::never ())) { - e->probability = profile_probability::never (); if (!(e->src->count == profile_count::zero ())) { nsuccs[e->src->index]--; @@ -3507,6 +3529,19 @@ determine_unlikely_bbs () } } } + /* Finally all edges from non-0 regions to 0 are unlikely. */ + FOR_ALL_BB_FN (bb, cfun) + if (!(bb->count == profile_count::zero ())) + FOR_EACH_EDGE (e, ei, bb->succs) + if (!(e->probability == profile_probability::never ()) + && e->dest->count == profile_count::zero ()) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, "Edge %i->%i is unlikely because " + "it enters unlikely block\n", + bb->index, e->dest->index); + e->probability = profile_probability::never (); + } } /* Estimate and propagate basic block frequencies using the given branch