From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by sourceware.org (Postfix) with ESMTPS id 78FC43858D20 for ; Mon, 26 Jun 2023 02:36:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 78FC43858D20 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687746974; x=1719282974; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=XAhGML2w5Nlec5KWSKH7dZ6UkQG7U/HWODYHJ9HR6GY=; b=f35f9GH+pgvd3joHrCi8dw+euiJavb4f4GFaIiCOLQAd3KuVsljE/6Ws oqP3XeO7fYFalrklKVVQ5q5v8Td6IMuCsLn0v01E2nZzfPBWkZj6tOmCF +MJKtfB21co+CeXldGSGhpnqcC1BMALG+tuDPFLwKCRGdvfBtRCMtuerN tVn3KCf5BJPqtKRsiv946F3d34dwSVlQSHyZz7jNXeZ4eiUY7vKxybd0U jRSjLNBMJNMqa4sOq1rT4ttawn/IoKTpnA9JM5Q6iuswmRmrwHCVycfSW sP//g+1Mc9KPsoh6EA4Jgn7nTYW8uLWEYmVJk/LavIUerkka1Q9iZcbky Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10752"; a="340742649" X-IronPort-AV: E=Sophos;i="6.01,158,1684825200"; d="scan'208";a="340742649" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2023 19:36:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10752"; a="890133853" X-IronPort-AV: E=Sophos;i="6.01,158,1684825200"; d="scan'208";a="890133853" Received: from shvmail03.sh.intel.com ([10.239.245.20]) by orsmga005.jf.intel.com with ESMTP; 25 Jun 2023 19:36:08 -0700 Received: from shliclel4217.sh.intel.com (shliclel4217.sh.intel.com [10.239.240.127]) by shvmail03.sh.intel.com (Postfix) with ESMTP id 3651D100568D; Mon, 26 Jun 2023 10:36:08 +0800 (CST) From: Hongyu Wang To: gcc-patches@gcc.gnu.org Cc: ubizjak@gmail.com, hongtao.liu@intel.com Subject: [PATCH] i386: Relax inline requirement for functions with different target attrs Date: Mon, 26 Jun 2023 10:34:08 +0800 Message-Id: <20230626023408.33758-1-hongyu.wang@intel.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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,SPF_HELO_PASS,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 List-Id: 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 honor just prefer_vecotr_width_type and other flags that may cause safety issue so caller can get more optimization opportunity. Bootstrapped/regtested on x86_64-pc-linux-gnu{-m32,} Ok for trunk? gcc/ChangeLog: * config/i386/i386.cc (ix86_can_inline_p): Do not check arch or tune directly, just check prefer_vector_width_type and make sure not to inline if they mismatch. gcc/testsuite/ChangeLog: * gcc.target/i386/inline-target-attr.c: New test. --- gcc/config/i386/i386.cc | 11 +++++---- .../gcc.target/i386/inline-target-attr.c | 24 +++++++++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/inline-target-attr.c diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc index 0761965344b..1d86384ac06 100644 --- a/gcc/config/i386/i386.cc +++ b/gcc/config/i386/i386.cc @@ -605,11 +605,12 @@ 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) + /* Do not inline when specified perfer-vector-width mismatched between + callee and caller. */ + else if ((callee_opts->x_prefer_vector_width_type != PVW_NONE + && caller_opts->x_prefer_vector_width_type != PVW_NONE) + && callee_opts->x_prefer_vector_width_type + != caller_opts->x_prefer_vector_width_type) ret = false; else if (caller_opts->x_ix86_fpmath != callee_opts->x_ix86_fpmath diff --git a/gcc/testsuite/gcc.target/i386/inline-target-attr.c b/gcc/testsuite/gcc.target/i386/inline-target-attr.c new file mode 100644 index 00000000000..995502165f0 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/inline-target-attr.c @@ -0,0 +1,24 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler-not "call\[ \t\]callee" } } */ + +__attribute__((target("arch=skylake"))) +int callee (int n) +{ + int sum = 0; + for (int i = 0; i < n; i++) + { + if (i % 2 == 0) + sum +=i; + else + sum += (i - 1); + } + return sum + n; +} + +__attribute__((target("arch=icelake-server"))) +int caller (int n) +{ + return callee (n) + n; +} + -- 2.31.1