From patchwork Tue Jul 4 03:12:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hongyu Wang X-Patchwork-Id: 1802998 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=server2.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=nQyeJyzg; dkim-atps=neutral Received: from server2.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 4Qw7CZ13r1z20bK for ; Tue, 4 Jul 2023 13:13:12 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0E2713857708 for ; Tue, 4 Jul 2023 03:13:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0E2713857708 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1688440390; bh=MOfRhg1ROalJ9DE8CyrlgLO+SaHk6liWCdUorYkcsiw=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=nQyeJyzgMpM3cfTXcGz6/+lXkAy/Mi1KBF4E3F1p4I+J8QJR0JHPViraeU/vztp11 IEvPq/RTtJEVxF7+hW9i5kcXX/+yE076Oq4y0YIj0CiGjzWteXKrafUSzjW552KkU2 vinEz6nr3DcQsja9njos056R2jB+BxWmh8hsy+hA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by sourceware.org (Postfix) with ESMTPS id 66BF93858C2C for ; Tue, 4 Jul 2023 03:12:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 66BF93858C2C X-IronPort-AV: E=McAfee;i="6600,9927,10760"; a="352846174" X-IronPort-AV: E=Sophos;i="6.01,179,1684825200"; d="scan'208";a="352846174" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jul 2023 20:12:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10760"; a="668922439" X-IronPort-AV: E=Sophos;i="6.01,179,1684825200"; d="scan'208";a="668922439" Received: from shvmail03.sh.intel.com ([10.239.245.20]) by orsmga003.jf.intel.com with ESMTP; 03 Jul 2023 20:12:45 -0700 Received: from shliclel4217.sh.intel.com (shliclel4217.sh.intel.com [10.239.240.127]) by shvmail03.sh.intel.com (Postfix) with ESMTP id 5C0B910056F3; Tue, 4 Jul 2023 11:12:44 +0800 (CST) To: gcc-patches@gcc.gnu.org Cc: ubizjak@gmail.com, hongtao.liu@intel.com Subject: [PATCH V2] i386: Inline function with default arch/tune to caller Date: Tue, 4 Jul 2023 11:12:44 +0800 Message-Id: <20230704031244.1074834-1-hongyu.wang@intel.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_SHORT, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_SOFTFAIL, 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: Hongyu Wang via Gcc-patches From: Hongyu Wang Reply-To: Hongyu Wang Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi, For function with different target attributes, current logic rejects to inline the callee when any arch or tune is mismatched. Relax the condition to allow callee with default arch/tune to be inlined. Boostrapped/regtested on x86-64-linux-gnu{-m32,}. Ok for trunk? gcc/ChangeLog: * config/i386/i386.cc (ix86_can_inline_p): If callee has default arch=x86-64 and tune=generic, do not block the inlining to its caller. gcc/testsuite/ChangeLog: * gcc.target/i386/inline_target_clones.c: New test. --- gcc/config/i386/i386.cc | 22 +++++++++++------ .../gcc.target/i386/inline_target_clones.c | 24 +++++++++++++++++++ 2 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/inline_target_clones.c diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc index 8989985700a..4741c9b5364 100644 --- a/gcc/config/i386/i386.cc +++ b/gcc/config/i386/i386.cc @@ -605,13 +605,6 @@ ix86_can_inline_p (tree caller, tree callee) != (callee_opts->x_target_flags & ~always_inline_safe_mask)) ret = false; - /* See if arch, tune, etc. are the same. */ - else if (caller_opts->arch != callee_opts->arch) - ret = false; - - else if (!always_inline && caller_opts->tune != callee_opts->tune) - ret = false; - else if (caller_opts->x_ix86_fpmath != callee_opts->x_ix86_fpmath /* If the calle doesn't use FP expressions differences in ix86_fpmath can be ignored. We are called from FEs @@ -622,6 +615,21 @@ ix86_can_inline_p (tree caller, tree callee) || ipa_fn_summaries->get (callee_node)->fp_expressions)) ret = false; + /* At this point we cannot identify whether arch or tune setting + comes from target attribute or not. So the most conservative way + is to allow the callee that uses default arch and tune string to + be inlined. */ + else if (!strcmp (callee_opts->x_ix86_arch_string, "x86-64") + && !strcmp (callee_opts->x_ix86_tune_string, "generic")) + ret = true; + + /* See if arch, tune, etc. are the same. */ + else if (caller_opts->arch != callee_opts->arch) + ret = false; + + else if (!always_inline && caller_opts->tune != callee_opts->tune) + ret = false; + else if (!always_inline && caller_opts->branch_cost != callee_opts->branch_cost) ret = false; diff --git a/gcc/testsuite/gcc.target/i386/inline_target_clones.c b/gcc/testsuite/gcc.target/i386/inline_target_clones.c new file mode 100644 index 00000000000..53db1600ce5 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/inline_target_clones.c @@ -0,0 +1,24 @@ +/* { dg-do compile } */ +/* { dg-require-ifunc "" } */ +/* { dg-options "-O3 -march=x86-64" } */ +/* { dg-final { scan-assembler-not "call\[ \t\]+callee" } } */ + +float callee (float a, float b, float c, float d, + float e, float f, float g, float h) +{ + return a * b + c * d + e * f + g + h + a * c + b * c + + a * d + b * e + a * f + c * h + + b * (a - 0.4f) * (c + h) * (b + e * d) - a / f * h; +} + +__attribute__((target_clones("default","arch=icelake-server"))) +void caller (int n, float *a, + float c1, float c2, float c3, + float c4, float c5, float c6, + float c7) +{ + for (int i = 0; i < n; i++) + { + a[i] = callee (a[i], c1, c2, c3, c4, c5, c6, c7); + } +}