From patchwork Thu Jun 1 16:30:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Andre Vieira (lists)" X-Patchwork-Id: 1789244 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=sdMROozT; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QXBSp0xN2z20QH for ; Fri, 2 Jun 2023 02:30:34 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0ED57385700D for ; Thu, 1 Jun 2023 16:30:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0ED57385700D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685637032; bh=ruN1BDtQK9URCyYR3766d70mJsF6mi3jzDHFlBiQH88=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=sdMROozTEOFHJWqxihaPePYFy+T0wZ8aiYG3bK8DtZ1chhhSGBtE2x7uaYdwy0Pu3 FZn7WUTnLK7vFffuGUFpWUjC+ANE4zj4m4tTCIkqy1DI4d0kTgaul1fnTz65qzrxJu lIDOQ6fOS4zYZwybGVflfAomIvYHCjZadMyQWYyw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 14F4C385840D for ; Thu, 1 Jun 2023 16:30:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 14F4C385840D Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 29FBE1063; Thu, 1 Jun 2023 09:30:51 -0700 (PDT) Received: from [10.57.74.92] (unknown [10.57.74.92]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9114E3F663; Thu, 1 Jun 2023 09:30:04 -0700 (PDT) Message-ID: Date: Thu, 1 Jun 2023 17:30:02 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Content-Language: en-US To: "gcc-patches@gcc.gnu.org" Cc: Richard Biener , Richard Sandiford , "jakub@redhat.com" Subject: [PATCH] inline: improve internal function costs X-Spam-Status: No, score=-14.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: "Andre Vieira \(lists\) via Gcc-patches" From: "Andre Vieira (lists)" Reply-To: "Andre Vieira \(lists\)" Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi, This is a follow-up of the internal function patch to add widening and narrowing patterns. This patch improves the inliner cost estimation for internal functions. Bootstrapped and regression tested on aarch64-unknown-linux-gnu. gcc/ChangeLog: * ipa-fnsummary.cc (analyze_function_body): Correctly handle non-zero costed internal functions. * tree-inline.cc (estimate_num_insns): Improve costing for internal functions. diff --git a/gcc/ipa-fnsummary.cc b/gcc/ipa-fnsummary.cc index b328bb8ce14b0725f6e5607da9d1e2f61e9baf62..449961fe44e4d86bf61e625dff0759d58e1e80ba 100644 --- a/gcc/ipa-fnsummary.cc +++ b/gcc/ipa-fnsummary.cc @@ -2862,16 +2862,19 @@ analyze_function_body (struct cgraph_node *node, bool early) to happen, but we cannot do that for call statements because edges are accounted specially. */ - if (*(is_gimple_call (stmt) ? &bb_predicate : &p) != false) + if (*(is_gimple_call (stmt) && !gimple_call_internal_p (stmt) + ? &bb_predicate : &p) != false) { time += final_time; size += this_size; } /* We account everything but the calls. Calls have their own - size/time info attached to cgraph edges. This is necessary - in order to make the cost disappear after inlining. */ - if (!is_gimple_call (stmt)) + size/time info attached to cgraph edges. This is necessary + in order to make the cost disappear after inlining. The only + exceptions are internal calls. */ + if (!is_gimple_call (stmt) + || gimple_call_internal_p (stmt)) { if (prob) { diff --git a/gcc/tree-inline.cc b/gcc/tree-inline.cc index 99efddc36c8906a797583a569424336e961c35d1..bac84d277254703369c27993dcad048de8d4ff70 100644 --- a/gcc/tree-inline.cc +++ b/gcc/tree-inline.cc @@ -4427,7 +4427,48 @@ estimate_num_insns (gimple *stmt, eni_weights *weights) tree decl; if (gimple_call_internal_p (stmt)) - return 0; + { + switch (gimple_call_internal_fn (stmt)) + { + default: + return 1; + + case IFN_GOMP_TARGET_REV: + case IFN_GOMP_USE_SIMT: + case IFN_GOMP_SIMT_ENTER_ALLOC: + case IFN_GOMP_SIMT_EXIT: + case IFN_GOMP_SIMT_LANE: + case IFN_GOMP_SIMT_VF: + case IFN_GOMP_SIMT_LAST_LANE: + case IFN_GOMP_SIMT_ORDERED_PRED: + case IFN_GOMP_SIMT_VOTE_ANY: + case IFN_GOMP_SIMT_XCHG_BFLY: + case IFN_GOMP_SIMT_XCHG_IDX: + case IFN_GOMP_SIMD_LANE: + case IFN_GOMP_SIMD_VF: + case IFN_GOMP_SIMD_LAST_LANE: + case IFN_GOMP_SIMD_ORDERED_START: + case IFN_GOMP_SIMD_ORDERED_END: + case IFN_BUILTIN_EXPECT: + case IFN_ANNOTATE: + case IFN_NOP: + case IFN_UNIQUE: + case IFN_DEFERRED_INIT: + case IFN_ASSUME: + return 0; + + case IFN_UBSAN_NULL: + case IFN_UBSAN_BOUNDS: + case IFN_UBSAN_VPTR: + case IFN_UBSAN_CHECK_ADD: + case IFN_UBSAN_CHECK_SUB: + case IFN_UBSAN_CHECK_MUL: + case IFN_UBSAN_PTR: + case IFN_UBSAN_OBJECT_SIZE: + /* Estimating a compare and jump. */ + return 2; + } + } else if ((decl = gimple_call_fndecl (stmt)) && fndecl_built_in_p (decl)) {