From patchwork Thu Nov 28 17:02:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 1202226 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-514784-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="A6getmxG"; 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 47P3pg6wQ6z9sP4 for ; Fri, 29 Nov 2019 04:02:19 +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=FjwvanFNj/VKo2/Bs3Hb0mJe7S9nmnaTdxAWcLZUS86eEr3vjExSj 1+SO1LMlaWtp18ybyNW49NbySOhyoqCS132KelLGbRVafx1v+ytSIGQN93bFUelh 9DcWAnWi5Ny+CisBjXerFOlxoilXnh+LyMcFONAOvuf+tVreCewUKM= 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=WWBUD9hduLkPKPuceENcwyiVWkw=; b=A6getmxGecMpf/jxk1th 7Z6AKomgdJlosPRnG0hR3072NnBalVit3WFeoAgsOOiB/iJY24hfas+42BOGkWSj tmd+cdI4Vox1yogp6BFq0usXQv01mY8v4dRW9MVihX47xAw6HamHwLUm5Hlf14WM NNx+dnyb7c1bqSDdNNv2qis= Received: (qmail 2642 invoked by alias); 28 Nov 2019 17:02: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 2631 invoked by uid 89); 28 Nov 2019 17:02:12 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=cfun, profiles 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, 28 Nov 2019 17:02:10 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 50A4E280823; Thu, 28 Nov 2019 18:02:08 +0100 (CET) Date: Thu, 28 Nov 2019 18:02:08 +0100 From: Jan Hubicka To: gcc-patches@gcc.gnu.org Subject: Prevent inconsistent profiles to be created in inline_transform Message-ID: <20191128170208.hkoedy6ttsfi2cve@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20170113 (1.7.2) Hi, ipa-inline-transforms first applies edge redirection and then scales profile. For some reason cgraph_edge::redirect_call_stmt_to_callee copies bb's count into callgraph edge count. This leads to inconsistency because cfg profile is before scaling at this point. Fixed thus. profilebootstrapped/regtested x86_64-linux, comitted. * ipa-inline-transform.c (inline_transform): Scale profile before redirecting. Index: ipa-inline-transform.c =================================================================== --- ipa-inline-transform.c (revision 278811) +++ ipa-inline-transform.c (working copy) @@ -681,6 +681,31 @@ inline_transform (struct cgraph_node *no if (preserve_function_body_p (node)) save_inline_function_body (node); + profile_count num = node->count; + profile_count den = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count; + bool scale = num.initialized_p () && !(num == den); + if (scale) + { + profile_count::adjust_for_ipa_scaling (&num, &den); + if (dump_file) + { + fprintf (dump_file, "Applying count scale "); + num.dump (dump_file); + fprintf (dump_file, "/"); + den.dump (dump_file); + fprintf (dump_file, "\n"); + } + + basic_block bb; + cfun->cfg->count_max = profile_count::uninitialized (); + FOR_ALL_BB_FN (bb, cfun) + { + bb->count = bb->count.apply_scale (num, den); + cfun->cfg->count_max = cfun->cfg->count_max.max (bb->count); + } + ENTRY_BLOCK_PTR_FOR_FN (cfun)->count = node->count; + } + for (e = node->callees; e; e = next) { if (!e->inline_failed) @@ -693,32 +718,8 @@ inline_transform (struct cgraph_node *no timevar_push (TV_INTEGRATION); if (node->callees && (opt_for_fn (node->decl, optimize) || has_inline)) { - profile_count num = node->count; - profile_count den = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count; - bool scale = num.initialized_p () && !(num == den); - if (scale) - { - profile_count::adjust_for_ipa_scaling (&num, &den); - if (dump_file) - { - fprintf (dump_file, "Applying count scale "); - num.dump (dump_file); - fprintf (dump_file, "/"); - den.dump (dump_file); - fprintf (dump_file, "\n"); - } - - basic_block bb; - cfun->cfg->count_max = profile_count::uninitialized (); - FOR_ALL_BB_FN (bb, cfun) - { - bb->count = bb->count.apply_scale (num, den); - cfun->cfg->count_max = cfun->cfg->count_max.max (bb->count); - } - ENTRY_BLOCK_PTR_FOR_FN (cfun)->count = node->count; - } todo = optimize_inline_calls (current_function_decl); - } + } timevar_pop (TV_INTEGRATION); cfun->always_inline_functions_inlined = true;