From patchwork Thu Nov 21 08:19:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 1198814 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-514279-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="SiNyT3ri"; 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 47JXXN3HLFz9sPJ for ; Thu, 21 Nov 2019 19:19:14 +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=cvOTWVh7itVSZ1b/Fppc5Kolfz1FPB4KGJAjQIVUcaHAfJeHHtFjQ pCGiThX8TYSsO7Rt7p06u4e5QMlJanTaCphE1H7tYr47KMZFVu5egFr77YNr+BVC Cu8WM10VgNgf9kV0z+MyeRYr2tRx7MoP79A/WZ8Um9S7UblKaJKdR4= 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=hsqEyqyHsp4+4/D7IT1qNEs3lHc=; b=SiNyT3riqDTWglNFxUTS BreQmlRgrolC1YY7TIh7Gd523WbpuudWT2UpuTwl6hX1VsqEU7wjjlfOuwHXz267 ulwTe9Vc/nIdDjKqKUbPQjJXEjUhvzfMx7NbSOaNSZVPteaVnFybgXuZ88O+Q6ZY O8K+zgRU1A6jPot0RpW+0t0= Received: (qmail 39672 invoked by alias); 21 Nov 2019 08:19:07 -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 39658 invoked by uid 89); 21 Nov 2019 08:19:06 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS autolearn=ham version=3.3.1 spammy=HX-Languages-Length:2097 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, 21 Nov 2019 08:19:05 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 2390428288B; Thu, 21 Nov 2019 09:19:03 +0100 (CET) Date: Thu, 21 Nov 2019 09:19:03 +0100 From: Jan Hubicka To: gcc-patches@gcc.gnu.org Subject: Avoid quadratic behaviour in early inlining Message-ID: <20191121081903.efceulgooy6gnoib@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20170113 (1.7.2) Hi, because early inliner is not producing call summaries, we do not want to estimate calls to very large function when we already know that inlning is going to fail. Bootstrapped/regtested x86_64-linux. * ipa-inline.c (want_early_inline_function_p): Do not estimate edge growth when callee function is very large. * ipa-inline.h (estimate_min_edge_growth): New. Index: ipa-inline.c =================================================================== --- ipa-inline.c (revision 278540) +++ ipa-inline.c (working copy) @@ -672,14 +672,29 @@ want_early_inline_function_p (struct cgr } else { - int growth = estimate_edge_growth (e); + /* First take care of very large functions. */ + int min_growth = estimate_min_edge_growth (e), growth = 0; int n; int early_inlining_insns = opt_for_fn (e->caller->decl, optimize) >= 3 ? param_early_inlining_insns : param_early_inlining_insns_o2; + if (min_growth > early_inlining_insns) + { + if (dump_enabled_p ()) + dump_printf_loc (MSG_MISSED_OPTIMIZATION, e->call_stmt, + " will not early inline: %C->%C, " + "call is cold and code would grow " + "at least by %i\n", + e->caller, callee, + min_growth); + want_inline = false; + } + else + growth = estimate_edge_growth (e); + - if (growth <= param_max_inline_insns_size) + if (!want_inline || growth <= param_max_inline_insns_size) ; else if (!e->maybe_hot_p ()) { Index: ipa-inline.h =================================================================== --- ipa-inline.h (revision 278540) +++ ipa-inline.h (working copy) @@ -79,6 +79,16 @@ estimate_edge_size (struct cgraph_edge * return entry->size - (entry->size > 0); } +/* Return lower bound on estimated callee growth after inlining EDGE. */ + +static inline int +estimate_min_edge_growth (struct cgraph_edge *edge) +{ + ipa_call_summary *s = ipa_call_summaries->get (edge); + struct cgraph_node *callee = edge->callee->ultimate_alias_target (); + return (ipa_fn_summaries->get (callee)->min_size - s->call_stmt_size); +} + /* Return estimated callee growth after inlining EDGE. */ static inline int