From patchwork Mon Dec 24 01:36:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 1018166 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-493077-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ucw.cz Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="l3YYv1oO"; 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 43NMJk5l9Sz9sDT for ; Mon, 24 Dec 2018 12:36:21 +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=gnJ/GefjT5tQt0vL8ahKy1l+BtD+d7GU5JR9ukqkzUFpF+K9Vnv6O bCLnZgpQfbcUSIURq/kc/cT3AbvKlvnT8o+ICWpxd0X+Y4AmJylBtlvFwHrUwLDy jfF0/rHRaSfz0DiBrsfHfV9vsw9469T/npF4t8SxH9a9M1UuUGt/N0= 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=TPzbChr1t5WR/rnj2QNyEbNGEic=; b=l3YYv1oOsn2tiqM7lftR 1WBxB1BeeDAXp3CP2eG/ozipjFVCvrPhOC+3BsGQkUH4L8uHPnPF1CUuyh9cz8da NBXeoKEWD8DG1+BPN12eDJi0AJqaNvP8eMHJdKm/7m4GRpv6qi1yAxlUW1LMNV0r r1Q8sArj6dslI/boWxM02Kk= Received: (qmail 130724 invoked by alias); 24 Dec 2018 01:36:13 -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 130702 invoked by uid 89); 24 Dec 2018 01:36:11 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY autolearn=ham version=3.3.2 spammy=sk:specula, regtested, ipautilsc, cfg 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; Mon, 24 Dec 2018 01:36:08 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 5509C280504; Mon, 24 Dec 2018 02:36:05 +0100 (CET) Date: Mon, 24 Dec 2018 02:36:05 +0100 From: Jan Hubicka To: gcc-patches@gcc.gnu.org Subject: Fix summary update after profile merging Message-ID: <20181224013605.fcwvvt4yb3dqgn3j@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20170113 (1.7.2) Hi, while looking into Firefox inline dumps I noticed that my previous patch was not quite enough to get inline summaries right. The problem is that we may have speculative edges from profile feedback and also it does happen that profiles mismatch and we should handle it better. This patch fixes the problem in more robust way. Bootstrapped/regtested x86_64-linux and also tested with firefox, will commit it shortly. Honza * ipa-utils.c (ipa_merge_profiles): Fix updating of fnsummary; also handle rescaling of mismatched profiles. * ipa-fnsummary.c (analyze_function): Handle speculative edges. Index: ipa-utils.c =================================================================== --- ipa-utils.c (revision 267377) +++ ipa-utils.c (working copy) @@ -392,6 +392,7 @@ if (!src->definition || !dst->definition) return; + if (src->frequency < dst->frequency) src->frequency = dst->frequency; @@ -416,6 +417,8 @@ fprintf (symtab->dump_file, "Merging profiles of %s to %s\n", src->dump_name (), dst->dump_name ()); } + profile_count orig_count = dst->count; + if (dst->count.initialized_p () && dst->count.ipa () == dst->count) dst->count += src->count.ipa (); else @@ -644,10 +647,21 @@ if (!preserve_body) src->release_body (); /* Update summary. */ - symtab->call_cgraph_removal_hooks (dst); - symtab->call_cgraph_insertion_hooks (dst); + compute_fn_summary (dst, 0); } - /* TODO: if there is no match, we can scale up. */ + /* We can't update CFG profile, but we can scale IPA profile. CFG + will be scaled according to dst->count after IPA passes. */ + else + { + profile_count to = dst->count; + profile_count::adjust_for_ipa_scaling (&to, &orig_count); + struct cgraph_edge *e; + + for (e = dst->callees; e; e = e->next_callee) + e->count = e->count.apply_scale (to, orig_count); + for (e = dst->indirect_calls; e; e = e->next_callee) + e->count = e->count.apply_scale (to, orig_count); + } src->decl = oldsrcdecl; } Index: ipa-fnsummary.c =================================================================== --- ipa-fnsummary.c (revision 267377) +++ ipa-fnsummary.c (working copy) @@ -2180,6 +2180,17 @@ es->call_stmt_time = this_time; es->loop_depth = bb_loop_depth (bb); edge_set_predicate (edge, &bb_predicate); + if (edge->speculative) + { + cgraph_edge *direct, *indirect; + ipa_ref *ref; + edge->speculative_call_info (direct, indirect, ref); + gcc_assert (direct == edge); + ipa_call_summary *es2 + = ipa_call_summaries->get_create (indirect); + ipa_call_summaries->duplicate (edge, indirect, + es, es2); + } } /* TODO: When conditional jump or swithc is known to be constant, but @@ -2491,7 +2502,8 @@ ipa_update_overall_fn_summary but because computation happens in different order the roundoff errors result in slight changes. */ ipa_update_overall_fn_summary (node); - gcc_assert (info->size == info->self_size); + /* In LTO mode we may have speculative edges set. */ + gcc_assert (in_lto_p || info->size == info->self_size); }