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: 115546 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp939465vqx; Mon, 3 Jul 2023 20:13:34 -0700 (PDT) X-Google-Smtp-Source: APBJJlE9UdRn9IysS42DK2VuJcgAwORX4jytidA1nIIlwx2xxB/IP3fqW80TGOgKqobmn+htSPdq X-Received: by 2002:aa7:c308:0:b0:51e:2282:e1fc with SMTP id l8-20020aa7c308000000b0051e2282e1fcmr328815edq.6.1688440414652; Mon, 03 Jul 2023 20:13:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688440414; cv=none; d=google.com; s=arc-20160816; b=xkj44PoRTrpzwgU4OTZY5dhaWcIrIn5qF3Imu0VXkSje5Y4uzXzWXNkzalSrUFcLPj 9kc8CzsTTB4RJrETJtAAXeYGicuQ+2/JycE3l6hmh0LyVO+binXtUZoJQu6D695gnpRL PT4j69yj+RoEdM7pZTh/iP1dkN7mXfd3lhs+REk9SjtMl0pgLwmgF2z03FGq/HqyayNs +FOurgFQekcVEmw3IzjrzwQ3P8vnh/Xeg3F0vlaYfzZ5WOmSG7AWNjDF7M2SE/ztY9Y2 n7rR9x5jRe4JgTdAhA3jpjSqBjDrZ3Sur9/C40v61J2D7jQSUnr0wN+Yxsgm0pIIk1EW AkGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=MOfRhg1ROalJ9DE8CyrlgLO+SaHk6liWCdUorYkcsiw=; fh=n8eNxIWSYJwy/CU3QSXzDvE/zeEoomCGojuOcYEQEyQ=; b=GJWK10qiuKuFawKXeJcYxdA6hlqbjPj0WlG/5aZBj21Ke7Zz32DfJqBazbdtoWrKXS HM2MhWFO2K6l17yplNVvmtanW3V8lxR58MlGG3KmHG7zpAaeVHtVMYn9MBJKlehj0fnc BruOkkD+pOw8Fb3itGoZSZoNuXlanp28vE01lObOlB1G3VjDxTeATMRmELkFhhgjGxSK 0yvKZ8IpS8iNwdJdKocdWGd2i2LwG3R3R8SIOkY12q6TAdPLAVapuV7FOhkMNQyrfxrq sp7AaCr1KpDHt+UgmG0MbWtsjVm9Pti3WTir3AsjFSITSvz55Y9tbe55P6QwBJDLTBPX Y8sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=UYlau0oR; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id f11-20020a50ee8b000000b0051e0310f5b2si3639441edr.642.2023.07.03.20.13.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jul 2023 20:13:34 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=UYlau0oR; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7A1603857711 for ; Tue, 4 Jul 2023 03:13:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7A1603857711 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1688440413; 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=UYlau0oRGRWHktpZwm3sXejGtQt74r9aSJ5dyS5GhHr6fhPwoXdS9fsWI2gpViPy4 2eYzD/VmoGQ91aOcdZcfK5ArmmI/KtibME64PoMpbGhsbl0dntVePgE9c8ydnimtke UQ0p9zWIuzmLG8o2G4cXwQUW9HCh9ULCV82Y+S5w= 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770458096155404174?= X-GMAIL-MSGID: =?utf-8?q?1770458096155404174?= 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); + } +}