From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32016 invoked by alias); 16 Jun 2017 17:47:45 -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 31990 invoked by uid 89); 16 Jun 2017 17:47:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.1 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=Hx-languages-length:2469, sum 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; Fri, 16 Jun 2017 17:47:43 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 44395546A4F; Fri, 16 Jun 2017 19:47:46 +0200 (CEST) Date: Fri, 16 Jun 2017 17:47:00 -0000 From: Jan Hubicka To: gcc-patches@gcc.gnu.org Subject: Fix profile update in tail merging Message-ID: <20170616174746.GF59896@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-SW-Source: 2017-06/txt/msg01228.txt.bz2 Hi, profile updating in tail merging is completely wrong when profile feedback is missing or 0. This fixes it hopefully reasonably. Bootstrapped/regtested x86_64-linux. Honza * tree-ssa-tail-merge.c (replace_block_by): Fix profile updating. Index: tree-ssa-tail-merge.c =================================================================== --- tree-ssa-tail-merge.c (revision 249244) +++ tree-ssa-tail-merge.c (working copy) @@ -1555,29 +1555,51 @@ replace_block_by (basic_block bb1, basic pred_edge, UNKNOWN_LOCATION); } - bb2->frequency += bb1->frequency; - if (bb2->frequency > BB_FREQ_MAX) - bb2->frequency = BB_FREQ_MAX; - bb2->count += bb1->count; /* Merge the outgoing edge counts from bb1 onto bb2. */ profile_count out_sum = profile_count::zero (); + int out_freq_sum = 0; + + /* Recompute the edge probabilities from the new merged edge count. + Use the sum of the new merged edge counts computed above instead + of bb2's merged count, in case there are profile count insanities + making the bb count inconsistent with the edge weights. */ + FOR_EACH_EDGE (e1, ei, bb1->succs) + { + if (e1->count.initialized_p ()) + out_sum += e1->count; + out_freq_sum += EDGE_FREQUENCY (e1); + } + FOR_EACH_EDGE (e1, ei, bb2->succs) + { + if (e1->count.initialized_p ()) + out_sum += e1->count; + out_freq_sum += EDGE_FREQUENCY (e1); + } + FOR_EACH_EDGE (e1, ei, bb1->succs) { e2 = find_edge (bb2, e1->dest); gcc_assert (e2); e2->count += e1->count; + if (out_sum > 0 && e2->count.initialized_p ()) + { + e2->probability = e2->count.probability_in (bb2->count); + } + else if (bb1->frequency && bb2->frequency) + e2->probability = e1->probability; + else if (bb2->frequency && !bb1->frequency) + ; + else if (out_freq_sum) + e2->probability = GCOV_COMPUTE_SCALE (EDGE_FREQUENCY (e1) + + EDGE_FREQUENCY (e2), + out_freq_sum); out_sum += e2->count; } - /* Recompute the edge probabilities from the new merged edge count. - Use the sum of the new merged edge counts computed above instead - of bb2's merged count, in case there are profile count insanities - making the bb count inconsistent with the edge weights. */ - FOR_EACH_EDGE (e2, ei, bb2->succs) - { - e2->probability = e2->count.probability_in (out_sum); - } + bb2->frequency += bb1->frequency; + if (bb2->frequency > BB_FREQ_MAX) + bb2->frequency = BB_FREQ_MAX; /* Move over any user labels from bb1 after the bb2 labels. */ gimple_stmt_iterator gsi1 = gsi_start_bb (bb1);