From patchwork Mon Jun 26 02:34:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hongyu Wang X-Patchwork-Id: 1799606 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=2620:52:3:1:0:246e:9693:128c; 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=TnbzFe4M; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4QqBn049MZz20XS for ; Mon, 26 Jun 2023 12:36:36 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 733DF3858423 for ; Mon, 26 Jun 2023 02:36:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 733DF3858423 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1687746994; bh=TBY4Xgn3Kr95SImwwotlrlPhJpFT26GUSsYQJDNEvAk=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=TnbzFe4MJ2RVIPRRhpgJTx9o3YHXJpOn7Ri51InINibaLsfXZ1id4NRpJj7IINsz+ sIVWUwiFWrRECTCYw7t4+1NfM9VJBV355hZ9Ahx6tcmo3MYA4RXA2Msjk4DsKk+bDS hxrcyJPEIyquwPufHZPbyogpLarRKDHRN2gQNy6Y= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 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) 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 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 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 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; +} +