From patchwork Wed Nov 20 16:45:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 1198330 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-514193-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="VL3HJSHe"; 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 47J7qL6GMmz9sPW for ; Thu, 21 Nov 2019 03:45:49 +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=IMcg03K4HutWnOIAspTVIKN2qHkaoQxSDKhIe0eHFjHmmilAM8MoM P6DPVSWSEXofoFHGLrhiNz+ZsQ+jfCKG+l6qindncsZW1HAos67aSqaPnHTWdkE5 GC/vTitEQ53ho4D63O8fHr8ERhbrrM2/riKulYyBv81/YBPU4e0wmg= 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=97/FLCocB7/y5Ohu2+M70ytDlB8=; b=VL3HJSHeE0LinSy8M7A1 wXi9swLduKYzySE4gQ7M7gtniMEkFHtnUIyrp5A1/a8pZQMnSCKN0IKTdQR9NHoK /9dncLp1RD3GK3Sem1PsdEGC4yKmYADi2OkK+5f7m9S25HG64OFTAhIY9hzm7xLv NquYvO7UOGMRbbQ3CVlCJi4= Received: (qmail 117413 invoked by alias); 20 Nov 2019 16:45:41 -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 117049 invoked by uid 89); 20 Nov 2019 16:45:23 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=heuristics, updated_nodes, sk:reset_e, overall_size 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; Wed, 20 Nov 2019 16:45:15 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 73174288028; Wed, 20 Nov 2019 17:45:10 +0100 (CET) Date: Wed, 20 Nov 2019 17:45:10 +0100 From: Jan Hubicka To: gcc-patches@gcc.gnu.org Subject: Fix (most of) nonlinearity in update_callee_keys Message-ID: <20191120164510.tkcriaelq6wfq73c@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20170113 (1.7.2) Hi, this patch makes inliner to update callee keys only in function within newly inlined clone rather than in the whole function it is inlined to. This is possible only when the remaining edges are not becoming more hot for inlining and on this I rely on monotonocity of the badness function: if caller gets bigger and slower the call is not becoming hotter. This is not true when wrapper penalty is applied and thus a special case is needed. Bootstrapped/regtested x86_64-linux, comitted. Honza * ipa-inline.c (wrapper_heuristics_may_apply): Break out from ... (edge_badness): ... here. (inline_small_functions): Use monotonicity of badness calculation to avoid redundant updates. Index: ipa-inline.c =================================================================== --- ipa-inline.c (revision 278459) +++ ipa-inline.c (working copy) @@ -1097,6 +1097,17 @@ want_inline_function_to_all_callers_p (s return true; } +/* Return true if WHERE of SIZE is a possible candidate for wrapper heuristics + in estimate_edge_badness. */ + +static bool +wrapper_heuristics_may_apply (struct cgraph_node *where, int size) +{ + return size < (DECL_DECLARED_INLINE_P (where->decl) + ? inline_insns_single (where, false) + : inline_insns_auto (where, false)); +} + /* A cost model driving the inlining heuristics in a way so the edges with smallest badness are inlined first. After each inlining is performed the costs of all caller edges of nodes affected are recomputed so the @@ -1227,10 +1238,8 @@ edge_badness (struct cgraph_edge *edge, and it is not called once. */ if (!caller_info->single_caller && overall_growth < caller_growth && caller_info->inlinable - && ipa_size_summaries->get (caller)->size - < (DECL_DECLARED_INLINE_P (caller->decl) - ? inline_insns_single (caller, false) - : inline_insns_auto (caller, false))) + && wrapper_heuristics_may_apply + (caller, ipa_size_summaries->get (caller)->size)) { if (dump) fprintf (dump_file, @@ -2158,11 +2167,24 @@ inline_small_functions (void) fprintf (dump_file, " Peeling recursion with depth %i\n", depth); gcc_checking_assert (!callee->inlined_to); + + int old_size = ipa_size_summaries->get (where)->size; + sreal old_time = ipa_fn_summaries->get (where)->time; + inline_call (edge, true, &new_indirect_edges, &overall_size, true); reset_edge_caches (edge->callee); add_new_edges_to_heap (&edge_heap, new_indirect_edges); - update_callee_keys (&edge_heap, where, updated_nodes); + /* If caller's size and time increased we do not need to update + all edges becuase badness is not going to decrease. */ + if (old_size <= ipa_size_summaries->get (where)->size + && old_time <= ipa_fn_summaries->get (where)->time + /* Wrapper penalty may be non-monotonous in this respect. + Fortunately it only affects small functions. */ + && !wrapper_heuristics_may_apply (where, old_size)) + update_callee_keys (&edge_heap, edge->callee, updated_nodes); + else + update_callee_keys (&edge_heap, where, updated_nodes); } where = edge->caller; if (where->inlined_to)